1

I am fairly new to LaTeX and I have a quite basic question. I create tables like this:

\begin{table}[H]
    \resizebox{\textwidth}{!}{%
        \begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-2} D{.}{.}{-2} D{.}{.}{-2} }
            Test & 1 & 2 & 3
\end{tabular}}
\end{table} 

However, I have a lot of tables and their number of columns differs. Accordingly, the font size changes automatically to my marginal settings (\resizebox{\textwidth}), i.e. the more columns the table has the smaller the font size. Is there a way to align the font size of all tables at once?

I know that I can decrease the font size manually by increasing the number within \extracolsep{5pt} to e.g.

\extracolsep{10pt}

However, I don't want to do this for every table and compare the results until they roughly coincide.

Thanks!

3
  • 1
    Without a complete example it is difficult to see but my first suggestion would be to get rid of the \resizebox. That should be used only as a last resort for desperate cases. Why should all tables have the same width? A table with ten columns will be likely broader than one with three; so?
    – campa
    Commented Jan 14, 2021 at 14:11
  • These inconsistent font sizes you observed are exactly the reason why you should not scale tables. If you want to make a table as wide as the textwidth, there are better options such as tabularx or tabular*. Which one to use depends on the table and its contents. There most likely is no solution that is applicable to all your tables.
    – leandriis
    Commented Jan 14, 2021 at 15:20
  • never scale tables! Commented Jan 14, 2021 at 20:42

1 Answer 1

1

Never scale tables, as you see, scaling just produces inconsistent font sizes.

Simply use

\begin{table}[htbp]
     \small
        \begin{tabular}{lD{.}{.}{-2} D{.}{.}{-2} D{.}{.}{-2} }
            Test & 1 & 2 & 3
\end{tabular}
\end{table}

or if \small is still too large \footnotsize.

Note that \extracolsep does nothing in tabular (it is used to give stretch space for tabular* to achieve the target width of the table). I also removed [H] which should be used very sparingly as it disables the float positioning algorithm (and specifying that the table may float is the sole purpose of the table environment).

You must log in to answer this question.

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