![固定表格列宽](https://linux22.com/image/313273/%E5%9B%BA%E5%AE%9A%E8%A1%A8%E6%A0%BC%E5%88%97%E5%AE%BD.png)
此代码中有两个表:
\documentclass[a4paper,11pt]{article}
\begin{document}
\title{}
\author{}
\date{\today}
\maketitle
\section{Header}
\begin{table}[!htbp] \centering
\footnotesize
\begin{tabular}{@{\extracolsep{5pt}} lll}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
Example & Reference \\\\[-1.8ex]
\cline{1-2}
\\[-1.8ex]
Northern Wheatears had higher reproductive success in higher vegetation height & ArltPart2007 \\
Mallards that avoided wetlands with large expanses of open water had higher reproductive success & BloomEtAl2013 \\
American Redstarts that occupied wet forest habitat in the winter raised more offspring than conspecifics occupying other habitats in the winter & NorrisEtAl2003 \\
Great Tits nesting in mature woodland produced larger broods than conspecifics nesting in gardens and hedgerows & RiddingtonGosler1995 \\
Reduction in winter stubble has led to a reduction in Reed Bunting survival rate & PeachEtAl1999 \\
Fledgling Ovenbird survival increased with vegetation structure & KingEtAl2006 \\
Daily nest survival of eight forest species was positively related to nest distance from the forest edge and nest height & NewmarkEtAl2011 \\
\hline \\[-1.8ex]
\end{tabular}
\caption{Examples of the effects on habitat on individual fitness.}
\label{table_fitness}
\end{table}
\begin{table}[!htbp] \centering
\footnotesize
\begin{tabular}{@{\extracolsep{5pt}} lll}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
Example & Reference \\\\[-1.8ex]
\cline{1-2}
\\[-1.8ex]
Northern Wheatears had higher reproductive success in higher\\ vegetation height & ArltPart2007 \\
Mallards that avoided wetlands with large expanses of open\\ water had higher reproductive success & BloomEtAl2013 \\
American Redstarts that occupied wet forest habitat in the\\ winter raised more offspring than conspecifics\\ occupying other habitats in the winter & NorrisEtAl2003 \\
Great Tits nesting in mature woodland produced larger\\ broods than conspecifics nesting in gardens and hedgerows & RiddingtonGosler1995 \\
Reduction in winter stubble has led to a reduction in Reed Bunting survival rate & PeachEtAl1999 \\
Fledgling Ovenbird survival increased with vegetation\\ structure & KingEtAl2006 \\
Daily nest survival of eight forest species was positively\\ related to nest distance from the forest edge and nest height & NewmarkEtAl2011 \\
\hline \\[-1.8ex]
\end{tabular}
\caption{Examples of the effects on habitat on individual fitness.}
\label{table_fitness}
\end{table}
\end{document}
产生如下结果:
在表 1 中,线条从 PDF 的边缘消失。因此,我添加了\\
将文本放在新行上。但是有没有办法自动创建列宽,以便将比列宽更宽的文本放在新行上?此外,我需要将参考资料向上移动一行 - 参见红色注释。
答案1
最初的问题:第一列的长条目被分成两行,放在两个表格行中。然后,将第二列的条目放在第二行。相反,您希望它在第一行:
Start of long text ... & Reference \\
long text continued & \\
但是,可以通过更优雅的方式解决这个问题,使用一X
列包tabularx
,然后第一列获取所有可用空间,并且条目会自动跨行拆分,请参阅回答Zarko 的。以下示例未使用\raggedright
,因为看起来列宽很大,对齐文本应该不会有太大问题。此外,我还缩进了以下几行,以便读者更容易找到下一个表格行。或者,可以添加一些垂直空间来分隔多行条目。
下一个问题是线条,看起来不太好;因此booktabs
使用了更好的包装线条。
\documentclass[a4paper,11pt]{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\footnotesize
\begin{tabularx}{\linewidth}{>{\hangindent=1em\hangafter=1 }Xl}
\toprule
Example & Reference \\
\midrule
Northern Wheatears had higher reproductive success in higher vegetation
height & ArltPart2007 \\
Mallards that avoided wetlands with large expanses of open water had
higher reproductive success & BloomEtAl2013 \\
American Redstarts that occupied wet forest habitat in the winter raised
more offspring than conspecifics occupying other habitats in the winter &
NorrisEtAl2003 \\
Great Tits nesting in mature woodland produced larger broods than
conspecifics nesting in gardens and hedgerows & RiddingtonGosler1995 \\
Reduction in winter stubble has led to a reduction in Reed Bunting
survival rate & PeachEtAl1999 \\
Fledgling Ovenbird survival increased with vegetation structure &
KingEtAl2006 \\
Daily nest survival of eight forest species was positively related to
nest distance from the forest edge and nest height & NewmarkEtAl2011 \\
\bottomrule
\end{tabularx}
\caption{Examples of the effects on habitat on individual fitness.}
\label{table_fitness}
\end{table}
\begin{table}
\centering
\footnotesize
\begin{tabularx}{\linewidth}{Xl}
\toprule
Example & Reference \\
\midrule
Northern Wheatears had higher reproductive success in higher vegetation
height & ArltPart2007 \\
\addlinespace
Mallards that avoided wetlands with large expanses of open water had
higher reproductive success & BloomEtAl2013 \\
\addlinespace
American Redstarts that occupied wet forest habitat in the winter raised
more offspring than conspecifics occupying other habitats in the winter &
NorrisEtAl2003 \\
\addlinespace
Great Tits nesting in mature woodland produced larger broods than
conspecifics nesting in gardens and hedgerows & RiddingtonGosler1995 \\
\addlinespace
Reduction in winter stubble has led to a reduction in Reed Bunting
survival rate & PeachEtAl1999 \\
\addlinespace
Fledgling Ovenbird survival increased with vegetation structure &
KingEtAl2006 \\
\addlinespace
Daily nest survival of eight forest species was positively related to
nest distance from the forest edge and nest height & NewmarkEtAl2011 \\
\bottomrule
\end{tabularx}
\caption{Examples of the effects on habitat on individual fitness.}
\label{table_fitness_addlinespace}
\end{table}
\end{document}
答案2
尝试:
\documentclass[a4paper,11pt]{article}
\usepackage{tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\begin{document}
\title{}
\author{}
\date{\today}
\maketitle
\section{Header}
\begin{table}[!htbp] \centering
\footnotesize
\begin{tabularx}{\hsize}{@{}Ll@{}}
\hline\hline
Example & Reference \\
\hline
Northern Wheatears had higher reproductive success in higher vegetation height
& ArltPart2007 \\
Mallards that avoided wetlands with large expanses of open water had higher reproductive success
& BloomEtAl2013 \\
American Redstarts that occupied wet forest habitat in the winter raised more offspring than conspecifics occupying other habitats in the winter
& NorrisEtAl2003 \\
Great Tits nesting in mature woodland produced larger broods than conspecifics nesting in gardens and hedgerows
& RiddingtonGosler1995 \\
Reduction in winter stubble has led to a reduction in Reed Bunting survival rate
& PeachEtAl1999 \\
Fledgling Ovenbird survival increased with vegetation structure
& KingEtAl2006 \\
Daily nest survival of eight forest species was positively related to nest distance from the forest edge and nest height
& NewmarkEtAl2011 \\
\hline
\end{tabularx}
\caption{Examples of the effects on habitat on individual fitness.}
\label{table_fitness}
\end{table}
\end{document}
\begin{table}[!htbp] \centering
\footnotesize
\begin{tabular}{@{\extracolsep{5pt}} lll}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
Example & Reference \\\\[-1.8ex]
\cline{1-2}
\\[-1.8ex]
Northern Wheatears had higher reproductive success in higher vegetation height & ArltPart2007 \\
Mallards that avoided wetlands with large expanses of open water had higher reproductive success & BloomEtAl2013 \\
American Redstarts that occupied wet forest habitat in the winter raised more offspring than conspecifics occupying other habitats in the winter & NorrisEtAl2003 \\
Great Tits nesting in mature woodland produced larger broods than conspecifics nesting in gardens and hedgerows & RiddingtonGosler1995 \\
Reduction in winter stubble has led to a reduction in Reed Bunting survival rate & PeachEtAl1999 \\
Fledgling Ovenbird survival increased with vegetation structure & KingEtAl2006 \\
Daily nest survival of eight forest species was positively related to nest distance from the forest edge and nest height & NewmarkEtAl2011 \\
\hline \\[-1.8ex]
\end{tabular}
\caption{Examples of the effects on habitat on individual fitness.}
\label{table_fitness}
\end{table}
我添加了tabularx
包并定义了新的列类型L
,允许在第一个表列中显示多行文本。您可以对第一个表执行类似操作。