在表格单元格中换行

在表格单元格中换行

我对列标题“累计需要通过的课程数量”和“累计需要通过的高级课程数量”的文本对齐方式显然是错误的。我确实认识到这些是异常长的列标题,但目前我想不出比这更准确的术语。

在此处输入图片描述

我希望两个列标题能够更多地“环绕”在“BSc”和“EDP”周围,尽管不完全是。也许如果截止点在“课程”一词上(将“必修”移到第二行),那就太好了。此外,是否可以将 EDP 列稍微向右移动一点,以便它与上面的“课程”一词更紧密地对齐?

梅威瑟:

\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}

\begin{document}
\begin{table}[H]
\begin{threeparttable}
\caption{Minimum Requirements for Automatic Readmission into the Science Faculty}
\label{table:sci}
\begin{tabular}{@{}p{0.18\textwidth}*{4}{L{\dimexpr0.1\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{c}{\bfseries Cumulative Number of Courses Required to be Passed} &
\multicolumn{2}{c}{\bfseries Cumulative Number of Senior Courses Required to be Passed}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
& BSc & EDP & BSc & EDP  \\
\midrule
First-year & 2 & 2 & --- & ---  \\
Second-year & 7 & 6 & --- & --- \\
Third-year & 11 & 10 & 3 & 2 \\
Fourth-year & 15 & 14 & 6 & 5 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

答案1

我对您的表格做了三处修改:

1)我添加了\centering

2)我将右侧 4 列的宽度改为0.2\textwidth...,并且

3) 我将每个标题放在各自的 中\Longstack。这需要在序言中进行三处额外的调整:添加包stackengine;告诉包使用\#作为行尾,因为tabular已经在使用\\(请注意,最新stackengine版本 4.00 可以使用\\行尾分隔符,即使嵌套在 中tabular);并告诉包在堆栈行的基线之间设置 12pt,因为 将tabular的值清零\baselineskip,否则就是默认的长堆栈间隙。请注意,您可以给出\Longstacka[l][r]可选参数来将其从默认对齐方式更改[c]

\documentclass{article}
\usepackage{booktabs, threeparttable, stackengine}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\setstackEOL{\#}
\setstackgap{L}{12pt}
\begin{document}
\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{Minimum Requirements for Automatic Readmission into the Science Faculty}
\label{table:sci}
\begin{tabular}{@{}p{0.18\textwidth}*{4}{L{\dimexpr0.20\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{c}{\bfseries \Longstack{Cumulative Number\# of Courses Required\# to be Passed}} &
\multicolumn{2}{c}{\bfseries \Longstack{Cumulative Number of\# Senior Courses Required\# to be Passed}}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
& BSc & EDP & BSc & EDP  \\
\midrule
First-year & 2 & 2 & --- & ---  \\
Second-year & 7 & 6 & --- & --- \\
Third-year & 11 & 10 & 3 & 2 \\
Fourth-year & 15 & 14 & 6 & 5 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

在此处输入图片描述

答案2

不要使用cin \multicolumn{2}{c}{...but

 \multicolumn{2}{L{\dimexpr0.3\linewidth-8\tabcolsep\relax}}{...

完整代码:

\documentclass{article}
\usepackage{booktabs, threeparttable}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}


\begin{document}
\begin{table}[H]
\begin{threeparttable}
\caption{Minimum Requirements for Automatic Readmission into the Science Faculty}
\label{table:sci}
\begin{tabular}{@{}p{0.18\textwidth}*{4}{L{\dimexpr0.3\linewidth-8\tabcolsep\relax}}@{}}
\toprule
& \multicolumn{2}{L{\dimexpr0.4\linewidth-4\tabcolsep\relax}}{\bfseries Cumulative Number of Courses Required to be Passed} &
\multicolumn{2}{L{\dimexpr0.4\linewidth-4\tabcolsep\relax}}{\bfseries Cumulative Number of Senior Courses Required to be Passed}  \\
\cmidrule(l){2-3} \cmidrule(l){4-5}
& BSc & EDP & BSc & EDP  \\
\midrule
First-year & 2 & 2 & --- & ---  \\
Second-year & 7 & 6 & --- & --- \\
Third-year & 11 & 10 & 3 & 2 \\
Fourth-year & 15 & 14 & 6 & 5 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

在此处输入图片描述

相关内容