在下表中,第一列的标题不知为何有点偏离。为什么会出现这种情况?我该如何进一步让其整体看起来更好?
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\begin{tabular}{@{}ccccccc@{}}
\toprule
\multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}Present\\State\end{tabular}} & \multicolumn{2}{c}{Input} & \multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}Next\\ State\end{tabular}} & Output \\
\cmidrule(l){1-2} \cmidrule(lr){5-6} \cmidrule(lr){3-4} \cmidrule(l){7-7}
A & B & x & y & A & B & z \\ \midrule
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 0 \\
0 & 0 & 1 & 1 & 0 & 1 & 0 \\ [1ex]
0 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 1 & 1 & 1 & 1 & 0 & 0 \\[1ex]
1 & 0 & 0 & 0 & 0 & 0 & 1 \\
1 & 0 & 0 & 1 & 0 & 0 & 1 \\
1 & 0 & 1 & 0 & 1 & 1 & 1 \\
1 & 0 & 1 & 1 & 0 & 1 & 1 \\[1ex]
1 & 1 & 0 & 0 & 0 & 0 & 1 \\
1 & 1 & 0 & 1 & 0 & 0 & 1 \\
1 & 1 & 1 & 0 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
由于
\begin{tabular}{@{}ccccccc@{}}
用作列说明符,因此必须使用
\multicolumn{2}{@{}c}{....
同样,即通过说删除第一列的水平空间@{}c
。
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\begin{tabular}{@{}ccccccc@{}}
\toprule
\multicolumn{2}{@{}c}{\begin{tabular}[c]{@{}c@{}}Present\\State\end{tabular}} & \multicolumn{2}{c}{Input} & \multicolumn{2}{c}{\begin{tabular}[c]{@{}c@{}}Next\\ State\end{tabular}} & Output \\
\cmidrule(r){1-2} \cmidrule(lr){5-6} \cmidrule(lr){3-4} \cmidrule(l){7-7}
A & B & x & y & A & B & z \\ \midrule
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 0 \\
0 & 0 & 1 & 1 & 0 & 1 & 0 \\ [1ex]
0 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 1 & 1 & 1 & 1 & 0 & 0 \\[1ex]
1 & 0 & 0 & 0 & 0 & 0 & 1 \\
1 & 0 & 0 & 1 & 0 & 0 & 1 \\
1 & 0 & 1 & 0 & 1 & 1 & 1 \\
1 & 0 & 1 & 1 & 0 & 1 & 1 \\[1ex]
1 & 1 & 0 & 0 & 0 & 0 & 1 \\
1 & 1 & 0 & 1 & 0 & 0 & 1 \\
1 & 1 & 1 & 0 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 & 1 & 1 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}