答案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}