[Tex/LaTex] Fit a table to page width

booktabstables

I am new to Latex and making tables using booktab.

I made a table with hierarchy in the x-axis such that I have 3 columns and each column further has 3 sub-columns.
But, the table fails to fit within the width of the page as shown below

enter image description here

I tried many solutions such as tabu, adjustbox, resize box and tabular*, but they do not seem to fix the problem or I do not know the proper syntax.

The code that I used is attached below with resize box.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{array}
\usepackage{graphicx}

\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}} 
\newcolumntype{R}{>{$}r<{$}}
\newcommand{\nm}[1]{\textnormal{#1}}

\begin{document}

\begin{table} [h!]
\centering
\resizebox{\textwidth}{!} {%
\begin{tabular}{LCCCCCCCCC}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{3}{c}{N N}    &
\multicolumn{3}{c}{MM}    &
\multicolumn{3}{c}{DW}    \\ 
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}

&
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column Two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2}     \\
\midrule

experiment1 & a  & b & c & d \\
experiment2 & p & q & r & s \\ 

\midrule[\heavyrulewidth]
\bottomrule

\end{tabular}%
}
\caption{Description of the table}\label{beta}
\end{table}

\end{document}

After using the resize I get the following

enter image description here

Can anyone help me this?
Thank You so much in advance.

Best Answer

An example of the solution without using more advanced methods, as rotating. It summarizes my suggestions from comments. Heavy line shows the width of text and separates from an original (not scaled) example. There are some changes in text, but probably without loss of understanding it.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{array}
\usepackage{graphicx}

\oddsidemargin-1cm
\textwidth17cm
\def\COMP#1{\begin{tabular}{c}#1\end{tabular}}

\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}} 
\newcolumntype{R}{>{$}r<{$}}
\newcommand{\nm}[1]{\textnormal{#1}}

\begin{document}

\begin{table} [h!]
\centering
%\resizebox{\textwidth}{!} {%
\begin{tabular}{LCCCCCCCCC}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{3}{c}{N N}    &
\multicolumn{3}{c}{MM}    &
\multicolumn{3}{c}{DW}    \\ 
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}

&
\multicolumn{1}{c}{\COMP{col.\\ One}} &
\multicolumn{1}{c}{\COMP{col.\\ two} }&
\multicolumn{1}{c}{\COMP{col.\\ One\\+col2}} &
\multicolumn{1}{c}{\COMP{col.\\ One}} &
\multicolumn{1}{c}{\COMP{col.\\ Two}} &
\multicolumn{1}{c}{\COMP{col.\\ One\\+col2}} &
\multicolumn{1}{c}{\COMP{col.\\ One}} &
\multicolumn{1}{c}{\COMP{col.\\ two}} &
\multicolumn{1}{c}{\COMP{col.\\ One\\+col2}}     \\
\midrule

ex1 & a  & b & c & d \\
ex2 & p & q & r & s \\ 

\midrule[\heavyrulewidth]
\bottomrule

\end{tabular}%
%}
\caption{Description of the table}\label{beta}
\end{table}

\noindent\rule{\textwidth}{1mm}

\begin{table} [h!]
\centering
%\resizebox{\textwidth}{!} {%
\begin{tabular}{LCCCCCCCCC}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{3}{c}{N N}    &
\multicolumn{3}{c}{MM}    &
\multicolumn{3}{c}{DW}    \\ 
\cmidrule(lr){2-4}
\cmidrule(lr){5-7}
\cmidrule(lr){8-10}

&
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column Two} &
\multicolumn{1}{c}{column One+col2} &
\multicolumn{1}{c}{column One} &
\multicolumn{1}{c}{column two} &
\multicolumn{1}{c}{column One+col2}     \\
\midrule

experiment1 & a  & b & c & d \\
experiment2 & p & q & r & s \\ 

\midrule[\heavyrulewidth]
\bottomrule

\end{tabular}%
%}
\caption{Description of the table}\label{beta}
\end{table}


\end{document}

enter image description here