95

I have the following latex table:

\begin{table}[ht]
\centering
\begin{tabular}{rlrrrrrrr}
  \hline
 & X & MASHvstRap & MASHvsBEEML & tRapvsBEEML & frequency & Mash\_mean & BEEML\_mean & tRap\_mean \\ 
  \hline
1 & ETS & 8.95e-04 & 7.35e-04 & 4.78e-06 &  10 & 0.52 & 0.67 & 0.30 \\ 
  11 & ZnF\_C2H2 & 7.08e-21 & 2.09e-02 & 1.70e-26 &  54 & 0.55 & 0.64 & 0.25 \\ 
  10 & Zn2Cys6 & 4.94e-04 & 5.50e-02 & 3.52e-06 &  17 & 0.38 & 0.61 & 0.13 \\ 
  8 & IRF & 1.16e-06 & 6.65e-02 & 5.54e-08 &  10 & 0.52 & 0.62 & 0.28 \\ 
  2 & FH & 1.27e-05 & 8.61e-02 & 5.20e-07 &  10 & 0.53 & 0.66 & 0.27 \\ 
  3 & HLH & 2.49e-05 & 1.31e+00 & 4.27e-05 &  13 & 0.61 & 0.74 & 0.26 \\ 
  4 & HMG & 8.73e-33 & 1.41e+00 & 3.49e-08 &  44 & 0.55 & 0.48 & 0.12 \\ 
  12 & ZnF\_C4 & 2.92e-06 & 1.92e+00 & 1.03e-07 &  10 & 0.66 & 0.73 & 0.27 \\ 
  9 & unknown & 3.15e-27 & 1.96e+00 & 5.38e-21 & 121 & 0.44 & 0.49 & 0.16 \\ 
  5 & Homeo & 1.69e-164 & 6.26e+00 & 2.35e-75 & 158 & 0.72 & 0.73 & 0.17 \\ 
  7 & Homeo, POU & 3.12e-12 & 7.36e+00 & 5.21e-12 &  11 & 0.69 & 0.70 & 0.18 \\ 
  6 & Homeo  & 9.82e-13 & 9.73e+00 & 1.21e-05 &  19 & 0.67 & 0.65 & 0.14 \\ 
   \hline
\end{tabular}
\caption{Paired t-test of most common TF families for Pearson Correlations} 
\end{table} 

But unfortunately the table doesn't fit to normal a4 paper size, and therefore needs to be adjusted. I read a lot of questions of other Ops but cannot find out how to do this for my table.

I thought of using tabu{} or adjustbox{} but still did'nt manage to proper adjust my table.

6
  • 2
    Please see tex.stackexchange.com/q/97505/2975 which I think should answer your question. Commented Jun 26, 2013 at 11:46
  • 2
    And: Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. It's especially helpful if you post complete minimal working examples (MWEs), so we can see your basic document structure (class, packages etc.) as well. Commented Jun 26, 2013 at 11:51
  • 1
    @MartinScharrer I read the startes guide and code above is actually only code i have. rest is just standard. But with youre given example for my answer i did not manage to get a nice table. Commented Jun 26, 2013 at 12:12
  • 1
    @Martin Scharrer Is there a simple fix for this, because i know am 5 hours further and tried everything only thing i get is errors errors and errors. And if it works it doesnt scale but adds some strange height and width next to my half table. Commented Jun 26, 2013 at 13:27
  • 1
    We are interested in this other "standard" stuff, too.
    – mafp
    Commented Jun 26, 2013 at 14:57

2 Answers 2

135

If you're willing to just scale the entire table down, then this is fairly straight-forward, put it in a box and scale the box to \textwidth.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
test

\begin{table}[ht]
\centering
\resizebox{\textwidth}{!}{\begin{tabular}{rlrrrrrrr}
  \hline
 & X & MASHvstRap & MASHvsBEEML & tRapvsBEEML & frequency & Mash\_mean & BEEML\_mean & tRap\_mean \\ 
  \hline
1 & ETS & 8.95e-04 & 7.35e-04 & 4.78e-06 &  10 & 0.52 & 0.67 & 0.30 \\ 
  11 & ZnF\_C2H2 & 7.08e-21 & 2.09e-02 & 1.70e-26 &  54 & 0.55 & 0.64 & 0.25 \\ 
  10 & Zn2Cys6 & 4.94e-04 & 5.50e-02 & 3.52e-06 &  17 & 0.38 & 0.61 & 0.13 \\ 
  8 & IRF & 1.16e-06 & 6.65e-02 & 5.54e-08 &  10 & 0.52 & 0.62 & 0.28 \\ 
  2 & FH & 1.27e-05 & 8.61e-02 & 5.20e-07 &  10 & 0.53 & 0.66 & 0.27 \\ 
  3 & HLH & 2.49e-05 & 1.31e+00 & 4.27e-05 &  13 & 0.61 & 0.74 & 0.26 \\ 
  4 & HMG & 8.73e-33 & 1.41e+00 & 3.49e-08 &  44 & 0.55 & 0.48 & 0.12 \\ 
  12 & ZnF\_C4 & 2.92e-06 & 1.92e+00 & 1.03e-07 &  10 & 0.66 & 0.73 & 0.27 \\ 
  9 & unknown & 3.15e-27 & 1.96e+00 & 5.38e-21 & 121 & 0.44 & 0.49 & 0.16 \\ 
  5 & Homeo & 1.69e-164 & 6.26e+00 & 2.35e-75 & 158 & 0.72 & 0.73 & 0.17 \\ 
  7 & Homeo, POU & 3.12e-12 & 7.36e+00 & 5.21e-12 &  11 & 0.69 & 0.70 & 0.18 \\ 
  6 & Homeo  & 9.82e-13 & 9.73e+00 & 1.21e-05 &  19 & 0.67 & 0.65 & 0.14 \\ 
   \hline
\end{tabular}}
\caption{Paired t-test of most common TF families for Pearson Correlations} 
\end{table} 

\end{document}
3
  • 13
    Note that \resizebox reads the whole table as marco argument which doesn't work with verbatim and some special TikZ matrix code. It's also not very efficient. An alternative would be to use the adjustbox package and replace the \resizebox with \begin{adjustbox}{width=\textwidth} .. \end{adjustbox}. Alternatively the width key can be replaced by max width, so that the table is only scaled down if needed. However, this is actually the accepted answer of the very similar question I linked in my comment above. Commented Jun 26, 2013 at 16:11
  • \resizeboxwill scale the contents of the third curly braces. By having a \tabularwith lots of columns if l, c and r will produce unpredictable results. If you want to have a table of defined with and having its columns automatically adapted to that overall width, better use the tabularx-package and its X-column (capital X here!).
    – Jan
    Commented Jan 8, 2017 at 8:23
  • Give me your address to go there and give him a hug. :-)
    – Pereira
    Commented May 1, 2021 at 23:40
60

As already mentioned in https://tex.stackexchange.com/a/97506/2975 you can use \resizebox or better adjustbox to scale the table to a specific width, e.g. \textwidth which is the width of the text on the page. This however might make your table text very small and hard to read.

\documentclass{article}
\usepackage{adjustbox}

\usepackage{lipsum}% example text

\begin{document}

\lipsum

\begin{table}[ht]
\centering
\begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{rlrrrrrrr}
  \hline
 & X & MASHvstRap & MASHvsBEEML & tRapvsBEEML & frequency & Mash\_mean & BEEML\_mean & tRap\_mean \\ 
  \hline
1 & ETS & 8.95e-04 & 7.35e-04 & 4.78e-06 &  10 & 0.52 & 0.67 & 0.30 \\ 
  11 & ZnF\_C2H2 & 7.08e-21 & 2.09e-02 & 1.70e-26 &  54 & 0.55 & 0.64 & 0.25 \\ 
  10 & Zn2Cys6 & 4.94e-04 & 5.50e-02 & 3.52e-06 &  17 & 0.38 & 0.61 & 0.13 \\ 
  8 & IRF & 1.16e-06 & 6.65e-02 & 5.54e-08 &  10 & 0.52 & 0.62 & 0.28 \\ 
  2 & FH & 1.27e-05 & 8.61e-02 & 5.20e-07 &  10 & 0.53 & 0.66 & 0.27 \\ 
  3 & HLH & 2.49e-05 & 1.31e+00 & 4.27e-05 &  13 & 0.61 & 0.74 & 0.26 \\ 
  4 & HMG & 8.73e-33 & 1.41e+00 & 3.49e-08 &  44 & 0.55 & 0.48 & 0.12 \\ 
  12 & ZnF\_C4 & 2.92e-06 & 1.92e+00 & 1.03e-07 &  10 & 0.66 & 0.73 & 0.27 \\ 
  9 & unknown & 3.15e-27 & 1.96e+00 & 5.38e-21 & 121 & 0.44 & 0.49 & 0.16 \\ 
  5 & Homeo & 1.69e-164 & 6.26e+00 & 2.35e-75 & 158 & 0.72 & 0.73 & 0.17 \\ 
  7 & Homeo, POU & 3.12e-12 & 7.36e+00 & 5.21e-12 &  11 & 0.69 & 0.70 & 0.18 \\ 
  6 & Homeo  & 9.82e-13 & 9.73e+00 & 1.21e-05 &  19 & 0.67 & 0.65 & 0.14 \\ 
   \hline
\end{tabular}
\end{adjustbox}
\caption{Paired t-test of most common TF families for Pearson Correlations} 
\end{table} 

\lipsum

\end{document}

result


One way to increase your table is to make it actually wider than the text but still keep it centered as explained for figures in https://tex.stackexchange.com/a/16584/2975. This can be easily done by using \begin{adjustbox}{width=1.2\textwidth,center=\textwidth} .. \end{adjustbox} instead of the keys used above. This values will make the table 120% of the text width but keep it centered to the text.

result 2


If this is still not suitable for you, you could rotate the tabular and \caption using the angle=90 key of adjustbox. Also sometimes it is advisable to break complicated tables into several smaller ones, which is of course not always possible.

3
  • Is it better to use this than, say, tabulary package? Commented Jun 26, 2013 at 16:37
  • @MarioS.E.: This depends really on the table content. AFAIK tabularx or tabulary only helps if you have longer text in at least one cell which then can be broken to fit into the rest of the line width. In this example it's not really useful because their are only numbers and single words. Ok, the headlines could be shorten or set smaller, but I wouldn't do this with tabulary but manually using two rows or something like \stackbox. Commented Jun 26, 2013 at 16:46
  • @MartinScharrer I dont want to bother you all the time, but the package is installed, and only cant be loaded. Still thanks for the lead to other article but wont help me because adjustbox is already installed Commented Jun 27, 2013 at 11:43

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