3

I am using overleaf. I have a wide table. I use \resizebox to keep it in line width. However, the font become very small. How can I enlarge the font and the height of each row, So that the width and height are both appropriately adjusted.

\begin{table}[t]
%\LARGE
\caption{names}
\label{tab: table 1}
\resizebox{\textwidth}{!}{
\begin{tabular}{cccccccc}

\toprule Modularity Class & 0 & 1 & 2 & 3 & 4 & 5 & 6 \ \midrule \hline 1 & CANADA & COVID & SOCIALDISTANCING & PANDEMIC & TRUMP & UK & COVID19 \ \hline 2 & AUSPOL & CHINA & QUARANTINE & NEWS & USA & COVID19UK & CORONAVIRUS \ \hline 3 & CDNPOLI & VACCINE & MASKS & HEALTHCARE & WEARAMASK & LONDON & COVID_19 \ \hline 4 & COVID19AUS & HEALTH & MASK & ECONOMY & COVIDIOTS & CORONAVIRUSUK & LOCKDOWN
\end{tabular} } \end{table}

David Carlisle
  • 757,742
  • 1
    Don't use resizebox to make a table fit into the textwidth. There are better possibilities that result in consistent font sizes throughout the document. – leandriis Jul 07 '21 at 06:29
  • 2
    https://tex.stackexchange.com/q/332902/134144 contains an overview over some of these approaches. Probably you can find one that is applicable to your table, there. – leandriis Jul 07 '21 at 06:31
  • It seems that you want to deform the font (different scaling in vertical and horizontal direction). This is typographically completely inappropriate. – wipet Jul 07 '21 at 06:41
  • 1
    never use resizebox on tables, it destroys any hope of reasonable font choice, as you see, but if you do use it avoid adding a space token at the start and end, the form you have above is like \fbox{ x } not like \fbox{x} – David Carlisle Jul 07 '21 at 06:42
  • @DavidCarlisle - In case you're curious: I chose to re-open the table to point out that using a "condensed" font face would a good idea for the table at hand. – Mico Jul 07 '21 at 07:01
  • 1
    @Mico Ok (gold badge auto closing can be a pain sometimes:-) Arguably of course the suggestion to use a condensed font would be an option for any wide table so could/should be an answer at the canonical table too wide question, but I agree answering here is easier and not unreasonable – David Carlisle Jul 07 '21 at 07:04

2 Answers2

2

There are not good formatting approaches to better fit a table with a largely bad design for the available space. The general solution for these cases only could be (a) obtain munch more space for the table (e.g., a landscape page) or (b) redesign the table.

And only then, if needed, think in any other codding approaches to adjust cell sizes, as horizontal padding, reduce font size (without \resizebox, of course), etc. that only will work starting with a reasonable design.

The option (a) not only have the disadvantage of neck exercises, in this case also the table is too short for a landscape page, so if the remaining space of the page cannot be filled with another table or so, the page layout will be awful. Therefore, I will go preferably with the option (b).

The most obvious transformation is transposing rows and columns. As this will be not enough, I also reduce the font to \scriptsize that is usually is too much, but for uppercase characters is still acceptable. I also will use tabulary instead o tabularx to have unequal column sizes, that could less inconvenient that hyphenate some kid of variables names:


mwe


\documentclass{article}
\usepackage{booktabs,tabulary,lipsum}
\begin{document}
\begin{table}
\centering\scriptsize
\caption{Modularity classes} 
\begin{tabulary}{\linewidth}{@{}cLLLL@{}}\toprule 
Names & \centering 1 & 
        \centering 2 & 
        \centering 3 &
        \centering\arraybackslash 4 \\
\cmidrule(r){1-1} 
\cmidrule(rl){2-2} 
\cmidrule(rl){3-3} 
\cmidrule(rl){4-4} 
\cmidrule(l){5-5} 
   0 &  CANADA &  AUSPOL &  CDNPOLI &  COVID19AUS \\ 
   1 &  COVID &  CHINA &  VACCINE &  HEALTH \\ 
   2 &  SOCIALDISTANCING &  QUARANTINE &  MASKS &  MASK \\ 
   3 &  PANDEMIC &  NEWS &  HEALTHCARE &  ECONOMY \\ 
   4 &  TRUMP &  USA &  WEARAMASK &  COVIDIOTS \\ 
   5 &  UK &  COVID19UK &  LONDON &  CORONAVIRUSUK \\ 
   6 &  COVID19 &  CORONAVIRUS &  COVID\_19 &  LOCKDOWN \\ 
   \bottomrule 
\end{tabulary} 
\end{table}
\noindent\lipsum[1][1-4] % dummy texto to see the fit the margins
\end{document}
Fran
  • 80,769
1

By imposing a global overall constraint on the width of the table, you're approaching the problem backwards. The cause of the problem is that the individual cells are too wide unless you permit line-breaking. This may be achieved, say, with the help of the tabularx package and eponymous environment. Note that in order to get satisfactory hyphenation points for some of the words in the table, you'll have to provide a list of acceptable hyphenation points yourself. Another good idea would be to use a "condensed" font, such as Calibri, for the table contents.

enter image description here

\documentclass{article}
\usepackage{iftex}
\ifluatex
  \usepackage{fontspec}
  \setmainfont{Calibri} % or some other condensed font
\else
  \usepackage[T1]{fontenc}
  \usepackage{lmodern}
\fi

\usepackage{booktabs,tabularx,ragged2e} \newcolumntype{C}{>{\Centering\hspace{0pt}}X} \newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X}

% provide hyphenation patterns for uncommon words: \hyphenation{can-ada so-cial-dis-tan-cing wear-a-mask cdn-poli co-ro-na-vi-rus co-ro-na-vi-rus-uk}

\begin{document} \setlength\tabcolsep{3pt} % default: 6pt \begin{table}[t] \caption{names\strut} \label{tab:table1} \begin{tabularx}{\textwidth}{@{} L *{7}{C} @{}} \toprule Modularity Class & 0 & 1 & 2 & 3 & 4 & 5 & 6 \ \midrule 1 & CANADA & COVID & SOCIALDISTANCING & PANDEMIC & TRUMP & UK & COVID-19
\ \addlinespace 2 & AUSPOL & CHINA & QUARANTINE & NEWS & USA & COVID-19-UK & CORONAVIRUS \ \addlinespace 3 & CDNPOLI & VACCINE & MASKS & HEALTHCARE & WEARAMASK & LONDON & COVID-_19 \ \addlinespace 4 & COVID-19-AUS & HEALTH & MASK & ECONOMY & CO-VID-IOTS & CORONAVIRUSUK & LOCKDOWN
\ \bottomrule \end{tabularx} \end{table} \end{document}

Mico
  • 506,678