【Overleaf】Latex表格基本方法的使用

【Overleaf】Latex表格基本方法的使用

基本用法

基本用法如下:%后面代表注释

\begin{tabular}{cccc}%一个c表示有一列,格式为居中显示(center),此处是4列(4个c)

1 & 2 & 3 & 4 \\%第一行各元素,中间用&连接

5 & 6 & 7 & 8 \\%第二行各元素,中间用&连接

\end{tabular}

运行效果如下:

添加竖线和横线

竖线

竖线的添加方式是在表头添加|

\begin{tabular}{|c|c|c|c|}%每列之间的|代表整列都要绘制|

1 & 2 & 3 & 4 \\%第一行第一列和第二列 中间用&连接

5 & 6 & 7 & 8 \\%第二行第一列和第二列 中间用&连接

\end{tabular}

运行效果如下:

横线

横线的语法是\hline

\begin{tabular}{cccc}

\hline % 一条横线

1 & 2 & 3 & 4 \\

\hline % 一条横线

5 & 6 & 7 & 8 \\

\hline % 一条横线

\end{tabular}

运行效果如下:

按列设置单元格的格式

单元格格式分为居左、居中、居右显示,上面的c就是居中(center)显示

\begin{tabular}{|l|c|r|}%l:left c:center r:right

\hline

1 & 2 & 3 \\

\hline

44444444 & 55555555 & 66666666 \\

\hline

\end{tabular}

运行效果如下:

三线表

有时我们希望绘制第一行和最后一行粗,中间行细的三线表。这个时候,需要引用宏包booktabs,引用方法为\usepackage{booktabs}。

\usepackage{booktabs}

\begin{tabular}{ccc}

\toprule %表格顶部粗横线

title1 & title2 & title3 \\

\midrule % 表格中间细横线

1 & 2 & 3 \\

4 & 5 & 6 \\

\bottomrule % 表格底部粗横线

\end{tabular}

运行效果如下:

table环境

{table}有若干可选参数 [!htbp]

h代表here,将表格排在当前文字位置

t 表示将表格放在下一页的 top (页首)

b 表示将表格放在当前页的 bottom (底部)

!表示忽略美观因素,尽可能按照参数指定的方式来处理表格浮动位置。

表格将会按照所给参数,依次尝试按照每个参数进行排版,当无法排版时,将会按照下一个参数

\begin{table}[!htbp]

\centering

\caption{This is a table} % 添加标题

\label{tab:tableTab} % 设置标签

\begin{tabular}{ccc}

\toprule

title1 & title2 & title3 \\

\midrule

1 & 2 & 3 \\

4 & 5 & 6 \\

\bottomrule

\end{tabular}

% 标题和标签写在这里也可以

\end{table}

运行效果如下:

单元格合并

横向合并

横向合并表格的关键字是\multicolumn{3}{|c|}{title}

\begin{table}[!htbp]

\centering

\begin{tabular}{|c|c|c|}

\hline

\multicolumn{3}{|c|}{title}\\ % 用\multicolumn{3}表示横向合并三列

% |c|表示居中并且单元格两侧添加竖线 最后是文本

\hline

1 & 2 & 3 \\

4 & 5 & 6 \\

\hline

\end{tabular}

\end{table}

运行效果如下:

纵向合并

纵向合并需要宏包\usepackage{multirow},

\usepackage{multirow}

\begin{table}[!htbp]

\centering

\begin{tabular}{|c|c|c|}

\hline

\multirow{4}*{title test}& 1 & 2 \\ % 纵向合并4个单元格,&后面是第一行需要显示的数据

\cline{2-3} % 为第二列到第三列添加横线

& 3 & 4 \\ % 第二行需要显示的数据

\cline{2-3} % 为第二列到第三列添加横线

& 5 & 6 \\ % 第三行需要显示的数据

\cline{2-3} % 为第二列到第三列添加横线

& 7 & 8 \\ % 第四行需要显示的数据

\hline

\end{tabular}

\end{table}

运行效果如下:

横向合并和纵向结合

\begin{table}[!htbp]

\centering

\begin{tabular}{|c|c|c|c|c|c|c|}

\hline

\multicolumn{2}{|c|}{ \multirow{2}*{title 1} }& \multicolumn{4}{c|}{title 2} &\multirow{2}*{title 3}\\

\cline{3-6}

\multicolumn{2}{|c|}{}& 1 & 2 & 3 & 4 &\\

\hline

\multirow{4}*{title 4}& 5 & 6 & 7 & 8 & 9 & 10 \\

\cline{2-7}

& 11 &12 & 13 & 14 & 15 & 16 \\

\cline{2-7}

& 17 & 18 & 19 & 20 & 21 & 22 \\

\cline{2-7}

& 23 & 24 & 25 & 26 & 27 & 28 \\

\hline

\end{tabular}

\end{table}

运行效果如下:

斜线表头

斜线表头的实现需要引入宏包\usepackage{diagbox},使用diagbox关键字添加

\usepackage{diagbox}

\begin{table}[!htbp]

\centering

\begin{tabular}{|c|c|c|}

\hline

\diagbox{a}{b}{c}& bc & cb\\ %添加斜线表头

\hline

ab & 2 & 3 \\

ba & 5 & 6 \\

\hline

\end{tabular}

\end{table}

运行效果如下:

相关推荐

oppo哪款音质最好 oppo音质最强三个品牌
365bet手机版客户端

oppo哪款音质最好 oppo音质最强三个品牌

📅 08-05 👁️ 6089
俄罗斯VS埃及
best365从哪能进去

俄罗斯VS埃及

📅 08-18 👁️ 615
砸伤怎么消肿止痛
365bet手机版客户端

砸伤怎么消肿止痛

📅 07-18 👁️ 387