我创建了一个表格如下:
\documentclass{article}
\usepackage{array,booktabs}
\usepackage{colortbl}
\usepackage{xcolor}
\begin{document}
\newcolumntype{L}{@{}>{\kern\tabcolsep}l<{\kern\tabcolsep}}
\begin{table}[htp]
\caption{Indicators for sustainable transportation \citep{r2}}
\label{tab: ind}
\centering
\footnotesize\setlength{\tabcolsep}{2.5pt}
\begin{tabular}{@{} l L L L @{} >{\kern\tabcolsep}l @{}} \toprule
\emph{Objective} & \emph{Indicator} & \emph{Direction} &&& \\\midrule
\emph{Economic} & & & & \\
\rowcolor{black!3}[0pt][0pt] Transport diversity & Mode split: portion of travel made by walking, cycling, rideshare, public transit and telework & More is better \\
\emph{Social} & & & & \\
\rowcolor{black!6}[0pt][0pt] Health and fitness & Percentage of population that regularly walks and cycles & More is better \\
\rowcolor{black!8}[0pt][0pt] Non-motorized transport planning & Degree to which impacts on non-motorized transport are considered in transportation modeling and planning & More is better \\
\emph{Environmental} & & & & \\
\rowcolor{black!10}[0pt][0pt] Resource efficiency & Non-renewable resource consumption in the production and use of vehicles and transport facilities & Less is better \\
\rowcolor{black!12}[0pt][0pt] Climate change emissions & Per capita fossil fuel consumption, and emissions of CO2 and other climate change emissions & Less is better \\
\rowcolor{black!14}[0pt][0pt] Noise pollution & Portion of population exposed to high levels of traffic noise & Less is better \\
\bottomrule
\hline
\end{tabular}
\end{table}
\end{document}
输出结果如下:
如您所见,表格的一部分超出了边框。此问题是由于单元格的文本太长而引起的。
我怎样才能自动修复它?
答案1
详细阐述 Werner 的评论。您可以使用列类型p
来指定列的特定宽度。在您的背景示例中,我认为最简单的方法是指定空白列来容纳彩色列间空间:
\documentclass{article}
\usepackage{array,booktabs}
\usepackage{colortbl}
\usepackage{xcolor}
\begin{document}
\begin{table}[htp]
\caption{Indicators for sustainable transportation}
\label{tab: ind}
\centering
\footnotesize\setlength{\tabcolsep}{0pt}
\begin{tabular}{p{2cm} p{10pt} p{5cm} p{10pt} l} \toprule
\emph{Objective} && \emph{Indicator} && \emph{Direction} \\\midrule
\emph{Economic} && && \\
\rowcolor{black!3}[0pt][0pt] Transport diversity && Mode split: portion of travel made by walking, cycling, rideshare, public transit and telework && More is better \\
\emph{Social} && && \\
\rowcolor{black!6}[0pt][0pt] Health and fitness && Percentage of population that regularly walks and cycles && More is better \\
\rowcolor{black!8}[0pt][0pt] Non-motorized transport planning && Degree to which impacts on non-motorized transport are considered in transportation modeling and planning && More is better \\
\emph{Environmental} && && \\
\rowcolor{black!10}[0pt][0pt] Resource efficiency && Non-renewable resource consumption in the production and use of vehicles and transport facilities && Less is better \\
\rowcolor{black!12}[0pt][0pt] Climate change emissions && Per capita fossil fuel consumption, and emissions of CO2 and other climate change emissions && Less is better \\
\rowcolor{black!14}[0pt][0pt] Noise pollution && Portion of population exposed to high levels of traffic noise && Less is better \\
\bottomrule
\hline
\end{tabular}
\end{table}
\end{document}
或者,您可以使用tabularx
来获取具有规范的可变宽度列X
。现在您必须指定表格的总宽度:
\documentclass{article}
\usepackage{array,booktabs}
\usepackage{colortbl,tabularx}
\usepackage{xcolor}
\begin{document}
\begin{table}[htp]
\caption{Indicators for sustainable transportation}
\label{tab: ind}
\centering
\footnotesize\setlength{\tabcolsep}{0pt}
\begin{tabularx}{\textwidth}{>{\hsize=0.6\hsize}X p{10pt} >{\hsize=1.4\hsize}X p{10pt} l} \toprule
\emph{Objective} && \emph{Indicator} && \emph{Direction} \\\midrule
\emph{Economic} && && \\
\rowcolor{black!3}[0pt][0pt] Transport diversity && Mode split: portion of travel made by walking, cycling, rideshare, public transit and telework && More is better \\
\emph{Social} && && \\
\rowcolor{black!6}[0pt][0pt] Health and fitness && Percentage of population that regularly walks and cycles && More is better \\
\rowcolor{black!8}[0pt][0pt] Non-motorized transport planning && Degree to which impacts on non-motorized transport are considered in transportation modeling and planning && More is better \\
\emph{Environmental} && && \\
\rowcolor{black!10}[0pt][0pt] Resource efficiency && Non-renewable resource consumption in the production and use of vehicles and transport facilities && Less is better \\
\rowcolor{black!12}[0pt][0pt] Climate change emissions && Per capita fossil fuel consumption, and emissions of CO2 and other climate change emissions && Less is better \\
\rowcolor{black!14}[0pt][0pt] Noise pollution && Portion of population exposed to high levels of traffic noise && Less is better \\
\bottomrule
\hline
\end{tabularx}
\end{table}
\end{document}
这里我使用了两X
列,每列都有一个规格>{\hsize=x\hsize}
。重要的是,x
s 的总和是列数X
。s 之间的比率x
给出了相应列的宽度比率X
。