0

I have the following table below and I would like to wrap the text in each column so that the table does not exceed the width of the page. I have tried several solutions but they seem to shrink the table.

Can you please advise? I have included my code and a screenshot of what the output currently looks like.

Thanks!

\documentclass[a4paper,11pt]{article}
\usepackage{tabulary}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{pdflscape,afterpage,booktabs,caption}

\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test - contents of table exceeds page width}
\setlength\tabcolsep{3pt}
\centering
  \small
 % your table
    \hspace*{-18mm}%
\begin{tabular}{cccc}
\hline\hline
Column 1&Column 2&Column 3\\ [0.5ex]
\hline
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
\hline
 \end{tabular}%
    \hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}

\end{document}

enter image description here

3 Answers 3

2

You could use the p{} column specifier, with which you can explicitly set the width of the column. Also, since you already load the booktabs package (even twice!), you should actually use it:

\documentclass[a4paper,11pt]{article}
\usepackage{tabulary}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{pdflscape,afterpage,caption}

\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test -- contents of table exceeds page width}
\setlength\tabcolsep{3pt}
\centering
  \small
 % your table
    \hspace*{-18mm}%
\begin{tabular}{ l p{60mm} p{60mm} p{60mm} }
\toprule
Column 1&Column 2&Column 3&Column 4\\ [0.5ex]
\midrule
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
\bottomrule
 \end{tabular}%
    \hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}

\end{document}

enter image description here

4

Some improvements, using tabularx so the table with be exactly text width of a landscape page, and some more spacing between rows:

\documentclass[a4paper,11pt]{article}
\usepackage{tabularx}
\usepackage{booktabs,caption, makecell}
\usepackage{pdflscape,afterpage}
\renewcommand{\theadfont}{\normalsize\bfseries}

\begin{document}

\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test - contents of table exceeds page width}
\centering
  \small
\begin{tabularx}{\linewidth}{@{}l*{3}{>{\arraybackslash}X}}
\toprule\midrule[0.5pt]
 & \thead{Column 1} & \thead{Column 2} & \thead{Column 3} \\
\midrule
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 \\
\addlinespace
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1 \\
\addlinespace
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1 \\
\addlinespace
Item 1 & item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1, item 1,item 1, item 1, item 1, item 1, item 1, item 1 & item 1, item 1, item 1, item 1 \\
\bottomrule
 \end{tabularx}%
    \hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}

\end{document} 

enter image description here

3

Since you are already loading tabulary you might want to benefit from its flexible width columns to create a table that uses the whole textblock height:

\documentclass[a4paper,11pt]{article}
\usepackage{tabulary}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{pdflscape,afterpage,caption}

\begin{document}
\begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Table test - contents of table exceeds page width}
\setlength\tabcolsep{3pt}
\centering
  \small
 % your table
    \hspace*{-18mm}%
\begin{tabulary}{\linewidth}{cCCC}
\toprule
Column 1&Column 2&Column 3\\ [0.5ex]
\midrule
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
Item 1&item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1, item 1&item 1, item 1, item 1, item 1, item 1,item 1 ,item 1 ,item 1 ,item 1 ,item 1 ,item 1&item 1, item 1, item 1, item 1\\
\bottomrule
 \end{tabulary}%
    \hspace*{-12mm}%
\label{table:comparison of techniques}
\end{table}
\end{landscape}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .