5

I am unfortunately quite a LaTeX noob and am having difficulties putting together a table. My goal is to center the content of each cell both vertically and horizontally. The table is aligned horizontally, otherwise, it won't fit on the page. I would like to be able to adjust the width of the individual columns so that the entire table fits on the page. I would also like to be able to work with newlines in the cells if I have multi-line content. You can find my current solution below. However, this leads to some cells with multiline content not being centered for whatever reason (see especially the "Performance" and "Limitations" column).

Does anyone have a solution for this problem?

Thanks in advance!

\documentclass[conference]{IEEEtran}
\usepackage{pdflscape}
\usepackage{array}

\begin{document}

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{landscape}
    \begin{table}[!h]
        \renewcommand{\arraystretch}{1.2}
        \caption{Comparison of Approaches \\ A: Accuracy, R: Recall, P: Precision, F1: F1-score}
        \label{table_comp}
        \centering
        \begin{tabular}{|C{2.5cm}||C{3cm}|C{1.5cm}|C{3.1cm}|C{3cm}|C{2.7cm}|C{4.5cm}|}
        \hline
        \bfseries Paper & \bfseries Technology & \bfseries Application & \bfseries Deployment Strategy \newline (Placement, Data Source) & \bfseries Dataset & \bfseries Performance Metrics & \bfseries Limitations\\
        \hline\hline
        \multicolumn{7}{|c|}{\bfseries SIDS} \\
        \hline\hline
        Paper 1 & bla1 & - & - & - & F1: 0.82 - 0.99 \newline R: 0.70 - 0.98 & focusing only on MC-MitM Attacks\\
        \hline
        Paper 2 & bla2 & - & - & - & Infected Nodes: Reduced from 49 to 10 \newline Survival Rate: 66.7\% & no baseline comparison \newline no details on dataset \newline uncommon metrics\\
        \hline\hline
        \multicolumn{7}{|c|}{\bfseries AIDS} \\
        \hline\hline
        Paper 3 & bla3 & - & - & - & P: 0.999 - 1.000 \newline R: 0.999 - 1.000 \newline F1: 0.999 - 1.000 & data imbalance not addressed\\
        \hline
        Paper 4 & bla4 & - & - & - & A: 0.8611 - 0.9999 \newline F1: 0.5466 - 0.9893 & insufficient baseline comparison\\
        \hline
        Paper 5 & bla5 & - & - & - & P: 0.9999 \newline R: 0.9749 \newline F1: 0.9866 & insufficient deployment strategy details \\
        \hline
        Paper 6 & bla6 & - & - & - & R: 0.9992 - 0.9998 \newline P: 0.9993 - 0.9998 \newline F1: 0.9992 - 0.9998 & requires significant data to outperform other models \newline insufficient deployment strategy details\\
        \hline
        Paper 7 & bla7 & - & - & - & R: 0.96 - 1.00 \newline P: 1.00 \newline F1: 0.98 - 1.00 & limited model comparison \newline data imbalance not addressed \newline vague details on deployment strategy\\
        \hline
        Paper 8 & bla8 & - & - & - & R: 0.998 - 1.000 \newline P: 1.000 \newline F1: 0.999 - 1.000 & no baseline model \newline mainly focus on DDoS \\
        \hline
        Paper 9 & bla9 & - & - & - & R: 0.4732 - 0.9983 \newline P: 0.4243 - 0.9974 \newline F1: 0.1094 - 0.9978 & insufficient deployment strategy details \newline limited model comparison \\
        \hline
        Paper 10 & bla10 & - & - & - & F1: 0.9782 - 0.9945 & vague details on deployment strategy\\
        \hline\hline
        \multicolumn{7}{|c|}{\bfseries Hybrid} \\
        \hline\hline
        Paper 11 & bla11 & - & - & - & A: 0.9997 \newline F1: 0.957 & No baseline comparison \newline vague details on deployment strategy \\
        \hline
        Paper 12 & bla12 & - & - & - & R: \textgreater \ 0.90 \newline F1: \textgreater \ 0.90  & limited model comparison \newline no explicit performance measurements \newline outdated general purpose dataset \newline data imbalance not addressed\\
        \hline
        Paper 13 & bla13 & - & - & - & F1: 0.8001 - 0.9999 & -\\
        \hline
        \end{tabular}
    \end{table}
\end{landscape}
\end{document}

Screenshot of the actual table: Screenshot of the problem

5
  • 2
    I would suggest abandoning the default table environment and use the package tabularray instead. It has everything you are asking for. ctan.org/pkg/tabularray?lang=en Commented Jun 21 at 22:17
  • 1
    Welcome to TeX.SE! Please add to your code the used documentclass and eventually page layout definitions (if you used them).
    – Zarko
    Commented Jun 22 at 3:43
  • What's the document's main font size? How wide are the margins?
    – Mico
    Commented Jun 22 at 5:32
  • It is based on the IEEEtran documentclass documentation
    – bolli
    Commented Jun 22 at 6:48
  • 1
    I suppose the three columns in the middle are not empty for all rows in the actual table. If they are, you could remove them to recover a serious amount of space!
    – nplatis
    Commented Jun 22 at 11:41

2 Answers 2

4

My goal is to center the content of each cell both vertically and horizontally.

Why? Why make life (or, at the very least, the chore of reading your table) tedious for your readers?

Your table simply contains too much material to fit on one page. I suggest you employ an xltabular environment, which combines the capabilities of the longtable and tabularx environments. I would also get rid of all vertical rules and most horizontal rules in order to give the material a more open and inviting "look".

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters as needed
\usepackage{pdflscape,xltabular}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{booktabs} % for well-spaced horizontal rules

\begin{document}

\begin{landscape}

\begin{xltabular}{\linewidth}{@{} 
  l
  l 
  l 
  L % <-- width of this column is a residual
  P{2cm} 
  P{3.5cm}
  P{6cm} @{}}


%%% headers and footers

\caption{Comparison of approaches}\label{table_comp} \\
\multicolumn{7}{@{}l}{A: Accuracy, R: Recall, P: Precision, F1: F1-score} \\[1ex]

\toprule
Paper & Technology & Application 
& Deployment Strategy \newline (Placement, Data Source) 
& Dataset & Performance Metrics & Limitations \\
\midrule
\endfirsthead

\multicolumn{7}{@{}l}{\tablename~\thetable, continued} \\[1ex]
\toprule
Paper & Technology & Application 
& Deployment Strategy \newline (Placement, Data Source) 
& Dataset & Performance Metrics & Limitations \\
\midrule
\endhead

\midrule
\multicolumn{7}{r@{}}{(continued on next page)} \\
\endfoot

\bottomrule
\endlastfoot


%%% body of table

\multicolumn{7}{@{}l}{SIDS} \\
\midrule
    Paper 1 & bla1 & -- & -- & -- 
    & F1: 0.82--0.99 \newline R: 0.70--0.98 
    & focusing only on MC-MitM Attacks \\
    \addlinespace
    Paper 2 & bla2 & -- & -- & -- 
    & Infected Nodes: Reduced from 49 to 10 
    \newline Survival Rate: 66.7\% 
    & no baseline comparison 
      \newline no details on dataset 
      \newline uncommon metrics \\
\midrule
    \multicolumn{7}{@{}l}{AIDS} \\
\midrule
    Paper 3 & bla3 & -- & -- & -- 
    & P: 0.999--1.000 \newline R: 0.999--1.000 \newline F1: 0.999--1.000 
    & data imbalance not addressed \\
    \addlinespace
    
    Paper 4 & bla4 & -- & -- & -- 
    & A: 0.8611--0.9999 \newline F1: 0.5466--0.9893 
    & insufficient baseline comparison \\
    \addlinespace
    Paper 5 & bla5 & -- & -- & -- 
    & P: 0.9999 \newline R: 0.9749 \newline F1: 0.9866 
    & insufficient deployment strategy details \\
    \addlinespace
    Paper 6 & bla6 & -- & -- & -- 
    & R: 0.9992--0.9998 \newline P: 0.9993--0.9998 \newline F1: 0.9992--0.9998 
    & requires significant data to outperform other models 
      \newline insufficient deployment strategy details \\
    \addlinespace
    Paper 7 & bla7 & -- & -- & -- 
    & R: 0.96--1.00 \newline P: 1.00 \newline F1: 0.98--1.00 
    & limited model comparison 
      \newline data imbalance not addressed 
      \newline vague details on deployment strategy \\
    \addlinespace
    Paper 8 & bla8 & -- & -- & -- 
    & R: 0.998--1.000 \newline P: 1.000 \newline F1: 0.999--1.000 
    & no baseline model 
      \newline mainly focus on DDoS \\
    \addlinespace
    Paper 9 & bla9 & -- & -- & -- 
    & R: 0.4732--0.9983 \newline P: 0.4243--0.9974 \newline F1: 0.1094--0.9978 
    & insufficient deployment strategy details 
      \newline limited model comparison \\
    \addlinespace
    Paper 10 & bla10 & -- & -- & -- 
    & F1: 0.9782--0.9945 & vague details on deployment strategy \\
\midrule
    \multicolumn{7}{@{}l}{Hybrid} \\
\midrule
    Paper 11 & bla11 & -- & -- & -- 
    & A: 0.9997 \newline F1: 0.957 
    & No baseline comparison 
      \newline vague details on deployment strategy \\
    \addlinespace
    Paper 12 & bla12 & -- & -- & -- 
    & R: $>0.90$ \newline F1: $>0.90$
    & limited model comparison 
    \newline no explicit performance measurements 
    \newline outdated general purpose dataset 
    \newline data imbalance not addressed \\
    \addlinespace
    Paper 13 & bla13 & -- & -- & -- 
    & F1: 0.8001--0.9999 & --  \\

\end{xltabular}
\end{landscape}
\end{document}
1
  • Yeah, i think you are right. I thought that centralizing the table content would make it easier to read, but it is much more important to " spread the table out" and stretch it over two pages
    – bolli
    Commented Jun 22 at 7:03
4

Your table I woulood design on the following (more profesisional) way. At its codding I also would consider @Kenneth Odle comment:

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{pdflscape}

\usepackage{enumitem}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx, varwidth}

\begin{document}
\begin{landscape}
    \begin{table}[h]
    \setlist{nosep, leftmargin=*}
\caption{Comparison of Approaches.\qquad A: Accuracy, R: Recall, P: Precision, F1: F1-score}
\label{table_comp}

\begin{tblr}{%colsep=4pt,
             colspec = {X[l]X[l] X[l]X[1.4, l] X[l]X[1.6, l] X[3]},
             cells   = {font=\small\linespread{0.84}\selectfont},
             row{1}  = {c, font=\small\bfseries},
             rowsep=3pt,
             stretch=-1,%<--- remove extra space above and below lists
                        % with nosep option; doc p.51 tabularray
              measure = vbox,
             }
%             C{2.5cm}||C{3cm}|C{1.5cm}|C{3.1cm}|C{3cm}|C{2.7cm}|C{4.5cm}|}
    \toprule    
Paper   &   Technology
            &   Application
                &   {Deployment Strategy\\ (Placement, Data Source)} 
                    &   Dataset
                        &   Performance Metrics 
                               &   Limitations                      \\   
    \midrule
\SetCell[c=7]{c, font=\bfseries}     SIDS 
        &   &   &   &   &   &                                       \\
    \midrule
Paper 1 &   bla1 
            & - & - & - &   {F1: 0.82 - 0.99 \\ R: 0.70 - 0.98} 
                            &   focusing only on MC-MitM Attacks    \\
Paper 2 &   bla2 
            & - & - & - &   {Infected Nodes: Reduced from 49 to 10\\ 
                             Survival Rate: \qty{66.7}{\%}}
                            &   \begin{itemize}
                            \item   no baseline comparison
                            \item   no details on dataset\
                            \item   uncommon metrics
                                \end{itemize}                   \\
    \midrule
\SetCell[c=7]{c, font=\bfseries}     AIDS
        &   &   &   &   &   &                                       \\
    \midrule
Paper 3 &   bla3 
            & - & - & - &   {P: 0.999 - 1.000\\ R: 0.999 - 1.000\\ F1: 0.999 - 1.000} 
                            &   \begin{itemize}
                            \item   data imbalance not addressed  
                                \end{itemize}   \\
Paper 4 &   bla4 
            & - & - & - &   {A: 0.8611 - 0.9999\\ F1: 0.5466 - 0.9893} 
                            &   \begin{itemize}
                            \item   insufficient baseline comparison 
                                \end{itemize}   \\
Paper 5 &   bla5 
            & - & - & - &   P: {0.9999\\ R: 0.9749\\ F1: 0.9866} 
                            &   \begin{itemize}
                            \item   insufficient deployment strategy details
                                \end{itemize}   \\
Paper 6 &   bla6 
            & - & - & - &   R: {0.9992 - 0.9998\\ P: 0.9993 - 0.9998\\ F1: 0.9992 - 0.9998} 
                            &   \begin{itemize}
                            \item   requires significant data to outperform other models 
                            \item   insufficient deployment strategy details
                                \end{itemize}   \\
Paper 7 &   bla7 
            & - & - & - &   {R: 0.96 - 1.00\\ P: 1.00\\ F1: 0.98 - 1.00}
                            &   \begin{itemize}
                            \item   limited model comparison 
                            \item   data imbalance not addressed 
                            \item   vague details on deployment strategy                 
                                \end{itemize}   \\
Paper 8 &   bla8 
            & - & - & - &   {R: 0.998 - 1.000\\ P: 1.000\\ F1: 0.999 - 1.000} 
                            &   \begin{itemize}
                            \item   no baseline model 
                            \item   mainly focus on DDoS 
                                \end{itemize}   \\
Paper 9 &   bla9 
            & - & - & - &   {R: 0.4732 - 0.9983\\ P: 0.4243 - 0.9974\\ F1: 0.1094 - 0.9978} 
                            &   \begin{itemize}
                            \item   insufficient deployment strategy details 
                            \item   limited model comparison     
                                \end{itemize}   \\
Paper 10 &  bla10 
            & - & - & - &   F1: 0.9782 - 0.9945 
                            &   \begin{itemize}
                            \item   vague details on deployment strategy  
                                \end{itemize}   \\
    \midrule
\SetCell[c=7]{c, font=\bfseries}      Hybrid 
        &   &   &   &   &   &                                       \\
    \midrule
Paper 11 &  bla11 
            & - & - & - &   {A: 0.9997\\   F1: 0.957}
                            &   \begin{itemize}
                            \item   No baseline comparison 
                            \item   vague details on deployment strategy \\
                                \end{itemize}   \\
Paper 12 &  bla12 
            & - & - & - &  {R: $>0.90$\\ F1:  $>0.90$}  
                            &   \begin{itemize}
                            \item   limited model comparison 
                            \item   no explicit performance measurements 
                            \item   outdated general purpose dataset 
                            \item   data imbalance not addressed\\
                                \end{itemize}   \\
Paper 13 &  bla13 
            & - & - & - &   F1: 0.8001 - 0.9999 
                            & -     \\
    \bottomrule
\end{tblr}
    \end{table}
\end{landscape}
\end{document}

enter image description here

3
  • 2
    Were you going to post some code too?
    – Mico
    Commented Jun 22 at 6:04
  • Would be great!
    – bolli
    Commented Jun 22 at 7:05
  • 1
    @mico, hiuh, I was shure that I do this ... now i need to find it and added to answe .... 😒. Ok., i Found ti 😊
    – Zarko
    Commented Jun 22 at 10:30

You must log in to answer this question.

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