2

I have tables which are quite long because they have between 9 and 25 columns. They don't even fit on a page with a landscape layout. I tried to resize them using resizebox as suggested here but it always raises an error.

This in my LaTeX-file:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}[ht]
\resizebox{\linewidth}{!}{%
    \centering
    \settowidth\mywidth{\textbf{\MakeUppercase{TABLENAME}}}
    \begin{minipage}[t]{\mywidth}
            \mbox{}\par
            \textbf{\MakeUppercase{TABLENAME}}
        \end{minipage}
    %\[
    \begin{tabular}[t]{ccccccccc}
    \toprule
    \multicolumn{1}{c}{\textbf{column 1}} & \multicolumn{1}{c}{column 2}} & \multicolumn{1}{c}{column 3} & \multicolumn{1}{c}{column 4} & \multicolumn{1}{c}{column 5} & \multicolumn{1}{c}{column 6} & \multicolumn{1}{c}{column 7} & \multicolumn{1}{c}{\textbf{column 8}} & \multicolumn{1}{c}{\textbf{column 9}}\\
    \midrule
        value & value & value & value & value & value & value & value & value \\
    \bottomrule 
    \end{tabular}   
    %\]

    \caption{My Caption}
    \label{tbl:verylongtable}
}
\end{table}
\end{document}

And the exception I get is

pdflatex> ! You can't use '\hrule' here except with leaders

When I try to put the whole table environment inside the resizebox (and not only the code inside the table environment) I get the error:

pdflatex> ! Not in outer par mode

How can I scale my table anyway? I did not found a solution which works yet. And another side question: I read that in the line

\resizebox{\columnwidth}{!}{%

The % is important. Why? I only know a percentage sign as a beginning of a comment.

5
  • The reason for the minipage inside the table environment can be found here: tex.stackexchange.com/questions/274779/…
    – Drudge
    Commented Jan 27, 2016 at 14:53
  • Why writing \MakeUppercase{TABLENAME}? Seems redundant... Also, \multicolumn{1}{c}{} is not necessary in your case.
    – Alenanno
    Commented Jan 27, 2016 at 14:55
  • @Alenanno I wrote a little piece of code which generated me the table environments based on a given file. Not all tablenames are in uppercase there.
    – Drudge
    Commented Jan 27, 2016 at 14:57
  • 1
    as for your last line the % is introducing a comment in that position see tex.stackexchange.com/questions/7453/… Commented Jan 27, 2016 at 15:04
  • Note that scaling tables should be avoided see this comment from earlier today: tex.stackexchange.com/questions/289548/… Commented Jan 27, 2016 at 15:08

1 Answer 1

6

\resizebox is a horizontal mode command (like \mbox) so it can take the tabular but not vertical material like \centering.

Also please test your example before posting there were undefined commands and extra } unrelated to the question asked.

\documentclass{article}
\usepackage{graphicx}
\usepackage{booktabs}%grrr
\begin{document}
\newlength\mywidth%grrr
\begin{table}[ht]

    \centering
    \settowidth\mywidth{\textbf{\MakeUppercase{TABLENAME}}}
    \begin{minipage}[t]{\mywidth}
            \mbox{}\par
            \textbf{\MakeUppercase{TABLENAME}}
        \end{minipage}

    \resizebox{\linewidth}{!}{\begin{tabular}[t]{ccccccccc}
    \toprule
    \multicolumn{1}{c}{\textbf{column 1}} & \multicolumn{1}{c}{column 2}
%grr}
 & \multicolumn{1}{c}{column 3} & \multicolumn{1}{c}{column 4} & \multicolumn{1}{c}{column 5} & \multicolumn{1}{c}{column 6} & \multicolumn{1}{c}{column 7} & \multicolumn{1}{c}{\textbf{column 8}} & \multicolumn{1}{c}{\textbf{column 9}}\\
    \midrule
        value & value & value & value & value & value & value & value & value \\
    \bottomrule 
    \end{tabular}}  


    \caption{My Caption}
    \label{tbl:verylongtable}

\end{table}
\end{document}
0

You must log in to answer this question.

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