Latex表格使用解析

  • 表格基本模板
  • 基本用法
  • 基本表格
  • 添加边框
  • 表格合并
  • 合并多列
  • 合并多行
  • 多行多列合并
  • 三线表


表格基本模板

\begin{table}[]
    \centering
    \begin{tabular}{} 
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

其中主体为tabular下文会讲解,\centering控制表格是否居中,\Caption控制表格的标题,\label全局唯一的id,用于文中引用。

基本用法

本小节单纯讲解tabular中的使用

基本表格

\begin{tabular}{cc} %% 有两个字母表示有两列,c 表示居中,还可以选择 l 或者 r
A&B\\ % \\ 表示换行,& 表示分割线
C&D\\
\end{tabular}

Springer latex表格_ico


表格列数需要在参数中表明,行数不限制,使用\换行即可。

添加边框

如果要添加边框(边框由分割线组成),对列添加分割线需要在参数中相应位置添加”|” ,对行分割线则使用”\hline” 或”\cline”

\begin{tabular}{|cc||} % 因为右侧有两道线,所以相应位置显示两条分割线
A&B\\\hline
C&D\\\cline{0-1} % 数字代表列数,从零开始,表示从 a-b
E&F\\\cline{0-0}
G&H\\\cline{1-1} % 边框可以任意重叠,但横向边框显示多条并不好控制,因此不推荐使用多条分割线完成特殊需求
I&J\\\cline{0-0}\cline{1-1}
\end{tabular}

Springer latex表格_latex_02

表格合并

合并多列

有时后,会遇到合并表格的需求,合并表格需要使用multirow这个库, 并使用到 \multicolumn 和 \multirow 这两个方法,

\usepackage{multirow}
\usepackage{multicolumn}

其中合并多列比较简单,在要合并的位置填入相应的命令,随后减少相 应的分隔符即可

\begin{tabular}{|c|c|c|c|c|}
\hline
1.0&2.0&3.0&4.0&5.0\\
\hline
6.0&\multicolumn{3}{c|}{合并三列}&7.0\\
\hline
8.0&9.0&10.0&11.0&12.0\\
\hline
\end{tabular}

注意中文显示不全的问题

Springer latex表格_分割线_03

合并多行

合并多行同理,不过在相同列的位置需要空出来,并在设置分割线的时 候将相应的列的位置空出来

\documentclass{ctexart}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
1.0&2.0&3.0\\
\hline
4.0&\multirow{3}{*}{合并三行}&5.0\\
\cline{1-1}
\cline{3-3}
6.0&&7.0\\
\cline{1-1}
\cline{3-3}
8.0&&9.0\\
\hline
10.0&11.0&12.0\\
\hline
\end{tabular}
\end{document}

Springer latex表格_分割线_04

多行多列合并

如果要同时合并多行多列,则需要对两个命令嵌套使用:

\documentclass{ctexart}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
1.0&2.0&3.0&4.0\\
\hline
5.0&\multicolumn{2}{c|}{\multirow{3}{*}{合并三行两列}}&6.0\\
\cline{1-1}
\cline{4-4}
7.0&\multicolumn{2}{c|}{}&8.0\\
\cline{1-1}
\cline{4-4}
9.0&\multicolumn{2}{c|}{}&10.0\\
\hline
11.0&12.0&13.0&14.0\\
\hline
\end{tabular}
\end{document}

Springer latex表格_ico_05

三线表

用到的宏包主要是 booktabs ,即:在导言区加入:

\usepackage{booktabs}

下面是普通三线表的代码和效果:

\documentclass{ctexart}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\caption{\label{tab:test}示例表格}
\begin{tabular}{lcl}
\toprule
。。 & 。。 & 。。 \\
\midrule
。。 & 。。 & 。。 \\
。。 & 。。 & 。。 \\
。。 & 。。 & 。。 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

Springer latex表格_latex_06


参考: LaTeX手册.