0

I have two tables with different number of columns, and they are too wide to fit in. So I used \resizebox to fit them within linewidth, but the fonts in these two tables are also scaled. Is there a way to keep font size the same in two tables and fit them within the linewidth.

\begin{table*}[!t]
\centering
\resizebox{\linewidth}{!}{
\begin{tabular}{@{}ccccccccccccccccccccc@{}}
\toprule
Hello & World & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 & 0.08 & 0.09 & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 &  \\
\bottomrule
\end{tabular}
}
\end{table*}

\begin{table*}[t!]
\centering
\resizebox{\linewidth}{!}{
\begin{tabular}{@{}cccccccccccccccccccccccc@{}}
\toprule
Hello & World & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 & 0.08 & 0.09 & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 & 0.08 & 0.09 & 0.10 \\
\bottomrule
\end{tabular}
}
\end{table*}

enter image description here

Stefan Pinnow
  • 29,535
  • Welcome to TeX.SE! I am not sure how to interpret your question. On the one hand, you want to squeeze the table, and on the other hand, you want to keep the font size. How is that supposed to work? (See here for your options.) –  Mar 10 '18 at 05:46
  • also why [!t] on the table? that makes it rather more likely to float to the end of the document. – David Carlisle Mar 10 '18 at 08:36
  • also when posting examples please always post complete documents so people don't need to guess needed packages (eg \toprule is not defined by default) – David Carlisle Mar 10 '18 at 08:39

2 Answers2

2

You give a good example of why you should never scale tables. If you need a smaller size, use a declared font size such as \small so that you get consistent spacing, however it is usually better to format your table so it fits. I realize that your example was just made up data so this reformatting might not be suitable, but usually with some domain knowledge of the data being shown you can format a table to fit in some way.

enter image description here

\documentclass[a4paper]{article}

\usepackage{booktabs}
\begin{document}

\begin{table*}
\centering
\setlength\tabcolsep{4pt}

\begin{tabular}{@{}*{19}{r}@{}}
\toprule
\multicolumn{2}{@{}c}{Something}&\multicolumn{17}{c@{}}{Things ${}\times10^2$}\\
\midrule
Hello & World & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 1 & 2 & 3 & 4 & 5 & 6 & 7 &  \\
\bottomrule
\end{tabular}

\end{table*}

\begin{table*}
\centering
\setlength\tabcolsep{4pt}

\begin{tabular}{@{}*{21}{r}@{}}
\toprule
\multicolumn{2}{@{}c}{Something}&\multicolumn{19}{c@{}}{Things ${}\times10^2$}\\
\midrule
Hello & World & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
\bottomrule
\end{tabular}

\end{table*}

Zzzz

\end{document}
David Carlisle
  • 757,742
  • @CarLaTeX as written I think it's correct: the table shows the number of things multiplied by 100, you could also (and probably would with real units) describe it as "things in units of thing x10^{-2)" It's like pizza toppings, all choices are good – David Carlisle Mar 10 '18 at 10:33
  • Ah, now I understand. Of course, I don't agree about the pizza toppings :P – CarLaTeX Mar 10 '18 at 10:36
  • There is also \thelastscalefactor as explained by David in https://tex.stackexchange.com/questions/409575/knowing-how-much-resizebox-scales, which you can use to find out what factor corresponds to textwidth and then scale both tables to this factor. However this requires that the largest table is processed first (or else you need to do complicated things with .aux files etc.) – Marijn Mar 10 '18 at 21:26
  • @Marijn it's better to stick to a simple rule: never scale tables. – David Carlisle Mar 10 '18 at 21:30
  • @DavidCarlisle I use resizebox all the time, it is my favorite LaTeX macro :D – Marijn Mar 10 '18 at 21:55
  • @Marijn whenever I see it applied to tables, I regret having implemented it :( You don't (I hope) justify text in paragraphs by scaling the lines to fit so having inconsistent spacing and font size, why do that to text that happens to be in a table? – David Carlisle Mar 10 '18 at 22:23
  • @DavidCarlisle for me tables serve a different purpose than paragraphs, paragraphs are for reading, they should be consistent and the spacing and font should be optimized for readability, while tables are for lookup and should be optimized for information content - the more the better and on screen you can zoom if needed. – Marijn Mar 11 '18 at 09:13
  • @Marijn "zoom"?? so modern, you make it sound like you are not using paper:-) – David Carlisle Mar 11 '18 at 09:46
1

You could use \scalebox (but think of your long-sighted readers and try to change the layout of your tables).

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{graphicx}
\renewcommand*{\arraystretch}{1.3}
\usepackage{mwe}% for testing purpose only

\begin{document}
    \blindtext% for testing purpose only

\begin{table*}[!t]
    \centering
    \scalebox{.54}{
        \begin{tabular}{@{}ccccccccccccccccccccc@{}}
            \toprule
            Hello & World & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 & 0.08 & 0.09 & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 &  \\
            \bottomrule
        \end{tabular}
    }
\end{table*}

\begin{table*}[!t]
    \centering
    \scalebox{.54}{
        \begin{tabular}{@{}cccccccccccccccccccccccc@{}}
            \toprule
            Hello & World & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 & 0.08 & 0.09 & 0.01 & 0.02 & 0.03 & 0.04 & 0.05 & 0.06 & 0.07 & 0.08 & 0.09 & 0.10 \\
            \bottomrule
        \end{tabular}
    }
\end{table*}

\end{document}

enter image description here

CarLaTeX
  • 62,716