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

  • 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.) – user121799 Mar 10 '18 at 5: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 8: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 8:39
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}
  • @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 tex.stackexchange.com/questions/409575/…, 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
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.