54

I have a table which its width exceed the textwidth of the document, but I want reduce its size to fit the textwidth space.

I have tried the resizebox command but it doesn't work at all.

\begin{table}[h!]
  \centering
  \resizebox{\textwidth}{!}{  
  \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
  \hline
  One & Two &Three & Four & Five & Six & Seven & Eight & Nine & Ten & Eleven &
  Twelve & Thirteen & Fourteen\\

  \hline
  \hline
  $1.111$ & $2.222$ & $3.333$ & $4.444$ & $5.555$ & $6.666$ & $7.777$ &
  $8.888$ & $9.999$ & $0.000$ & $1.111$ & $2.222$ & $3.333$ & $4.444$\\
  \hline  
\end{tabular}
}
  \caption{Test Table}
  \label{tab:label_test}
\end{table}

The table keeps the same width and exceed the border of the page. I want resize the table, scaling all the tabular object without touch the caption fontsize.

How can I do that?

If I copy the code of @HarishKumar: Width adjustbox command

4
  • I think I have a problem with my latex package, because even the solution provided by @HarishKumar doesn't work...
    – nunzio13n
    Mar 2, 2014 at 14:15
  • 4
    The problem is that you are always viewing the DVI output. You schould run pdflatex and then view the PDF output! DVI viewers cannot show scaling and rotations. Or convert your dvi to pdf if you need that way.
    – user2478
    Mar 2, 2014 at 14:22
  • You are right... thank you very much I was becoming crazy
    – nunzio13n
    Mar 2, 2014 at 14:25
  • Remark for any passer-by: scaling tables should be very low in the list of options. In the sense that one should never do it. Reducing the font size with \small or \footnotesize together with actions on \tabcolsep is most of the times sufficient to get by.
    – egreg
    Nov 6, 2023 at 10:10

5 Answers 5

80

\resizebox should work provided you put \usepackage{graphicx}. But here is a better option with adjustbox package. With this, you can resize only if the table goes beyond \textwidth, otherwise not.

\documentclass{article}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{showframe}   %% just for demo
\begin{document}
  \begin{table}[h!]
  \centering
  \begin{adjustbox}{max width=\textwidth}
  \begin{tabular}{*{14}{|c}|}%%{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
  \hline
  One & Two &Three & Four & Five & Six & Seven & Eight & Nine & Ten & Eleven &
  Twelve & Thirteen & Fourteen\\
  \hline
  \hline
  $1.111$ & $2.222$ & $3.333$ & $4.444$ & $5.555$ & $6.666$ & $7.777$ &
  $8.888$ & $9.999$ & $0.000$ & $1.111$ & $2.222$ & $3.333$ & $4.444$\\
  \hline
\end{tabular}
\end{adjustbox}
  \caption{Test Table}
  \label{tab:label_test}
\end{table}
\end{document}

enter image description here

8
  • Thanks but your solution doesn't work for me, look at my edited question
    – nunzio13n
    Mar 2, 2014 at 14:20
  • 1
    @nunzio13n It works. Some thing else is wrong.
    – user11232
    Mar 2, 2014 at 15:32
  • 1
    You may want to note that the \centering instruction isn't entirely redundant, as it will have an effect in case the natural width of the object contained in adustbox is less than \textwidth.
    – Mico
    Aug 15, 2015 at 8:30
  • This solution works as long as you don't use XeLaTeX and hyperlinks in the table. See similar post. May 6, 2017 at 8:14
  • 1
    This is amazing! Worked perfectly - thank you! Sep 3, 2021 at 6:52
16

you have two unwanted spaces. Use

\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}   %% just for demo
\begin{document}
  \begin{table}
  \resizebox{\textwidth}{!}{%
  \begin{tabular}{*{14}{|c}|}%%{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline
  One & Two &Three & Four & Five & Six & Seven & Eight & Nine & Ten & Eleven &
  Twelve & Thirteen & Fourteen\\\hline\hline
  $1.111$ & $2.222$ & $3.333$ & $4.444$ & $5.555$ & $6.666$ & $7.777$ &
  $8.888$ & $9.999$ & $0.000$ & $1.111$ & $2.222$ & $3.333$ & $4.444$\\\hline
\end{tabular}%
}
  \caption{Test Table}\label{tab:label_test}
\end{table}
\end{document}

enter image description here

2
  • Thank you for your answer but even without the spaces, width the comment character %, the table keeps to exceed the border of the page
    – nunzio13n
    Mar 2, 2014 at 14:05
  • That's not possible with your code! You must do something special. See my edited answer.
    – user2478
    Mar 2, 2014 at 14:09
3

just put the scale in before \textwidth e.g. width=0.9\textwidth.

3
  • Welcome, can you extend your answer a little bit Right now, it is quite short and seems to be more suited as a comment.
    – Johannes_B
    Aug 15, 2015 at 8:17
  • This answer is insufficient, as it needs to be mentioned where to put this command and the effect. if set in wrong place, it just shrinks the table without shrinking the content.
    – PWillms
    Feb 8, 2021 at 2:36
  • thanks this works
    – Lyrk
    Jan 24, 2022 at 17:27
1

Try playing with max width with 0.9 or 0.7. It shrinks the table further.

For e.g., \begin{adjustbox}{max width=0.77\textwidth}

-1
\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}   %% just for demo
\begin{document}
    \tiny
    \begin{table}[h]
         \resizebox{\textwidth}{!}{ %   
            \begin{tabular}{*{14}{|l|{0.6cm}}}%%{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}\hline
                One & Two &Three & Four & Five & Six & Seven & Eight & Nine & Ten & Eleven &
                Twelve & Thirteen & Fourteen\\\hline\hline
                1.111 & 2.222 & 3.333 & 4.444 & 5.555 & 6.666 & 7.777 &
                8.888 & 9.999 & 0.000 & 1.111 & 2.222 & 3.333 & 4.444\\\hline
            \end{tabular}
    %   }       
        \caption{Test Table}\label{tab:label_test}
    \end{table}
\end{document}

enter image description here.

I have removed all $ signs. They are not needed. I have set all columns to 0.6 cm. I have put \begin{table}[h] so that table begins at this height.

1
  • 1
    Your MWE contain error. Please correct it.
    – Zarko
    Sep 21, 2021 at 11:17

You must log in to answer this question.

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