我想知道如何调整表格内文本的对齐方式。例如,我想让表格左列的某些行中的文本发生偏移,这些行代表标题。我该如何做才能让某一行稍微向右移动一点。非常感谢您的帮助。
答案1
有多种方法可以实现这一点。这里仅介绍两种。
在列中的每个元素前添加空格,并删除标题前的空格。使用 进行自动插入
>{<stuff>} l
,而\multicolumn{1}{c}
避免这种插入。\documentclass{article} \usepackage{booktabs,array} \begin{document} \begin{table} \centering \newcommand{\rowhead}[1]{\multicolumn{1}{l}{\bfseries #1}}% \begin{tabular}{ >{\hspace*{1em}}l c } \toprule \multicolumn{1}{c}{\bfseries Heading} & \bfseries Stuff \\ \midrule \rowhead{Subheading 1} \\ Something weird here & 2 \\ Something completely different & 3 \\ Who knows & 4 \\ \addlinespace \rowhead{Subheading 2} \\ Something weird here & 5 \\ Something completely different & 6 \\ Who knows & 7 \\ \bottomrule \end{tabular} \caption{Some table} \end{table} \end{document}
添加一个表示空间的额外列,并设置跨两列的标题。您可以调整第一列的宽度以增加/减少空间。请注意,列分隔 (
\tabcolsep
) 在此处仍然有效。\documentclass{article} \usepackage{booktabs} \begin{document} \begin{table} \centering \newcommand{\rowhead}[1]{\multicolumn{2}{l}{\bfseries #1}}% \begin{tabular}{ l l c } \toprule \multicolumn{2}{c}{\bfseries Heading} & \bfseries Stuff \\ \midrule \rowhead{Subheading 1} \\ & Something weird here & 2 \\ & Something completely different & 3 \\ & Who knows & 4 \\ \addlinespace \rowhead{Subheading 2} \\ & Something weird here & 5 \\ & Something completely different & 6 \\ & Who knows & 7 \\ \bottomrule \end{tabular} \caption{Some table} \end{table} \end{document}