我想制作一个只有 1 列的表格。我希望表格具有固定宽度并包含多个句子。由于某些句子可能很长,因此可能需要多行来容纳 1 个句子。这是一个包含 3 个句子的表格的样子(抱歉我无法很好地画出垂直线和水平线):
---------------------------
| Sentence 1 is very very |
| very very long. |
---------------------------
| Sentence 2 is short. |
---------------------------
| Sentence 3 is very very |
| very very very very ve- |
| -ry very long. |
---------------------------
所以我不想手动将一个句子分成几行,我希望一旦指定了表格的宽度,LaTeX 就可以做到这一点。因此,表格的高度取决于所有句子的长度......
有人知道这是否可能吗?
答案1
不是太漂亮,但作为一个起点......
\documentclass{article}
\begin{document}
\begin{tabular}{|p{5cm}|} % The value that you need in place of 5cm
\hline
Sentence 1 is very very
very very long. \\
\hline
Sentence 2 is short. \\
\hline
Sentence 3 is very very
very very very very very very
very very very very very very long. \\
\hline
\end{tabular}
\end{document}
答案2
p
为此制作了列:
% arara: pdflatex
\documentclass{article}
\usepackage{booktabs}
\usepackage{microtype} % for nice justifying in narrow columns
\begin{document}
\begin{table}
\begin{tabular}{p{3cm}}\toprule
Sentence 1 is very very very very long.\\\addlinespace
Sentence 2 is short.\\\addlinespace
Sentence 3 is very very
very very very very very very long.\\\bottomrule
\end{tabular}
\end{table}
\end{document}
如果您加载 ,大多数情况下都不需要连字符microtype
。如果需要,请加载\usepackage[english]{babel}
。
如果您希望列在右边(对于短文本片段来说看起来会更好),您可以在此站点搜索包array
并将\raggedright
-command 添加到您喜欢的每一列。