表格宏包:\usepackage{booktabs}
调整表格内文字位置
命令:\makecell[c]
(缺省时默认居中,其余选项 t,b,l,r,c )
宏包: \usepackage{makecell}
手动调整表格列宽
命令:\begin{tabular}{p{ x cm}<{\centering}}
(x
表示需要设置的列宽的数字)
e.g.,
\begin{table}[t]
\centering
\scriptsize
\caption{Example}
\scalebox{1}
{
\begin{tabular}{p{0.5cm}<{\centering}|p{0.7cm}<{\centering}|p{0.9cm}<{\centering}|p{1.1cm}<{\centering}|}\toprule[1.5pt]
C1 & C2 & C3& C4\\\hline
C1 & C2 & C3& C4\\
C1 & C2 & C3& C4\\ \bottomrule[1.5pt]
\end{tabular}
}
\end{table}
表格内文字换行
命令:\makecell[c]{...\\...}
(\\
表示换行 )
宏包: \usepackage{makecell}
e.g.,
\begin{table}[t]
\centering
\scriptsize
\caption{Example}
\scalebox{1}
{
\begin{tabular}{ccccc}
\toprule[1.5pt]
\multirow{2}*{\makecell[c]{C1-1\\C1-2}} & \multirow{2}*{C2} &\multicolumn{3}{c}{C3} \\ \cline{3-5}
&& C3-1& C3-2&C3-3\\\bottomrule[1.5pt]
\end{tabular}
}
\end{table}
添加表格横线,调整粗细
命令:
\hline
\cline[n-m]
(可以选择列n-m
添加横线,列数从1开始计数)
\toprule
\midrule
\bottomrule
注意:当使用这些命令时,需要在前面加 \\
即正确使用方法是:
例如:
\\ \hline
其中,\toprule
、\midrule
、\bottomrule
可以通过在命令后加 []
调整横线粗细,但需要导入宏包
\usepackage{booktabs}
例如:
\\ \midrule[1.5pt]
e.g.,
\begin{table}[t]
\centering
\scriptsize
\caption{Example}
\scalebox{1}
{
\begin{tabular}{c}\toprule[1.5pt]
Row1\\\hline
Row2\\ \midrule[1pt]
Row3\\\bottomrule[1.5pt]
\end{tabular}
}
\end{table}
多行,多列合并
命令: \multirow{n}*{}
\multicolumn{n}{c}{}
(n代表需要合并的行数或列数, *
, {c}
都表示居中,且不能互相替换)
宏包: \usepackage{multirow}
e.g.,
\begin{table}[t]
\centering
\scriptsize
\caption{Example}
\scalebox{1}
{
\begin{tabular}{ccccc}
\toprule[1.5pt]
\multirow{2}*{C1} & \multirow{2}*{C2} &\multicolumn{3}{c}{C3} \\ \cline{3-5}
&& C3-1& C3-2&C3-3\\\bottomrule[1.5pt]
\end{tabular}
}
\end{table}
表格内换行
命令:\makecell[c]{...\\...}
(c
表示居中
宏包:\usepackage{makecell}
e.g.,
\begin{table}[t]
\centering
\scriptsize
\caption{Example}
\scalebox{1}
{
\begin{tabular}{cccc}
\toprule[1.5pt]
C1&C2&C3&\makecell[c]{C4-1\\C4-2}\\
\bottomrule[1.5pt]
\end{tabular}
}
\end{table}
斜表线
(更详细的教程可参考 diagbox 宏包 - 为空单元格绘制斜表线
命令:\diagbox{}{}
宏包:\usepackage{diagbox}
\begin{table}[t]
\centering
\scriptsize
\caption{Example}
\scalebox{1}
{
\begin{tabular}{cccc}
\toprule[1.5pt]
\diagbox{C1-1}{C1-2}{C1-3} &C2&C3&C4\\\hline
&C2-1&C3-1&C4-1\\
&C2-2&C3-2&C4-2\\
\bottomrule[1.5pt]
\end{tabular}
}
\end{table}