4

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.

8
  • 1
    A giraffe doesn't fit to a guinea pig cave. If you may enlarge the \textwidth, your (much too wide) table will fit. You can also re-create your table to be narrower. Sep 30, 2014 at 4:22
  • Add \usepackage[showframe]{geometry} to see if your table with the \resizebox is actually fitting in the margins.
    – jon
    Sep 30, 2014 at 4:22
  • @PrzemysławScherwentke: what do you mean by enlarge the \textwidth Sep 30, 2014 at 4:29
  • @jon: Can you please give me an example? Sep 30, 2014 at 4:29
  • 1
    We need to see a more realistic example with some representative data so that we know what goes in the columns. One fix (from the given table) would be to eliminate the word column from the column headings. Alternatively you could rotate the table so that you have larger width to work with. Sep 30, 2014 at 5:16

2 Answers 2

4

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

0
0

Yet another solution

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{array}
        \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}           
\usepackage{graphicx}
\newcommand{\nm}[1]{\textnormal{#1}}

\begin{document}

\begin{table} [h!]
\centering
\resizebox{\textwidth}{!} {%
\begin{tabular}{@{\hspace{1cm}}cc cc cc cc c}
\toprule

\multicolumn{3}{c}{N N}    &
\multicolumn{3}{c}{MM}    &
\multicolumn{3}{c}{DW}    \\ 
\cmidrule(lr){1-3}
\cmidrule(lr){4-6}
\cmidrule(lr){7-9}


\multicolumn{1}{C{1.5cm}}{column One} &
\multicolumn{1}{C{1.5cm}}{column two} &
\multicolumn{1}{C{1.5cm}}{column One+col2} &
\multicolumn{1}{C{1.5cm}}{column One} &
\multicolumn{1}{C{1.5cm}}{column Two} &
\multicolumn{1}{C{1.5cm}}{column One+col2} &
\multicolumn{1}{C{1.5cm}}{column One} &
\multicolumn{1}{C{1.5cm}}{column two} &
\multicolumn{1}{C{1.5cm}}{column One+col2}     \\
\midrule

\multicolumn{9}{l}{Experiment 1}\\ \cmidrule{1-2}
 a  & b & c & d \\
\multicolumn{9}{l}{Experiment 2} \\ \cmidrule{1-2}
  p & q & r & s \\ 

\midrule[\heavyrulewidth]
\bottomrule

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

\end{document}

You must log in to answer this question.

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