表格标题分布在两行上,使表格更短

表格标题分布在两行上,使表格更短

我的桌子上写着......

\begin{center}
\begin{tabularx} {\linewidth}{ll>{\raggedright}Xr} 

桌子

但我想将前两列中的文本(例如准备工作和省略步骤)分散到两行,因为我想减少前两列的宽度,增加第三列的宽度。我试过了,\multicolumn{1}{m{2cm}但没有用。

有没有更简单更好的方法?(请为不懂编程的人解释一下)

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

相关内容