使表格跨度文本宽度精确

使表格跨度文本宽度精确

考虑这个例子:

\documentclass{report}
\usepackage{lipsum}
\begin{document}
\begin{tabular}{lll}
  A & B & \lipsum[1][1-3]
\end{tabular}
\end{document}

在输出中: 在此处输入图片描述

最后一列超出了页面范围。我可以使用 来限制最后一列\begin{tabular}{llp{3cm}}。但是,让表格自动跨越文本宽度会更方便。怎么做?

答案1

withtabularx包很简单:

\documentclass{report}
\usepackage{tabularx}             % <---
\usepackage{lipsum}

\noindent
\begin{document}
\begin{tabularx}{\linewidth}{llX}  % table width is determined with \linewidth
                                   % at least one column had to be `X` type
  A & B & \lipsum[66]
\end{tabularx}

\noindent
\begin{tabularx}{\linewidth}{@{} llX @{}} % border \tabcolsep is suppressed
  A & B & \lipsum[66]
\end{tabularx}

\begin{table}[htb]                      % table is in float environment
\begin{tabularx}{\linewidth}{@{}llX@{}} % border \tabcolsep is suppressed
  A & B & \lipsum[66]
\end{tabularx}
\end{table}

\end{document}

在此处输入图片描述

相关内容