考虑代码生成的两列表格环境的正确内容
\documentclass{book}
\begin{document}
\thispagestyle{empty}
\Large
\begin{tabular}{l l}
January: & Some content - second column; \, Why is this running off the page? \, Victories 41, defeats 4. \\
& A statement of the next line. \, Second statement. \\
& \\
February: & Some content - second column; \, would like to right-justify this column. \, Victories 41, defeats 4. \\
& A statement of the next line. \, Second statement. \\
& \\
March: & Some content - second column; \, Why is this running off the page? \, Victories 41, defeats 4. \\
& A statement of the next line. \, Second statement.
\end{tabular}
\end{document}
问题:我该如何防止行尾溢出?更具体地说,当文本宽度达到一定范围(或达到某个指定宽度)时,如何自动强制换行;并且第二列的后续内容也对齐?
谢谢。
答案1
使用tabularx
:
\documentclass{book}
\usepackage{tabularx}
%\usepackage{showframe}% To see the page layout
\begin{document}
\thispagestyle{empty}
\Large
\noindent
\begin{tabularx}{\linewidth}{l X}
January: & Some content - second column; Why is this running off the page? Victories 41, defeats 4. \\
& A statement of the next line. Second statement. \\
& \\
February: & Some content - second column; would like to right-justify this column. Victories 41, defeats 4. \\
& A statement of the next line. Second statement. \\
& \\
March: & Some content - second column; Why is this running off the page? Victories 41, defeats 4. \\
& A statement of the next line. Second statement.
\end{tabularx}
\end{document}
您可以调整列分隔并(例如)将其用作@{} l X @{}
列规范。请注意,在表格内设置此项将不允许正确跨页边界(垂直)分页。
或者(并且更好,因为完全支持分页)使用列表(如description
):
\documentclass{book}
\usepackage{enumitem}
%\usepackage{showframe}% To show the document layout
\begin{document}
\thispagestyle{empty}
\Large
\begin{description}[leftmargin=5em,labelwidth=5em,labelsep=0pt,font=\mdseries]
\item[January:] Some content - second column; Why is this running off the page? Victories 41, defeats 4. \par
A statement of the next line. Second statement.
\item[February:] Some content - second column; would like to right-justify this column. Victories 41, defeats 4. \par
A statement of the next line. Second statement.
\item[March:] Some content - second column; Why is this running off the page? Victories 41, defeats 4. \par
A statement of the next line. Second statement.
\end{description}
\end{document}