我正在LaTeX中创建一个报告,其中涉及到几个表。我卡住了,因为我在表格中的单元格数据超过了页面的宽度。我能否以某种方式将文本换行,使其落入表中相同单元格中的下一行?
它是否与桌子的宽度有关?但由于它超出了页面的宽度,会有什么不同吗?
我正在LaTeX中创建一个报告,其中涉及到几个表。我卡住了,因为我在表格中的单元格数据超过了页面的宽度。我能否以某种方式将文本换行,使其落入表中相同单元格中的下一行?
它是否与桌子的宽度有关?但由于它超出了页面的宽度,会有什么不同吗?
当前回答
另一种选择是在每个需要文本换行的单元格中插入一个迷你页,例如:
\begin{table}[H]
\begin{tabular}{l}
\begin{minipage}[t]{0.8\columnwidth}%
a very long line a very long line a very long line a very long line
a very long line a very long line a very long line a very long line
a very long line a very long line a very long line %
\end{minipage}\tabularnewline
\end{tabular}
\end{table}
其他回答
使用p{width}作为列说明符,而不是l/r/c。
\begin{tabular}{|p{1cm}|p{3cm}|}
This text will be wrapped & Some more text \\
\end{tabular}
编辑:(根据评论)
\begin{table}[ht]
\centering
\begin{tabular}{p{0.35\linewidth} | p{0.6\linewidth}}
Column 1 & Column2 \\ \hline
This text will be wrapped & Some more text \\
Some text here & This text maybe wrapped here if its tooooo long \\
\end{tabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
我们得到:
简单得像一块蛋糕!
你可以定义一个新的列类型,比如(L),同时保持当前的对齐(c, r或L):
\documentclass{article}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\begin{document}
\begin{table}
\begin{tabular}{|c|L|L|}
\hline
Title 1 & Title 2 & Title 3 \\
\hline
one-liner & multi-line and centered & \multicolumn{1}{m{3cm}|}{multi-line piece of text to show case a multi-line and justified cell} \\
\hline
apple & orange & banana \\
\hline
apple & orange & banana \\
\hline
\end{tabular}
\end{table}
\end{document}
要在表格单元格中将文本AB更改为A \r B,请将其放入单元格位置:\makecell{A \\ B}。
在此之前,还需要包含包makecell。
我喜欢表格包的简单性:
\usepackage{tabulary}
...
\begin{tabulary}{\linewidth}{LCL}
\hline
Short sentences & \# & Long sentences \\
\hline
This is short. & 173 & This is much loooooooonger, because there are many more words. \\
This is not shorter. & 317 & This is still loooooooonger, because there are many more words. \\
\hline
\end{tabulary}
在本例中,您根据\textwidth来安排表的整个宽度。比如0.4。然后其余的工作由包自动完成。
大部分示例摘自http://en.wikibooks.org/wiki/LaTeX/Tables。
另一种选择是在每个需要文本换行的单元格中插入一个迷你页,例如:
\begin{table}[H]
\begin{tabular}{l}
\begin{minipage}[t]{0.8\columnwidth}%
a very long line a very long line a very long line a very long line
a very long line a very long line a very long line a very long line
a very long line a very long line a very long line %
\end{minipage}\tabularnewline
\end{tabular}
\end{table}