[Tex/LaTex] Table exceeds text width

tableswidth

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.

Best Answer

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