# How to make really wide tables narrower

Is there a way to fix extremely wide tables?

I have the following table:

\begin{tabular}{lllll}
\toprule
&  Manual Tests & Randoop 2.5 Minutes With GUI Code &  Randoop 2.5 Minutes Without GUI Code &  Randoop 5 Minutes Without GUI Code \\ \midrule
\% Covered Instructions &  \textbf{82.40\%} &  21.25\% &  21.30\% &  \textbf{22.10\%} \\ \bottomrule
\end{tabular}


And it looks like so:

Is there a way to make the cells slimmer? If relevant I am using scrreprt.

-

You can use p{width} column type for a fixed column, text will wrap automatically. For example:

\begin{tabular}{*{5}{p{3cm}}}
\toprule
&  Manual Tests & Randoop 2.5 Minutes With GUI Code &  Randoop 2.5 Minutes Without GUI Code &  Randoop 5 Minutes Without GUI Code \\ \midrule
\% Covered Instructions &  \textbf{82.40\%} &  21.25\% &  21.30\% &  \textbf{22.10\%} \\ \bottomrule
\end{tabular}


You can also use \shortstack and use \\ for manual line break. For example:

\begin{tabular}{ccccc}
\toprule
&  Manual Tests & \shortstack{Randoop 2.5 Minutes\\ With GUI Code} &  \shortstack{Randoop 2.5 Minutes\\ Without GUI Code} &  \shortstack{Randoop 5 Minutes\\ Without GUI Code} \\ \midrule
\% Covered Instructions &  \textbf{82.40\%} &  21.25\% &  21.30\% &  \textbf{22.10\%} \\ \bottomrule
\end{tabular}


\shortstack here can be replaced by a small tabular envronment, for better vertical alignment:

\newcommand{\minitab}[2][c]{\begin{tabular}{#1}#2\end{tabular}}

\begin{tabular}{ccccc}
\toprule
&  Manual Tests & \minitab{Randoop 2.5 Minutes\\ With GUI Code} &  \minitab{Randoop 2.5 Minutes\\ Without GUI Code} &  \minitab{Randoop 5 Minutes\\ Without GUI Code} \\ \midrule
\% Covered Instructions &  \textbf{82.40\%} &  21.25\% &  21.30\% &  \textbf{22.10\%} \\ \bottomrule
\end{tabular}


Furthermore, you can use makecell package for more flexible commands. \shortstack or \minitab can be replaced by \makecell, \thead etc.

% \usepackage{makecell}
\begin{tabular}{ccccc}
\toprule
&  Manual Tests & \thead{Randoop 2.5 Minutes\\ With GUI Code} &  \thead{Randoop 2.5 Minutes\\ Without GUI Code} &  \thead{Randoop 5 Minutes\\ Without GUI Code} \\ \midrule
\% Covered Instructions &  \textbf{82.40\%} &  21.25\% &  21.30\% &  \textbf{22.10\%} \\ \bottomrule
\end{tabular}

-
Thank you. That makecell package did the trick. – Tiago Veloso Feb 10 '11 at 18:07

You could break lines in wide cells. For this you could use p cells instead of l, such as p{2cm}.

I recommend

• Using the tabularx package to adjust the table to the text width

• Using features of the array package to insert commands into the column definition

• Getting better breaks in cells by ragged2e

• Loading microtype for finer automatic justification

• Using booktabs of course, you do it already as I can see.

It's a bit much to tell - just check out the package documentation.

Here's a quick example for your table:

\documentclass{scrreprt}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{microtype}
\newcolumntype{Y}{>{\RaggedRight}X}
\newcolumntype{P}[1]{>{\RaggedRight}p{#1}}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{P{2.5cm}lYYY}
\toprule
&  Manual Tests & Randoop 2.5 Minutes With GUI Code &  Randoop 2.5 Minutes Without GUI Code &  Randoop 5 Minutes Without GUI Code \\ \midrule
\% Covered Instructions &  \textbf{82.40\%} &  21.25\% &  21.30\% &  \textbf{22.10\%} \\ \bottomrule
\end{tabularx}
\end{document}


-
In this example, how would you vertically align the Manual Tests Cell? – Tiago Veloso Feb 19 '11 at 19:38
@Tiago: Take a look at tex.stackexchange.com/questions/7208/… – doncherry Aug 31 '11 at 15:34