1

I'm sorry for the ambiguity of the question's title.

I'm working with a 2-columns latex template. Here's my MWE:

\begin{table}
\centering
\caption{My table}
\resizebox{\columnwidth}{!}{%
\begin{tabular}{ccc|cc|cc}
\toprule
\multirow{2}{*}{\rotatebox{90}{Rank}}     & \multirow{2}{*}{\rotatebox{90}{FLOPs ↓\%}}          & \multirow{2}{*}{\rotatebox{90}{Params. ↓\%}}                     & \multicolumn{2}{c|}{NMSE}    & \multicolumn{2}{c}{Accuracy (\%)}    \\
\cmidrule{4-7}
     & &     & Before    & After           & Before    & After               \\
\midrule
1       & 88.03        & 87.06          & 0.xxxx    & 0.1613          & 10        & 93.84               \\
2       & 76.44        & 75.98          & 0.xxxx    & 0.1508          & 10        & 94.11               \\
3       & 64.85        & 64.91          & 0.xxxx    & 0.1420          & 68.1      & 94.18               \\
4       & 53.27        & 53.84          & 0.xxxx    & 0.1383          & 89.96     & 94.07               \\
5       & 41.69        & 42.76          & 0.xxxx    & 0.1348          & 92.5      & 94.22               \\
6       & 30.10        & 31.69          & 0.xxxx    & 0.1541          & 93.38     & 94.15               \\
7       & 18.51        & 20.61          & 0.xxxx    & 0.1333          & 93.89     & 94.11               \\
8       & 6.93         & 9.54           & 0.xxxx    & 0.0011          & 94.03     & 94.03               \\
\bottomrule
\end{tabular}
}
\end{table}

This code yields the table:

enter image description here

I have 2 problems:

  1. The FLOPs and Params columns overflowed the cell. How can I fix this? My main idea is to rotate the cell so that the resized table can be bigger.
  2. I want the vertical dividing lines between 2 columns Params and NMES, and NMES and Accuracy to cross over the first line.

Thank you very much!

Tien
  • 135

1 Answers1

1

Some suggestions:

  • Never, ever use \resizebox to force a table into the width of the textblock (here: \columnwidth), unless you don't mind showing your contempt for your readers openly -- and aren't too worried about the backlash you might experience as a consequence.

    If you don't believe me or don't know what I'm talking about, you should still refrain from using \resizebox.

  • You're not setting aside enough vertical space for the rotated column headers. I suggest you change all instances of \multirow{2} to \multirow{4} and insert two extra blank rows in the header.

  • Don't use vertical rules if you want to use the line-drawing macros of the booktabs package. No exceptions. None.

  • To make the table more readable, do align the numbers in columns 2 thru 7 on their decimal markers. This may be done with the help of the machinery of the siunitx package; see the code below for a practical implementation of this idea.

  • If you believe the table's width should equal \columnwidth exactly, consider using a tabular* environment. See the code for the second table shown below for a practical implementation of this idea.

enter image description here

\documentclass{IEEEtran} % or some other suitable document class
\usepackage{newtxtext,newtxmath} % optional (Times Roman font)
\usepackage{graphicx,booktabs,multirow}
\usepackage{siunitx}
\newcolumntype{T}[1]{S[table-format=#1]}
\usepackage{lipsum} % filler text

\begin{document} \begin{table}[h]

\centering

\caption{with \texttt{tabular}} \begin{tabular}{@{} l {2}{T{2.2}} {2}{T{1.4}} {2}{T{2.2}} @{}} \toprule \multirow{4}{}{\rotatebox{90}{Rank}} & {\multirow{4}{}{\rotatebox{90}{FLOPs ↓%}}} & {\multirow{4}{}{\rotatebox{90}{Params. ↓%}}} & \multicolumn{2}{c}{NMSE} & \multicolumn{2}{c@{}}{Accuracy (%)} \ \cmidrule(lr){4-5} \cmidrule(l){6-7} & & & {Before} & {After} & {Before} & {After} \ \ \ \midrule 1 & 88.03 & 87.06 & 0.1111 & 0.1613 & 10 & 93.84 \ 2 & 76.44 & 75.98 & 0.1111 & 0.1508 & 10 & 94.11 \ 3 & 64.85 & 64.91 & 0.1111 & 0.1420 & 68.1 & 94.18 \ 4 & 53.27 & 53.84 & 0.1111 & 0.1383 & 89.96 & 94.07 \ 5 & 41.69 & 42.76 & 0.1111 & 0.1348 & 92.5 & 94.22 \ 6 & 30.10 & 31.69 & 0.1111 & 0.1541 & 93.38 & 94.15 \ 7 & 18.51 & 20.61 & 0.1111 & 0.1333 & 93.89 & 94.11 \ 8 & 6.93 & 9.54 & 0.1111 & 0.0011 & 94.03 & 94.03 \ \bottomrule \end{tabular}

\bigskip\bigskip \setlength\tabcolsep{0pt} \caption{with \texttt{tabular}} \begin{tabular}{\columnwidth}{@{\extracolsep{\fill}} l {2}{T{2.2}} {2}{T{1.4}} {2}{T{2.2}} } \toprule \multirow{4}{}{\rotatebox{90}{Rank}} & {\multirow{4}{}{\rotatebox{90}{FLOPs ↓%}}} & {\multirow{4}{}{\rotatebox{90}{Params. ↓%}}} & \multicolumn{2}{c}{NMSE} & \multicolumn{2}{c}{Accuracy (%)} \ \cmidrule{4-5} \cmidrule{6-7} & & & {Before} & {After} & {Before} & {After} \ \ \ \midrule 1 & 88.03 & 87.06 & 0.1111 & 0.1613 & 10 & 93.84 \ 2 & 76.44 & 75.98 & 0.1111 & 0.1508 & 10 & 94.11 \ 3 & 64.85 & 64.91 & 0.1111 & 0.1420 & 68.1 & 94.18 \ 4 & 53.27 & 53.84 & 0.1111 & 0.1383 & 89.96 & 94.07 \ 5 & 41.69 & 42.76 & 0.1111 & 0.1348 & 92.5 & 94.22 \ 6 & 30.10 & 31.69 & 0.1111 & 0.1541 & 93.38 & 94.15 \ 7 & 18.51 & 20.61 & 0.1111 & 0.1333 & 93.89 & 94.11 \ 8 & 6.93 & 9.54 & 0.1111 & 0.0011 & 94.03 & 94.03 \ \bottomrule \end{tabular*} \end{table}

\lipsum[1][1-4] \end{document}

Mico
  • 506,678
  • Deeply from my heart, thank you for these lessons @Mico – Tien Jun 09 '23 at 11:50
  • Hi @Mico, can you please cite some sources that I can read more about the reasons to avoid using \resizebox. Normally I generate tables with https://www.tablesgenerator.com/ and this site recommends using resize box. Thank you so much. – Tien Jun 09 '23 at 12:42
  • @Van-TienPHAM - I, in turn, wouldn’t recommend that site. The code they produce is unbelievably convoluted and cannot be used as a starting point for learning how to code tables innLaTeX. I’m not at all surprised that they use \resizebox as a panacea. – Mico Jun 09 '23 at 12:57
  • @Van-TienPHAM - For references, look at what David Carlisle — the author of the \resizebox instructions [!] has to say in this topic on this site. – Mico Jun 09 '23 at 12:59
  • thank you so much @Mico, I respect your reputation score. I'm quite surprised by this because I see many papers from prestigious conferences (e.g, IEEE CVPR) using \resizebox (my guess via reading the papers, others from my colleagues). One last question please, the code you gave above makes the text font of the table a little weird. I mean it became different from the normal text of paragraphs (while this doesn't happen with the \resizebox approach). Is this expected? Thank you! – Tien Jun 09 '23 at 14:03