3

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.

4

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

  • Your Table 2 has even solved my next problem - line spaces. Many thanks! – luciano Jun 13 '15 at 9:20
  • The \hangindent macro is really nice; I didn't knew about that. :) – Svend Tveskæg Jun 13 '15 at 9:22
  • @SvendTveskæg It's a primitive command/dimen register similar to \parindent, but its effect is limited to one paragraph like \looseness. – Heiko Oberdiek Jun 13 '15 at 9:56
  • @HeikoOberdiek Exxxxxxcellent (to quote Mr. Burns)! – Svend Tveskæg Jun 13 '15 at 10:26
3

Try:

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

enter image description here

I add the tabularx package and define new column type L which allow multi line text in first table column. Similarly you can do with for first table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.