Latex 表格定制
- Latex 表格位置参数说明
- 表格例子
- 合并行
- 合并列
- 合并行与列
- Table说明
Latex 表格位置参数说明
| 参数 | 位置 |
|---|---|
| c | 将文本置于中间 |
| l | 将文本左对齐 |
| r | 将文本右对齐 |
| p{宽度} | 文本对齐单元格顶部 |
| m{宽度} | 文本对齐单元格中间 |
| b{宽度} | 文本对齐单元格底部 |
更多的选项:
| 选项 | 意义 |
|---|---|
| & | 定义每个单元格,仅用于第二行 |
| \ | 这将终止该行并开启下一个新行 |
| | | 指定表格的垂直线(可选) |
| \hline | 指定表格的水平线 |
| *{数量}{格式} | 有许多列时,可以使用 |
| || | 指定表格中的双垂线 |
表格例子
下述例子展示合并行,和并列,合并行与列
合并行
可以用multirow 指令,采用格式:\multirow{行的数量}{宽度}{文本}
示例:
\begin{tabular}{|l|l|}\hlineRelease &Codename \\ \hlineFedora Core 4 &Stentz \\ \hline\multirow{2}{*}{MultiRow} &Fedora 8 \\ &Werewolf \\ \hline
\end{tabular}
这里\multirow{2} 表示合并两行,两行过后是Fedora 和 Werewolf, 此时注意虽然上一行MultiRow内容已经占用两行,但下一行开始时,依然要用空白内容占据一行,因此&Werewolf 前面内容空白,但要占位。

需注意:multirow 需要引用package,\usepackage{multirow}
表格例子引用自:合并行.
合并列
multicolumn 的参数是 multicolumn {列的数量}{单元格选项}{位置}{文本}
单元格选项中 c:居中,l:居左,r:居右,|:有竖线
例如, |c|: 就是居中,两边有竖线。
示例:
\begin{tabular}{|l|l|l|}\hlineRelease &Codename &Date \\ \hlineFedora Core 4 &Stentz &2005 \\ \hline\multicolumn{3}{|c|}{Mulit-Column} \\ \hline
\end{tabular}

表格例子引用自:合并列.
合并行与列
\begin{tabular}{l|cccc}\hline\multirow{2}{*}{\textbf{Env}} & \multicolumn{4}{c}{\textbf{Training Time}} \\& \textbf{PPO} & \textbf{TRPO} & \textbf{DDPG} & \textbf{A3C}\\\hline\textbf{Env 1} & & & &\\\textbf{Env 2} & & & & \\\textbf{Env 3} & & & &\\\hline\end{tabular}
说明:{l|cccc}: l代表第一列居左侧,并且第一列与后面的列用|隔开,后面四列不隔开,并且居中。
\multirow{2}{*}{\textbf{Env}}:合并两行,
\multicolumn{4}{c}{\textbf{Training Time}}:紧接着合并四列,且居中,
然后 下一行,&PPO前面要留空白来占位,后面是四列。
呈现效果如下:

Table说明
上面的都是针对tabular来进行的一些例子说明,在实际paper书写中,需要用到table的命令,这样能用table环境,书写table名称,caption,label等。
示例:
\begin{table}[where] table
\end{table}
官方文档说明:
In the above syntax, table stands for the contents of the ‘tabular’ environment together with a possible \caption command. The argument where specifies the allowed locations for the table. For example, when \begin{table}[t] is typed, it means that the table will appear on the top of the page.
于是,前面的合并行与列的示例可以更新为:
\begin{table}[t]
\begin{center}
\caption{The training time of differnt algorithms over three environments.}
\label{table:learning_time}
\begin{tabular}{l|cccc}\hline\multirow{2}{*}{\textbf{Env}} & \multicolumn{4}{c}{\textbf{Training Time}} \\& \textbf{PPO} & \textbf{TRPO} & \textbf{DDPG} & \textbf{A3C}\\\hline\textbf{Env 1} & & & & \\\textbf{Env 2} & & & & \\\textbf{Env 3} & & & & \\\hline
\end{tabular}
\end{center}
\end{table}
说明:
\begin{table}[t] :将table置于页面顶端
\begin{center}:将table置于页面中间,是版面的中间
\caption: table的标题
\label: 用于引用这个table的label
更多详细内容可以参考:
1. Creating Tables with Latex
2. The difference between \begin{center} and \centering
3. Creating tables
4. 嵌套表格绘制
















