代码
\begin{table}[]
\centering
\begin{tabular}{|l|l|}
\hline
7 Seven & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
3 3c Three-C\\ \phantom{3 }3b Three-B\\ \phantom{3 }3a Three-A & 3 Three\\ \hline
2 2b Two-B\\ \phantom{2 }2a Two-A & 2 Two\\ \hline
1 1b One-B\\ \phantom{1 }1a One-A & 1 One\\ \hline
\end{tabular}
\end{table}
产生以下输出:
我查找了几种将单元格“3 Three”、“2 Two”和“1 One”对齐到顶部的方法,但目前都不起作用。此外,右侧的线条也不完整。
另一个问题是字母“a”、“b”和“c”的宽度不同。因此,“Three-C”、“Three-B”和“Three-A”等没有与完美的垂直线对齐。我认为制表符可以解决这个问题。但在表格中使用制表符是否可行?表格单元格内的换行符是否正确?它们在 TeXstudio for Windows 中以红色标记:
答案1
下面的代码怎么样?
编辑:右列与顶部对齐。
\documentclass[]{scrartcl}
\begin{document}
\begin{tabular}{|l|l|}
\hline
7 Seven & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
\begin{tabular}[t]{@{}l@{}l@{}}
3~ & 3c Three-C\\
& 3b Three-B\\
& 3a Three-A
\end{tabular}&
3 Three\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
2~ & 2b Two-B\\
& 2a Two-C\\
\end{tabular}&
2 Two\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
1~ & 1b One-B\\
& 1a One-C\\
\end{tabular}&
1 One\\\hline
\end{tabular}
\end{document}
答案2
建议:将数字放在各自的列中,以使其对齐
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|lll|l|}
\hline
7 & \multicolumn{2}{l|}{Seven} & 7 Seven\\ \hline
6 &\multicolumn{2}{l|}{Six} & 6 Six\\ \hline
5 &\multicolumn{2}{l|}{Five} & 5 Five\\ \hline
4 &\multicolumn{2}{l|}{Four} & 4 Four\\ \hline
3 & 3c & Three-C & 3 Three\\
& 3b & Three-B & \\
& 3a & Three-A & \\ \hline
2 & 2b & Two-B & 2 Two\\
& 2a & Two-A & \\ \hline
1 & 1b & One-B & 1 One\\
& 1a & One-A & \\ \hline
\end{tabular}
\end{table}
\end{document}
或者按照Mico 的建议间距更紧密的版本:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|l@{\ }l@{\ }l|l|}
\hline
7 & \multicolumn{2}{@{}l|}{Seven} & 7 Seven\\ \hline
6 & \multicolumn{2}{@{}l|}{Six} & 6 Six\\ \hline
5 & \multicolumn{2}{@{}l|}{Five} & 5 Five\\ \hline
4 & \multicolumn{2}{@{}l|}{Four} & 4 Four\\ \hline
3 & 3c & Three-C & 3 Three\\
& 3b & Three-B & \\
& 3a & Three-A & \\ \hline
2 & 2b & Two-B & 2 Two\\
& 2a & Two-A & \\ \hline
1 & 1b & One-B & 1 One\\
& 1a & One-A & \\ \hline
\end{tabular}
\end{table}
\end{document}
答案3
感谢您,我几乎找到了完美的答案。
\begin{tabular}{|l|l|}
\hline
7 Seven & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
\begin{tabular}[t]{@{}l@{}l@{}}
3 3c~ & Three-C\\
\phantom{3 }3b & Three-B\\
\phantom{3 }3a & Three-A
\end{tabular}&
3 Three\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
2 2b~ & Two-B\\
\phantom{2 }2a~ & Two-A\\
\end{tabular}&
2 Two\\\hline
\begin{tabular}[t]{@{}l@{}l@{}}
1 1b~ & One-B\\
\phantom{1 }1a~ & One-A\\
\end{tabular}&
1 One\\\hline
\end{tabular}
但现在,仔细看看:
我知道这是由于各种表格区域造成的。
samcarter 的解决方案可以避免这种情况,但是空白区域很大。
答案4
哦,让我们把 TABstack 放进去...它可以同时完成几件事:
它提供了一个堆叠列表
它可以将该列表与顶行对齐
它可以将分成几列,
3a
以便Three-C
实现正确的列对齐。
妇女权利委员会:
\documentclass{article}
\usepackage{tabstackengine}
\setstacktabbedgap{1ex}
\newcommand\mytabstack[1]{{\addstackgap[2pt]{\tabbedLongunderstack[l]{#1}}}}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{|l|l|}
\hline
7 Seven & 7 Seven\\ \hline
6 Six & 6 Six\\ \hline
5 Five & 5 Five\\ \hline
4 Four & 4 Four\\ \hline
3 \mytabstack{3c & Three-C\\ 3b & Three-B\\ 3a & Three-A} & 3 Three\\ \hline
2 \mytabstack{2b & Two-B\\ 2a & Two-A} & 2 Two\\ \hline
1 \mytabstack{1b & One-B\\ 1a & One-A} & 1 One\\ \hline
\end{tabular}
\end{table}
\end{document}
如果您希望堆叠单元格中的垂直间距更像tabular
的固有行为,则重新定义
\newcommand\mytabstack[1]{{\tabbedLongunderstack[l]{\strut#1\strut}}}
实现