Hong's Page.

Latex多行表格

字数统计: 473阅读时长: 2 min
2019/12/01 895 Share

Latex 多行表格

有时候我们在latex需要绘制多行多列的复杂表格。需要用到multirow这个packge。

例如下图的表格。

Latex/Untitled.png
Latex/Untitled.png
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{table}[htbp]
\centering
\caption{Multi rows and columns}
\begin{tabular}{|M{0.2\columnwidth}|M{0.23\columnwidth}|M{0.16\columnwidth}|M{0.2\columnwidth}|}
% \begin{tabular}{|c|c|c|c|}
\hline
\hline
\textbf{c1} & \multicolumn{3}{|c|}{\textbf{c2}} \\
\hline
\multirow{3}{*}{\shortstack{\\single \\ column \\multirow}} & \multirow{2}{*}{\shortstack{\\First row\\ second row}} & Data & Data \\
\cline{3-4}
& & Data & Data \\
\cline{2-4}
& \multirow{2}{*}{Data} & Data & Data \\
\cline{3-4}
& & Data & Data \\
\cline{2-4}
& Data changes line automatically& Data & Data\\
\hline
\end{tabular}
\label{t2}
\end{table}

上面的代码中的M是为了让表格中的内容居中而设计的。

\multirow{2}{*}{Multi-Row}中的\multirow是跨行而用的,有三个参数,第一个参数表示跨多少行,第二个参数*表示系统自动调整文字,最后一个参数是填入的内容。

\multicolumn\multirow类似。

\cline{3-4}表示在第3栏位和第4栏位之间加入竖线。

另外上面的表格中还涉及一个表格的一个格子中的自动换行问题。比如First row second row那一格使用了\shortstack{}将表格内的数据包括了起来,然后在里面使用了换行符,如果不使用这个的话,整个,数据不会自动换行,First row second row的就会超出表格。如果同一行中的数据没有被分割,那么就不需要使用\shortstack{},数据会自动进行换行。如上表中的Data changes line automatically.

CATALOG
  1. 1. Latex 多行表格