1

I am writing a conference manuscript using the IEEEtran document class. I am having problem with my table having 9 columns, so didn't fit well into the template's column. Log output shows:

Overfull \hbox (45.8143pt too wide) in paragraph at lines 85--101 

I give a MWE below to reproduce the issue:

%%%% added packages
\usepackage{lipsum}
\usepackage{booktabs,multirow,array}

\begin{document}

\lipsum[1]

\begin{table}[htbp]f
    \centering
    \caption{{Summary of results}
    \begin{tabular}{@{} ll*{7}{r} @{}}
    \toprule
     \multicolumn{2}{l@{}}{Before trip filtering} &  \multicolumn{7}{c@{}}{Predicted class} \\
    \cmidrule(l){3-9}
    \multicolumn{2}{l@{}}{}  & Foot  & Bike & Bus & Car & Metro & Support & Recall \\
    \midrule
              & Foot  & 8534 &  99 &  904 &  4939 & 125 & 14601 & 0.58 \\
              & Bike  &  339 & 483 &   62 &   514 &   0 &  1398 & 0.35  \\ 
Actual class  & Bus   & 1558 &  25 & 1117 &  5616 &   1 &  8317 & 0.20 \\
              & Car   & 1447 & 117 &  629 & 18064 &  44 & 20301 & 0.72\\
              & Metro &  350 &   7 &   12 &   513 &  22 &   904 & 0.04  \\ 
\cmidrule(l){2-9}
            & Precision & 0.70  & 0.66  & 0.41  & 0.61  & 0.11  &   & \\  
    \bottomrule
    \end{tabular}
    \label{tab1}
\end{table}

\lipsum[1]

\end{document}

Output: enter image description here

I am looking for a way to resize this table, to fit in well in one column.

2
  • 1
    \begin{table*} (two-column table) or \tabcolsep=1pt (reduce column separation) or \scalebox
    – Symbol 1
    Feb 4 at 0:28
  • thank you, \tabcolsep=1pt is what I really need in this case.
    – Amina Umar
    Feb 4 at 0:50

2 Answers 2

2

It suffices to (a) set \tabcolsep to 0pt (default is 6pt), (b) switch from a tabular to a tabular* environment with a target width of \columnwidth, and (c) use the (admittedly complicated looking) @{\extracolsep{\fill}} device to instruct LaTeX to increase the whitespace padding between columns as needed. (Basically, this setup endogenizes the \tabcolsep parameter.)

For more information about the tabular* environment, see this answer. [Shameless self-citation alert!]

A separate issue: Should the \cmidrule directives span columns 3 thru 9, or should they perhaps just span columns 3 thru 7?

enter image description here

\documentclass{IEEEtran}
\usepackage{booktabs} %%,multirow,array}
\usepackage{lipsum}
\begin{document}

\lipsum[1]

\begin{table}[htbp]
\setlength\tabcolsep{0pt} % <-- new
\caption{Summary of results}\label{tab1}
\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}} ll *{7}{r} }
   \toprule
   \multicolumn{2}{l}{Before trip filtering} &
   \multicolumn{5}{c}{Predicted class} & Support & Recall \\
   \cmidrule{3-7}
   & & Foot & Bike & Bus & Car & Metro \\
   \midrule
           & Foot  & 8534 &  99 &  904 &  4939 & 125 & 14601 & 0.58 \\
           & Bike  &  339 & 483 &   62 &   514 &   0 &  1398 & 0.35 \\ 
   Actual class & Bus & 1558 & 25 & 1117 & 5616 &  1 &  8317 & 0.20 \\
           & Car   & 1447 & 117 &  629 & 18064 &  44 & 20301 & 0.72 \\
           & Metro &  350 &   7 &   12 &   513 &  22 &   904 & 0.04 \\ 
   \cmidrule{3-7}
           & Precision & 0.70 & 0.66& 0.41 & 0.61  & 0.11 \\  
   \bottomrule
\end{tabular*}
\end{table}

\lipsum[1]

\end{document}
0
\documentclass{IEEEtran}
\usepackage{showframe}
\usepackage{lipsum}
\usepackage{tabularray}
\begin{document}
\lipsum[1-6]
\begin{table}[htbp]
\centering
\caption{Summary of results}
\label{tab1}
\begin{tblr}
{
colspec        = {X[c,m]*{8}{Q[c,m]}},
cell{1}{1}     = {r=2,c=2}{},
cell{1}{3}     = {c=7}{},
cell{3}{1}     = {r=5}{},
hline{1,Z}     = {wd=.08em},
hline{2}       = {3-Z}{wd=.05em},
hline{3}       = {wd=.05em},
hline{Y}       = {2-Z}{wd=.05em},
columns        = {colsep=2.5pt},
cell{3-Z}{3-Z} = {halign=r}
}
Before trip filtering &           & Predicted class &      &      &       &       &         &        \\
                      &           & Foot            & Bike & Bus  & Car   & Metro & Support & Recall \\
Actual class          & Foot      & 8534            & 99   & 904  & 4939  & 125   & 14601   & 0.58   \\
                      & Bike      & 339             & 483  & 62   & 514   & 0     & 1398    & 0.35   \\
                      & Bus       & 1558            & 25   & 1117 & 5616  & 1     & 8317    & 0.20   \\
                      & Car       & 1447            & 117  & 629  & 18064 & 44    & 20301   & 0.72   \\
                      & Metro     & 350             & 7    & 12   & 513   & 22    & 904     & 0.04   \\
                      & Precision & 0.70            & 0.66 & 0.41 & 0.61  & 0.11  &         &        \\
\end{tblr}
\end{table}
\lipsum[1]
\end{document}

enter image description here

You must log in to answer this question.

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