Latex 表格命令总结

表格宏包:\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}	

在这里插入图片描述

  • 10
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值