[Tex/LaTex] Fix column width of table

columnstableswidth

I have two tables in this code:

\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}

The produces this:

enter image description here

In table 1, the lines disappear off the edges of the PDF. Therefore I have added \\ to put text on new lines. But is there a way to automatically create a column width so that text wider than the column width will be put on a new line? Also I need the references moved a line up – see red annotation.

Best Answer

The original problem: The long entry of the first column was split in two lines in two table rows. The entry of the second column was then put in the second row. Instead, you want it in the first row:

Start of long text ... & Reference \\
long text continued    & \\

However, this can be solved in a more elegant way with an X column of package tabularx, then the first column gets all the available space and the entry is broken across lines automatically, see the answer of Zarko. The following example does not use \raggedright, because it seems that the column width is so large, that justified text should work without much trouble. Also I have indented the following lines to make it easier for the reader to find the next table row. Alternatively some vertical space can be added to separate the multi-line entries.

The next problem are the lines, which do not look too good; therefore the nicer lines of package booktabs are used.

\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}

Result

Related Question