表格排版
1. 经常会看到Table或者Figure后面加上[htb],其中h表示here, t –top,
b-bottom,即表格在文中的位置。那么[htb]是按照其顺序排列进行选择,
即h, t ,b顺序。
/begin{figure}[htb!]
2.调整表格列高、行高及大小。可以使用:
/begin{table} /renewcommand{/arraystretch}{1.5} //调整行高到原来1.5
倍
/begin{table} /addtolength{/tabcolsep}{-2pt} //减少列宽-2pt
/begin{table} /small //缩小表格尺寸到最小
3. 表格的对齐及边框
/begin{tabular}{|l||r|r|r|c|}
此处,l表示left, r表示right, c表示center。上面表示表共有5列,列中文
字分别是左、右、右、右、
中对齐。
表格排版
与 word 不同,LaTeX 通过一定的语法规则将表格写成纯文本形式。基本规则包 括:
表格从上到下,每一行从左到右,单元格内容使用 & 分隔,用 \\ 换行。 最基本的表格
环境是 tabular 环境。下面是一个简单的表格代码和实际效果:
\begin{tabular}[t]{l|c}
\hline
姓名 & 年龄 \\
\hline %去掉的话就没有中间的线
张三 & 32 \\
李四 & 12 \\
王五 & 24 \\
\hline
\end{tabular}
表格排版:一般三线表的处理
学术论文普遍使用三线表。三线表的特点主要是:整个表格通常只有三条横线, 首
尾两条横线较粗,中间一条较细,一般不使用竖线。LaTeX 处理三线表相当简 单
方便。用到的宏包主要是 booktabs 。下面是普通三线表的代码和效果:
\begin{table}[htbp]
\caption{\label{tab:test}示例表格}
\begin{tabular}{lcl}
\toprule
姓名 & 年龄 & 地址\\
\midrule
张三 & 32 & 中华人民共和国\\
李四 & 12 & 中华人民共和国\\
王五 & 24 & 中华人民共和国\\
\bottomrule
\end{tabular}
\end{table}
表格排版:固定列宽
• 固定列宽可以使用 array 宏包的 p{2cm} 系列命令,如果需要指定水平对齐方
式,可以使用下面的形式 >{\centering}p{2cm} 实现,但如果使用这种方式,
缺省情况下不能使用 \\ 换行,需要使用\tabularnewline 代替。为了仍然使
用 \\ 换行,需要在导言区加上下面的代码:
\usepackage{array}
\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\newcolumntype{C}[1]{>{\PreserveBackslash\centering}p{#1}}
\newcolumntype{R}[1]{>{\PreserveBackslash\raggedleft}p{#1}}
\newcolumntype{L}[1]{>{\PreserveBackslash\raggedright}p{#1}}
•
•
•
•
•
• 使用 C{3cm} 命令即可指定该列宽度为 3cm,并且文字居中对齐,左对齐和
右对 齐命令分别是 L{2cm} 和 R{2cm} 。
• 下面是一个的例子:
表格排版:固定列宽
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
\begin{table}
\caption{Symbols on System Information}
\begin{center}
\begin{tabular}{c|C{8cm}} %中的竖线|表示列的竖线
\hline
$H_i$ & upper bound of Domaini's memory\\
\hline
$L_i$ & lower bound of Domaini's memory\\
\hline
$C_i$ & submitted amount of Domaini's memory that is claimed to use\\
\hline
$MC_i$ & submitted amount of Domaini's memory after adjustment according to $H_i$
and $L_i$\\
\hline
$N_i$ & amount of memory allocated to Domaini\\
\hline
$Nt_i$ & target amount of memory allocated to Domaini next time cycle without
bonus\\
\hline
$T_i$ & target amount of memory allocated to Domaini next time cycle with bonus\\
\hline
$F_i$ & free memory of Domaini\\
\hline
$A_i$ & active memory of Domaini,equals $N_i - F_i$\\\hline$SF_i$ & amount of idle
swap space of Domaini\\
\hline
$ST_i$ & amount of swap space of Domaini\\
\hline
\end{tabular}
\end{center}
\end{table}
表格排版
booktabs
它定义了三条划线命令:\toprule、\midrule 和 \bottomrule,可分别对表格顶部、
中部和底部使用不同粗细的水平线,见下例:
它还可以改变表格的行距,使表格尤其是长
表格更加美观。
该宏包可与 enfloat、threeparttable、
rotating 宏包配合使用。同时加载 colortbl
宏包,还可以划彩色格线。
使用 booktabs 宏包应注意:绝不要画垂直
线,绝不要画双线 ;如果表格左右两边的
内容毫无关联,最好将其分为两个表格而不
是用垂直线隔开。另外在排表格时,单位符
号应置于列首;相同数据不要用“同上”之类
的简称;0.1不要写成.1。
再加载 longtable 宏包,该宏包的三条划线
命令也可在跨页长表格中使用。
源文件
Simon Fear
表格排版
\begin{table}
\caption{Start Time of All Processes of Dacapo and 186.crafty}
\begin{center}
\begin{tabular}{@{}cccc@{}}
\toprule
\multicolumn{2}{c}{VM1} & \multicolumn{2}{c}{VM2}\\
\cmidrule(r){1-2}
\cmidrule(r){3-4}Process & Start time & Process & Start time\\ %这个是第二行的
\midrule186.crafty & 14.69 & antlr & 20.26 \\
antlr & 675.65 & bloat & 23.91 \\
bloat & 679.52 & chart & 35.05 \\
chart & 690.51 & eclipse & 46.86 \\
eclipse
fop
hsqldb & 834.68
jython & 842.07 & luindex & 202.01 \\
luindex
lusearch & 870.13 & pmd
pmd
xalan & 892.29 & 186.crafty & 277.75 \\
\bottomrule
\end{tabular}
\end{center}
\end{table}
& 702.2 & fop
& 830.54 & hsqldb & 178.4 \\
& jython & 185.26 \\
& 174.25 \\
& 859.11 & lusearch& 213.99 \\
& 227.79 \\
& 883.81 & xalan & 235.5 \\
表格排版:带表格注释的三线表
三线表有时候还需要加上注释以便给出表格的资料来源等信息。解决这一
问题可 以使用下面三个办法之一:
使用 ctable 宏包。该宏包用法简单,下面是典型代码和效果:
\ctable[%
caption=The Skewing Angles,
label=tab:nowidth,
]{lcc}
{\tnote{for the abstraction reaction,
$Mu+HX \rightarrow MuH+X$.}
\tnote[b]{1 degree${} = \pi/180$ radians.}
\tnote[c]{this is a particularly long note, showing that footnotes
are set in raggedright mode as we don't like hyphenation
in table footnotes.}
}
{\FL & $H(Mu)+F_2$ & $H(Mu)+Cl_2$ \ML
$\beta$(H) & $80.9$\tmark[b] & $83.2$ \NN
$\beta$(Mu) & $86.7$ & $87.7$ \LL
}