![表格标题分布在两行上,使表格更短](https://linux22.com/image/414545/%E8%A1%A8%E6%A0%BC%E6%A0%87%E9%A2%98%E5%88%86%E5%B8%83%E5%9C%A8%E4%B8%A4%E8%A1%8C%E4%B8%8A%EF%BC%8C%E4%BD%BF%E8%A1%A8%E6%A0%BC%E6%9B%B4%E7%9F%AD.png)
答案1
您需要将前两列更改为段落列,可以使用 `p{} 或 X-column(您必须更改为 tabularx 或 xltabular)。
如果您使用 tabularx,则可以将前两列设置为固定宽度p
列,将第三列设置X
为使用边距之间剩余可用空间的列。请参阅示例 2,我将在一两分钟内提供。
如果您需要多页表格,请指出,我会更新代码。也可以将列设置为右侧不规则。
示例 1 - 表格
\documentclass{article}
\usepackage{array, booktabs}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
\begin{tabular}{@{}p{2cm}p{2cm}p{5cm}@{}}
\toprule
\bfseries Theme & \bfseries Code & \bfseries Description\\
\midrule
Preparatory Work & Omitting a step & Lot of interesting text that fills up lots of lines. Even more lines than you can think of if you continue to write nonsense!\\
\bottomrule
\end{tabular}
\end{document}
示例 2 - tabularx
\documentclass{article}
\usepackage{tabularx, booktabs}
\usepackage[margin=2.5cm]{geometry}
\begin{document}
\begin{tabularx}{\linewidth}{@{}p{2cm}p{2cm}X@{}}
\toprule
\bfseries Theme & \bfseries Code & \bfseries Description\\
\midrule
Preparatory Work & Omitting a step & Lot of interesting text that fills up lots of lines. Even more lines than you can think of if you continue to write nonsense! As you see, column three expands to take the rest of the line width.\\
\bottomrule
\end{tabularx}
\end{document}
答案2
如果您需要在表格单元格内添加换行符的情况有限,可以使用该makecell
包。如果表格中出现更多换行符(或更具体:在某一列中),您绝对应该查看p
列,提及的 Sveinung。
\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage{makecell}
\begin{document}
\begin{center}
\begin{tabularx}{\linewidth}{ll>{\raggedright}Xr}
\toprule
\textbf{Label 1}& \textbf{Label 2}&\textbf{Label 3}& $N$\\
\midrule
\makecell[lt]{preparatory\\ work} &\makecell[lt]{Adding\\ information}&
Description on several lines. Description on several lines.
Description on several lines. Description on several lines.
& 2
\\
&\makecell[lt]{organizing\\ information}&
New Description on several lines. Description on several lines.
Description on several lines. Description on several lines.
& 3
\\
word &short term&
Description on several lines. Description on several lines.
Description on several lines. Description on several lines.
& 2
\\
\bottomrule
\end{tabularx}
\end{center}
\end{document}