2

My table exceeds the text width... I have already tried lots of stuff (ex: tabularx, tabulary and others that I can't remember right now) to try to correct but none of them has solved my problem.

I have a situation like this one:

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{tabularx}

\title{Your Paper}
\author{You}

\begin{document}
\maketitle
\begin{abstract}
Your abstract.
\end{abstract}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ultrices ipsum nec ultricies placerat. Quisque iaculis bibendum nunc, a ultricies magna pellentesque ut. Vivamus iaculis lacinia diam, sed porttitor metus ornare id. Nunc posuere magna at eleifend malesuada. Vestibulum non diam in lacus rutrum condimentum. Nullam fermentum facilisis turpis et tristique. Donec tempor purus nulla, vel ullamcorper augue sagittis sit amet. Integer blandit finibus ex, eget placerat neque mollis non. Mauris ut tempor lectus. Nullam id dolor vel lectus aliquet porta.

\section{Introduction}
Donec euismod feugiat lacus, quis convallis libero lacinia vitae. Morbi in efficitur ante, nec placerat orci. Curabitur nec rutrum neque. Integer mollis purus in dolor vulputate convallis egestas vel erat. Cras condimentum nunc eu urna sagittis pulvinar. In hac habitasse platea dictumst. Integer quam ligula, semper sit amet libero vitae, ornare maximus nibh. Quisque vitae interdum purus, in euismod arcu. Aenean at sollicitudin arcu, ac commodo lacus.

\begin{table}[h]
\centering
\begin{tabular}{ccccccccccc}
\hline
\multicolumn{1}{|c|}{PH} & \multicolumn{2}{c|}{10 } & \multicolumn{2}{c|}{20 }  & \multicolumn{2}{c|}{30 }  & \multicolumn{2}{c|}{45 }  & \multicolumn{2}{c|}{60 }  \\ \hline 
\multicolumn{1}{|c|}{W}  & \multicolumn{1}{c|}{RMSE} & \multicolumn{1}{c|}{Adj. $r^2$} & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{Adj. $r^2$} & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{Adj. $r^2$} & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{Adj. $r^2$} & \multicolumn{1}{c|}{RMSE}  & \multicolumn{1}{c|}{Adj. $r^2$} \\ \hline
\multicolumn{1}{|c|}{4} & \multicolumn{1}{c|}{7.77} & \multicolumn{1}{c|}{0.92} & \multicolumn{1}{c|}{14.23}    & \multicolumn{1}{c|}{0.72} & \multicolumn{1}{c|}{19.23}    & \multicolumn{1}{c|}{0.48} & \multicolumn{1}{c|}{24.10}    & \multicolumn{1}{c|}{0.18} & \multicolumn{1}{c|}{26.61}    & \multicolumn{1}{c|}{0.01} \\ \hline
\multicolumn{1}{|c|}{7} & \multicolumn{1}{c|}{7.79} & \multicolumn{1}{c|}{0.91} & \multicolumn{1}{c|}{14.26}    & \multicolumn{1}{c|}{0.71} & \multicolumn{1}{c|}{19.22}    & \multicolumn{1}{c|}{0.47} & \multicolumn{1}{c|}{23.99}    & \multicolumn{1}{c|}{0.18} & \multicolumn{1}{c|}{26.35}    & \multicolumn{1}{c|}{0.02} \\ \hline
\end{tabular}
\caption{My caption}
\label{my-label}
\end{table}


\end{document}

How can I fix this? I would like to shrink it to fit to the margins of the text. Although, if if it becomes too small I would like to have an opinion and an example of how could I display the same information but in other way. An important aspect is that I'll have 33 tables with the same problem. Each table has 18 rows in total instead of the two presented here (it was just an example).

PS: This is not the document class that I'm working with. It was just an example to don't put here tons of code. In my document I have more space but the problem is the same.

4
  • What do you want to fix? Make everything smaller? rotate the table? re-think how you want to present the information?
    – jon
    Jun 27, 2015 at 1:46
  • What have you tried? "Lots of stuff" doesn't help. Do you want it to remain as-is but fit within the text block width? Or do you want to shrink it down to fit? Or do you want to resize it to fit?
    – Werner
    Jun 27, 2015 at 1:47
  • @jon and Werner I already edited the post to answer your questions.
    – user25847
    Jun 27, 2015 at 6:47
  • 1
    In addition to all the other answers concerning Adj. $R^2$: You might consider to write it as following: $R^2_\mathit{Adj.}$. That also saves you some space.
    – phx
    Jun 28, 2015 at 8:49

3 Answers 3

5

booktabs can improve the appearance of the tabular significantly. rotating allows you to present it as a sidewaystable:

\documentclass[a4paper]{article}
\usepackage{booktabs,rotating}

\begin{document}
  \begin{sidewaystable}
    \centering
    \begin{tabular}{*{11}{c}}
      \toprule
      PH & \multicolumn{2}{c}{10 } & \multicolumn{2}{c}{20}  & \multicolumn{2}{c}{30}  & \multicolumn{2}{c}{45}  & \multicolumn{2}{c}{60}  \\
      W  & RMSE & Adj. $r^2$ & RMSE  & Adj. $r^2$ & RMSE  & Adj. $r^2$ & RMSE  & Adj. $r^2$ & RMSE  & Adj. $r^2$ \\\midrule
      4 & 7.77 & 0.92 & 14.23    & 0.72 & 19.23    & 0.48 & 24.10    & 0.18 & 26.61    & 0.01 \\
      7 & 7.79 & 0.91 & 14.26    & 0.71 & 19.22    & 0.47 & 23.99    & 0.18 & 26.35    & 0.02 \\ \bottomrule
    \end{tabular}
    \caption{My caption}
    \label{my-label}
  \end{sidewaystable}
\end{document}

rotated tabular

If you really don't want to rotate it, your only option is to make it smaller. That either means rethinking how you present the data or squishing it. Only you can really do the former, so here's an example of the latter. But remember that your readers will not thank you for this kind of thing!

\documentclass[a4paper]{article}
\usepackage{booktabs}

\begin{document}
  \begin{table}
    \centering\small\setlength\tabcolsep{.225em}
    \begin{tabular}{*{11}{c}}
      \toprule
      PH & \multicolumn{2}{c}{10 } & \multicolumn{2}{c}{20}  & \multicolumn{2}{c}{30}  & \multicolumn{2}{c}{45}  & \multicolumn{2}{c}{60}  \\
      W  & RMSE & Adj. $r^2$ & RMSE  & Adj. $r^2$ & RMSE  & Adj. $r^2$ & RMSE  & Adj. $r^2$ & RMSE  & Adj. $r^2$ \\\midrule
      4 & 7.77 & 0.92 & 14.23    & 0.72 & 19.23    & 0.48 & 24.10    & 0.18 & 26.61    & 0.01 \\
      7 & 7.79 & 0.91 & 14.26    & 0.71 & 19.22    & 0.47 & 23.99    & 0.18 & 26.35    & 0.02 \\ \bottomrule
    \end{tabular}
    \caption{My caption}
    \label{my-label}
  \end{table}
\end{document}

squished

4
  • 1
    I think, Adj. is an abbreviation, then the space afterwards is too large. This can be fixed by Adj.\@ $r^2$ or Adj.~$r^2$. Also cheating like Adj.\,$r^2 might be an option to get the table smaller in width. Jun 27, 2015 at 3:39
  • cfr, could you help me on this one?
    – user25847
    Jun 28, 2015 at 16:20
  • @user25847 You seem to have a nice answer there from Bernard, now. Are you happy with that one?
    – cfr
    Jun 28, 2015 at 17:48
  • There is an error with the code that prevents me of testing Bernard's suggestion so I do not know if it works on my doc.
    – user25847
    Jun 28, 2015 at 18:13
4

Also an option, a different layout of the table columns and rows, e.g.:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{tabular}{
    S[table-format=2.0]
    S[table-format=1.0]
    S[table-format=2.2]
    S[table-format=1.2]
  }
    \toprule
    {PH} & {W} & {RMSE} & {Adj.\@ $r^2$} \\
    \midrule
    10 & 4 &  7.77 & 0.92 \\
       & 7 &  7.79 & 0.91 \\
    \addlinespace
    20 & 4 & 14.23 & 0.72 \\
       & 7 & 14.26 & 0.71 \\
    \addlinespace
    45 & 4 & 24.10 & 0.18 \\
       & 7 & 23.99 & 0.18 \\
    \addlinespace
    60 & 4 & 26.61 & 0.01 \\
       & 7 & 26.35 & 0.02 \\
    \bottomrule
  \end{tabular}
\end{document}

Result

1
  • 2
    I like this answer most since it emphasizes the option to change the layout of tables instead of just trying to fiddle with font sizes, abbreviations etc. In stats we would call it the "long" vs. the "wide" format.
    – phx
    Jun 28, 2015 at 8:54
1

If you're willing to write $\bar{R}^2$ instead of Adj. $r^2$ -- the former notation is much more common in my field, viz., econometrics -- you can shorten the header material sufficiently so that the table will fit in "ordinary", i.e., portrait mode. Like the other two persons giving answers up to now, I also recommend using the rule-drawing macros of the booktabs package.

enter image description here

\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\title{Your Paper}
\author{You}

\begin{document}

\section{Introduction}

\begin{table}[h]
\begin{tabularx}{\textwidth}{ @{} l *{10}{C} @{} }
\toprule
PH & \multicolumn{2}{c}{10 } 
   & \multicolumn{2}{c}{20 }  
   & \multicolumn{2}{c}{30 }  
   & \multicolumn{2}{c}{45 }  
   & \multicolumn{2}{c}{60 }  \\ 
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9} \cmidrule(l){10-11}  
W  & \textsc{rmse} & $\bar{R}^2$ & 
     \textsc{rmse} & $\bar{R}^2$ & 
     \textsc{rmse} & $\bar{R}^2$ & 
     \textsc{rmse} & $\bar{R}^2$ & 
     \textsc{rmse} & $\bar{R}^2$ \\ 
\midrule
4 & 7.77 & 0.92 & 14.23  & 0.72 & 19.23 & 0.48 & 24.10 & 0.18 & 26.61 & 0.01\\ 
7 & 7.79 & 0.91 & 14.26 & 0.71 & 19.22 & 0.47 & 23.99 & 0.18 & 26.35 & 0.02 \\ 
\bottomrule
\end{tabularx}
\caption{My caption}
\label{my-label}
\end{table}

\end{document}
1
  • Thanks for the suggestion ... I adopted another notation $R_{adj}^2$ :) Could you help me on this one?
    – user25847
    Jun 28, 2015 at 16:21

You must log in to answer this question.

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