LaTeX表格制作

article/2025/10/23 23:19:58

一些LaTeX中表格的使用方法如下:

1.table

\documentclass{article}\begin{document}\begin{table}[h]\centering\begin{tabular}{|l|c|c|}\hlineSetting&\multicolumn{2}{c|}{A4 size paper}\\\hline&mm&inches\\Top&25&1.0\\Bottom&25&1.0\\Left&20&0.8\\Right&20&0.8\\Column Width&82&3.2\\Column Spacing&6&0.25\\\hline\end{tabular}\caption{Margin settings for A4 size paper}\label{tab:Margin_settings}\end{table}\end{document}

 


2.tabular

\begin{tabular}{|c|c|c|}\hline 2&9&4\\\hline 7&5&3\\\hline 6&1&8\\\hline
\end{tabular}


 


例子里面的|c|这样的,那个地方叫做导言区,来约定表格的每列属性的:

l
left-justified column
c
centered column
r
right-justified column
b
bottom
c
center (default)
t
top
p{'width'}
paragraph column with text vertically aligned at the top
m{'width'}
paragraph column with text vertically aligned in the middle (requires array package)
b{'width'}
paragraph column with text vertically aligned at the bottom (requires array package)
|
vertical line
||
double vertical line

另外,还有一些常用的命令

&
column separator
\\
start new row (additional space may be specified after \\ using square brackets, such as \\[6pt]
\hline
horizontal line
\newline
start a new line within a cell (in a paragraph column)
\tabularnewline
start a new line within a cell (in a paragraph column) instead of \\ to avoid a Misplaced \noalign error in the tabular
\cline{i-j}
partial horizontal line beginning in column i and ending in column j

除了最简单的用例外,还可以这样:

% example 1:
\begin{center}\begin{tabular}{ | l || c || r }\hline1 & 2 & 3 \\ \hline4 & 5 & 6 \\ \hline \hline7 & 8 & 9 \\\hline\end{tabular}
\end{center}


 
example 1 

% example 2:
%\multicolumn{n}{format}{item}
\begin{tabular}{|c|c|c|}\hline \multicolumn{3}{|c|}{?}\\\hline 7&5&3\\\hline 6&1&8\\\hline
\end{tabular}


 
example 2 

% example 3:
\begin{tabular}{|r|l|}\hline7C0 & hexadecimal \\3700 & octal \\ \cline{2-2}11111000000 & binary \\\hline \hline1984 & decimal \\\hline
\end{tabular}


 
example 3 


array环境中(使用时需要包含:\usepackage{array}),重新实现了tabular环境,加了不少新选项进去:


 

对于tabular的第一个例子略作修改,可以发现在不含有array包和含有时效果是不一样的:

% example 1:
%\usepackage{array}
\tabcolsep20pt
\arrayrulewidth2pt
\begin{tabular}{*{3}{|c}|}
%\begin{tabular}{|c|c|c|}\hline 2&9&4\\\hline 7&5&3\\\hline 6&1&8\\\hline
\end{tabular}% example 2:
...
\usepackage{array}
...\tabcolsep20pt
\arrayrulewidth2pt
\begin{tabular}{*{3}{|c}|}
%\begin{tabular}{|c|c|c|}\hline 2&9&4\\\hline 7&5&3\\\hline 6&1&8\\\hline
\end{tabular}


 
example 1 


 
example 2 


对于表格内有长文本时,直接排下来不但很难看而且很容超出页面的范围,可以这么做:

Without specifying width for last column:
\begin{center}\begin{tabular}{| l | l | l | l |}\hlineDay & Min Temp & Max Temp & Summary \\ \hlineMonday & 11C & 22C & A clear day with lots of sunshine.However, the strong breeze will bring down the temperatures. \\ \hlineTuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest. \\ \hlineWednesday & 10C & 21C & Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening. \\\hline\end{tabular}
\end{center}With width specified:
\begin{center}\begin{tabular}{ | l | l | l | p{5cm} |}\hlineDay & Min Temp & Max Temp & Summary \\ \hlineMonday & 11C & 22C & A clear day with lots of sunshine.  However, the strong breeze will bring down the temperatures. \\ \hlineTuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells across most of Scotland and Northern Ireland, but rain reaching the far northwest. \\ \hlineWednesday & 10C & 21C & Rain will still linger for the morning. Conditions will improve by early afternoon and continue throughout the evening. \\\hline\end{tabular}
\end{center}


 

另外使用宏包tabulary也可以实现:

\usepackage{tabulary}
...\begin{center}\begin{tabulary}{0.7\textwidth}{LCL}Short sentences      & \#  & Long sentences                                                 \\\hlineThis is short.       & 173 & This is much loooooooonger, because there are many more words.  \\This is not shorter. & 317 & This is still loooooooonger, because there are many more words. \\\end{tabulary}  
\end{center}


其中的对齐方式除了 L , C 外,还有 R , J


让我们看下\parbox的用法,如果我们想把文段分割成为表的形式:

\begin{tabular}{cc}boring cell content & \parbox[t]{5cm}{rather long par\\new par}
\end{tabular}
  • 1
  • 2
  • 3


 


调整行列间距可以使用命令:

\setlength{\tabcolsep}{5pt} %colums, default value is 6pt\renewcommand{\arraystretch}{1.5} %rows, default value is 1.0

另外一种方式是在\hlinecline{i-j}后添加\noalign{\smallskip}, 例如:

\begin{center}\begin{tabular}{ | l | l | r | }\hline\multicolumn{2}{c}{Item} \\\cline{1-2}Animal & Description & Price (\$) \\\hlineGnat  & per gram & 13.65 \\& each     &  0.01 \\Gnu   & stuffed  & 92.50 \\Emu   & stuffed  & 33.33 \\Armadillo & frozen & 8.99 \\\hline\end{tabular}example 1$ $\setlength{\tabcolsep}{4pt}\begin{tabular}{ | l | l | r | }\hline\multicolumn{2}{c}{Item} \\\cline{1-2}Animal & Description & Price (\$) \\\hlineGnat  & per gram & 13.65 \\& each     &  0.01 \\Gnu   & stuffed  & 92.50 \\Emu   & stuffed  & 33.33 \\Armadillo & frozen & 8.99 \\\hline\end{tabular}example 2$ $\renewcommand{\arraystretch}{1.5}\begin{tabular}{ | l | l | r | }\hline\multicolumn{2}{c}{Item} \\\cline{1-2}Animal & Description & Price (\$) \\\hlineGnat  & per gram & 13.65 \\& each     &  0.01 \\Gnu   & stuffed  & 92.50 \\Emu   & stuffed  & 33.33 \\Armadillo & frozen & 8.99 \\\hline\end{tabular}example 3$ $\setlength{\tabcolsep}{6pt}\renewcommand{\arraystretch}{1.0}\begin{tabular}{ | l | l | r | }\hline\noalign{\smallskip}\multicolumn{2}{c}{Item} \\\cline{1-2}\noalign{\smallskip}Animal & Description & Price (\$) \\\noalign{\smallskip}\hline\noalign{\smallskip}Gnat  & per gram & 13.65 \\& each     &  0.01 \\Gnu   & stuffed  & 92.50 \\Emu   & stuffed  & 33.33 \\Armadillo & frozen & 8.99 \\\noalign{\smallskip}\hline\end{tabular}example 4\end{center}


 

其他用法如在某一行后空出一定间距:

\begin{tabular}{ll}\hlineMineral & Color \\[0.5cm]Ruby & red \\Sapphire & blue \\\hline
\end{tabular}


 


一些LaTeX的环境也可以插入表格中:

\begin{tabular}{m{5cm} c} % here the m can be replaced by p or b.\\ \hline\begin{verbatim}I love coding\end{verbatim}& LaTeX\\ \hline
\end{tabular}


 

使用列规格设置命令:>{\cmd} and <{\cmd},如设置表格中的字符都是数学手写字体:

...
\usepackage{array}
...\newcolumntype{F}{>{$}c<{$}}
\begin{tabular}{FFF}\alpha & \beta    & \gamma   \\\delta & \epsilon & \upsilon \\\sigma & \tau     & \phi     \\
\end{tabular}


 


@-expressions的用法:

\begin{tabular}{|@{}l|l@{}|}\hlinestuff & stuff \\ \hlinestuff & stuff \\\hline
\end{tabular}\begin{tabular}{r@{.}l}3   & 14159 \\16  & 2     \\123 & 456   \\
\end{tabular}


 


行的特别设置,给出几个例子:

\begin{tabular}{ |l|l| }\hline\multicolumn{2}{|c|}{Team sheet} \\\hlineGK & Paul Robinson \\LB & Lucas Radebe \\DC & Michael Duberry \\DC & Dominic Matteo \\RB & Dider Domi \\MC & David Batty \\MC & Eirik Bakke \\MC & Jody Morris \\FW & Jamie McMaster \\ST & Alan Smith \\ST & Mark Viduka \\\hline
\end{tabular}


 

...
\usepackage{multirow}
...\begin{tabular}{ |l|l|l| }\hline\multicolumn{3}{ |c| }{Team sheet} \\\hlineGoalkeeper & GK & Paul Robinson \\ \hline\multirow{4}{*}{Defenders} & LB & Lucas Radebe \\& DC & Michael Duburry \\& DC & Dominic Matteo \\& RB & Didier Domi \\ \hline\multirow{3}{*}{Midfielders} & MC & David Batty \\& MC & Eirik Bakke \\& MC & Jody Morris \\ \hlineForward & FW & Jamie McMaster \\ \hline\multirow{2}{*}{Strikers} & ST & Alan Smith \\& ST & Mark Viduka \\\hline
\end{tabular}


 

...
\usepackage{multirow}
...\begin{tabular}{cc|c|c|c|c|l}\cline{3-6}& & \multicolumn{4}{ c| }{Primes} \\ \cline{3-6}& & 2 & 3 & 5 & 7 \\ \cline{1-6}\multicolumn{1}{ |c  }{\multirow{2}{*}{Powers} } &\multicolumn{1}{ |c| }{504} & 3 & 2 & 0 & 1 &     \\ \cline{2-6}\multicolumn{1}{ |c  }{}                        &\multicolumn{1}{ |c| }{540} & 2 & 3 & 1 & 0 &     \\ \cline{1-6}\multicolumn{1}{ |c  }{\multirow{2}{*}{Powers} } &\multicolumn{1}{ |c| }{gcd} & 2 & 2 & 0 & 0 & min \\ \cline{2-6}\multicolumn{1}{ |c  }{}                        &\multicolumn{1}{ |c| }{lcm} & 3 & 3 & 1 & 1 & max \\ \cline{1-6}
\end{tabular}


 

\begin{tabular}{ r|c|c| }\multicolumn{1}{r}{}&  \multicolumn{1}{c}{noninteractive}& \multicolumn{1}{c}{interactive} \\\cline{2-3}massively multiple & Library & University \\\cline{2-3}one-to-one & Book & Tutor \\\cline{2-3}
\end{tabular}


 


3.booktabs

三线表

\usepackage{booktabs}\begin{tabular}{ccc}\toprule2&9&4\\\midrule7&5&3\\6&1&8\\\bottomrule
\end{tabular}


 


4.colortbl

常用的表格填色colortbl包:

% example 1:
\usepackage{colortbl}\begin{tabular}{ccc}\rowcolor[gray]{.9}2&9&4\\\rowcolor[gray]{.8}7&5&3\\\rowcolor[gray]{.7}6&1&8\\
\end{tabular}


 
example 1 

% example 2:
\begin{tabular}{>{\columncolor[gray]{.9}}c|>{\columncolor[gray]{.8}}c|>{\columncolor[gray]{.7}}c}2&9&4\\7&5&3\\6&1&8\\
\end{tabular}


 
example 2 

%example 3:
\begin{tabular}{ccc}\cellcolor[rgb]{.9,.9,.9}2&\cellcolor[rgb]{.8,.9,.9}9&\cellcolor[rgb]{.7,.9,.9}4\\\cellcolor[rgb]{.9,.8,.9}7&\cellcolor[rgb]{.8,.8,.9}5&\cellcolor[rgb]{.7,.8,.9}3\\\cellcolor[rgb]{.9,.7,.9}6&\cellcolor[rgb]{.8,.7,.9}1&\cellcolor[rgb]{.7,.7,.9}8\\
\end{tabular}


 
example 3 


5.diagbox

画斜线表头的包diagbox

\usepackage{diagbox}
...\begin{tabular}{|l|ccc|}
\hline
\diagbox{Time}{Room}{Day} & Mon & Tue & Wed \\
\hline
Morning & used & used & \\
Afternoon & & used & used \\
\hline
\end{tabular}


http://chatgpt.dhexx.cn/article/LtqYuLFS.shtml

相关文章

LaTex中表格常用设置

推荐一个在线生成各种表格命令的工具&#xff1a;https://tablesgenerator.com/。 1.表格参数 table 后面加*表示双栏表格&#xff0c;如\begin{table*}...\end{table*}。 表格中常用选项[htbp]是浮动格式&#xff1a; h当前位置。将图形放置在正文文本中给出该图形环境的地…

Latex中的表格(2)

Latex中的表格 一、一个加脚注的三线表的例子二、一个表格中加注释的例子三、两个并排的两个表格的例子3.1 使用小页环境并排表格3.2 使用子表格并排表格 四、一个格式复杂的表格的例子五、一个长表格的例子 这篇文章主要罗列一些特殊的表格例子。内容来自&#xff1a;一篇北师…

【教程】在线生成LaTeX中的表格

【教程】在线生成LaTeX中的表格 当我们写论文时不可避免要用表格总结自己的实验结果。但是LaTeX中的表格操作实在是太麻烦了&#xff0c;所以有一个在线生成LaTex中的表格能大大提高生产力 本教程展示从Excel表格到LaTeX表格的整个过程&#xff0c;简单易用&#xff0c;不用自己…

LaTex(1):使用在线表格生成器工具生成LaTex表格及latex相关工具网站

目录 0 在线工具 1 常用命令&#xff1a; 1.0 编辑表格 1.1 Table—set size可以改变表格大小&#xff1a; 1.2 合并表格和拆分表格&#xff1a; 1.3 生成latex代码与复制代码&#xff1a; 2 示例 3. 相关工具网站 3.1 latex公式编辑器 0 在线工具 表格生成器网页&a…

latex表格手把手超详细教程(table, tabular, multirow, multicolumn)

最近写论文要用latex&#xff0c;实验部分需要画表格&#xff0c;于是百度看了两个多小时的博客&#xff0c;一无所获&#xff0c;全都写的乱七八糟的&#xff0c;越看越烦躁&#xff0c;于是谷歌五分钟&#xff0c;就学会了怎么画表格&#xff0c;下面是我最终画出来的表格&am…

Latex基本表格绘制

Latex基本表格绘制 文章目录 Latex基本表格绘制1.基本格式2.添加竖线和横线3.设置每一列的单元格格式4.常见的三线表5.table环境6.单元格合并7.斜线表头8.其他(2018.11.23)1.基本格式 \documentclass{article}\begin{document}\begin{tabular}{cc}%一个c表示有一列,格式为居中…

LaTeX表格Table使用解析

推荐一个在线生成表格命令的工具&#xff1a;LaTeX Table Generator 常用选项[htbp]是浮动格式&#xff1a; h当前位置。将图形放置在正文文本中给出该图形环境的地方。如果本页所剩的页面不够&#xff0c;这一参数将不起作用。 t顶部。将图形放置在页面的顶部。 b底部。将图形…

在 LaTeX 中插入表格

原  文&#xff1a;在 LaTeX 中插入表格 译  者&#xff1a;Xovee 翻译时间&#xff1a;2020-1024 在 LaTeX 中插入表格 在科研论文中&#xff0c;表格是最重要的内容之一。LaTeX 提供了许多定制化表格的功能&#xff0c;包括调整表格大小&#xff0c;合并单元格&#xf…

LaTeX表格处理

关于LaTeX中对表格的一些处理 在使用latex撰写文档时&#xff0c;可能会遇到表格太大超过页面范围&#xff0c;表格太小显示不美观&#xff0c;以及生成跨行表格&#xff0c;表头斜线等问题&#xff0c;以下是一些调整表格的命令。 调整表格大小 使用以下的latex命令之前&am…

latex画表格(自用)

绘制 latex 表格需要用到 table 和 tabular 环境。 其中table环境里写表格的标题&#xff08;caption&#xff09;、表格的偏移之类的。 tabular环境则是绘制表格的内容。 首先是table环境部分&#xff0c;\begin{center} 让表格居中&#xff0c;\caption{Table name.} 写表格…

Latex论文表格画法

参考 Latex论文表格画法 - 云社区 - 腾讯云 1、基本表格画法 \begin{table}[htbp] 表示表格的开始。中括号中的 htbp 表示的是表格的浮动格式。当然这个基本参数不仅仅只是对表格有用。需要注意的是&#xff0c;一般使用 [htb] 这样的组合&#xff0c;这样组合的意思就是Latex会…

LaTeX中的表格

LaTeX中的表格 这一节我们主要讨论LaTeX中表格的制作和排版问题。 &#xff08;1&#xff09;在LaTeX中&#xff0c;可以使用tabular环境生成表格。 &#xff08;2&#xff09;tabular环境需要一个指定列排版格式的必选参数。可以用l指定左对齐&#xff0c;用c指定居中对齐&a…

Latex 制作表格

Latex 制作表格 前言一、Latex三线表1、普通三线表2、跨页三线表 二、简单表1、基本需求表2、表格整体相关设置【表名及位置、表宽、注解、字号】1. 表格标题及位置2. 表宽设置3. 表格注解4. 字号设置 三、复杂表1、合并单元格2、斜线表头 五、常用表格模板代码总结 前言 Late…

Qt学习c++

Qt学习C 平台及版本Day01 HelloWorld程序生成Day02 分析第一个Qt程序1) main.cpp2) mainwindow.h和mainwindow.cpp Day03 Qt控件和事件Day04 信号和槽基本理解connect()函数实现信号和槽实例演示信号和槽机制 Day05 Qt QLabel文本框的使用QLabel文本框的信号和槽QLabel的常用方…

Qt学习基础

1. Qt是什么&#xff1f; Qt是一个基于C语言的图形用户界面&#xff08;GUI&#xff09;开发框架&#xff0c;Qt不仅仅可以进行GUI开发&#xff0c;除此之外Qt也能进行很多其它功能开发&#xff0c;包括但不限于多线程、数据库、图像处理、音视频处理、网络通信与文件IO等。 Qt…

Qt学习心得体会

Qt是一种跨平台C图形界面程序开发框架&#xff0c;在社会中各种行业都有着举足轻重的地位。 Qt为了实现对象与对象之间的通信&#xff0c;提出了信号与槽的概念。当一个对象发生改变会发送一个信号通知另一个对象执行一个函数&#xff0c;这个函数称为槽&#xff0c;信号只需要…

QT 学习笔记(二)

文章目录 一、标准信号和槽1. 准备工作1.1 main.c1.2 widget.cpp 2. 添加按钮2.1 widget.h2.2 widget.cpp2.3 运行结果 3. 信号和槽&#xff08;重点&#xff09;3.1 信号3.2 自定义槽3.3 widget.h3.4 widget.cpp3.5 运行结果 二、两个独立窗口1. 添加新窗口2. 自定义信号3. 窗…

Qt学习 - 总

Qt学习 学习中的错误常用快捷键杂项布局信号与槽数据库相关QSS选择器 {property:value}Qt样式表设置函数 setStyleSheet()QSS文本属性 事件QMouseEvent&#xff1a;鼠标事件键盘事件QWheelEvent&#xff1a;滚轮事件QCloseEvent&#xff1a;关闭事件QTimerEvent&#xff1a;超时…

Qt日常学习

2022/07/28 使用Visual Studio2019 搭配 Qt5.14&#xff0c;可视化Qt界面使用QtDesigner。 若只使用代码来做界面太麻烦&#xff0c;效率低&#xff1b;只使用可视化界面进行拖拽效率高但无法实现全部功能。使用代码可视化结合的方式能够实现绝大部分功能。 练习1&#xff1…

QT入门学习(一):什么是QT

QT 是什么&#xff1f; QT是一个跨平台C图形用户界面应用程序开发框架。它不仅可以开发GUI程序&#xff0c;也可以开发非GUI程序。我们通常使用QT开发GUI程序。 它可以开发Windows、Linux、Mac平台的应用程序。也可以开发移动端应用程序以及嵌入式程序。 QT 模块 QT 有模块…