2

I'm begin in LaTeX and I generated the following table with the help of an online table generator. However, I have some issues with the centering of some cell contents.

enter image description here

Here is my code:

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{multirow}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{pgfplots}\pgfplotsset{compat=1.16}
\usepackage{xcolor}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{N}{>{\centering\arraybackslash}m{.5in}}
\newcolumntype{G}{>{\centering\arraybackslash}m{2in}}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
  T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
%%\usepackage{array}
%%\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}

\begin{table*}[htbp!]
\caption{Data quality alteration}
\begin{center}
\begin{tabular}{|C{1cm}|C{0.7cm}|C{1.7cm}|C{0.7cm}|C{1.7cm}|C{0.7cm}|C{1.7cm}|C{0.7cm}|C{1.7cm}|C{0.7cm}|C{1.7cm}|}
\hline
\multirow{3}{=}{\begin{tabular}[c]{@{}c@{}}\ \textbf{}\\\textbf{Anomaly}\end{tabular}} 
& \multicolumn{10}{c|}{\textbf{System variables }} \\ \cline{2-11} 
& \multicolumn{2}{c|}{\textbf{$t_{m}$}} 
& \multicolumn{2}{c|}{\textbf{$s_{p}$}} 
& \multicolumn{2}{c|}{\textbf{$o_{v}$}} 
& \multicolumn{2}{c|}{\textbf{$l_{ft}$}} 
& \multicolumn{2}{c|}{\textbf{$l_{ot}$}} \\ 
\cline{2-11} 
& \textbf{$\vec{DQV}$} 
& \textbf{$\vec{IQV}$} 
& \textbf{$\vec{DQV}$} 
& \textbf{$\vec{IQV}$} 
& \textbf{$\vec{DQV}$} 
& \textbf{$\vec{IQV}$} 
& \textbf{$\vec{DQV}$} 
& \textbf{$\vec{IQV}$} 
& \textbf{$\vec{DQV}$} 
& \textbf{$\vec{IQV}$} \\ 
\cline{2-11} 
& \textbf{\{$i_{inc}$\}} 
& \textbf{\{$cd_{err},ed_{coh}$\}} 
& \textbf{\{$i_{inc}$\}} 
& \textbf{\{$cd_{err},ed_{coh}$\}} 
& \textbf{\{$i_{inc}$\}} 
& \textbf{\{$cd_{err},ed_{coh}$\}} 
& \textbf{\{$i_{inc}$\}} 
& \textbf{\{$cd_{err},ed_{coh}$\}} 
& \textbf{\{$i_{inc}$\}} 
& \textbf{\{$cd_{err},ed_{coh}$\}} \\ 
\hline
\textbf{Normal} & \{false\} & \{false,0\} & \{false\} & \{false,2\} & \{false\} & \{false,2\} & \{false\} & \{false,0\} & \{false\} & \{false,0\} \\ \hline
\textbf{Port scan} & \{false\} & \{false,0\} & \{false\} & \{false,2\} & \{false\} & \{false,2\} & \{false\} & \{false,0\} & \{false\} & \{false,0\} \\ \hline
\textbf{PLC STOP} & \{false\} & \{false,\textbf{18}\} & \{\textbf{true}\} & \{\textbf{true,50}\} & \{\textbf{true}\} & \{\textbf{true,50}\} & \{false\} & \{false,\textbf{-2}\} & \{false\} & \{false,\textbf{-2}\} \\ \hline
\textbf{MITM attack on $s_{p}$} & \{false\} & \{\textbf{true},\textbf{29}\} & \{false\} & \{false,\textbf{50}\} & \{false\} & \{false,\textbf{50}\} & \{false\} & \{false,\textbf{-2}\} & \{false\} & \{false,\textbf{-2}\} \\ \hline
\textbf{MITM attack on $o_{v}$} & \{false\} & \{false,\textbf{-13}\} & \{false\} & \{false,2\} & \{false\} & \{false,\textbf{50}\} & \{false\} & \{false,0\} & \{false\} & \{false,0\} \\ \hline
\end{tabular}
\label{tab4}
\end{center}
\end{table*}
\end{document}

Thanks for your help.

7
  • 1
    Welcome to TeX.SE! Please complete your code fragment that it will become compilable (missing are document class, some packages and your definitions). It seems, that your table is wider than text width and columns width is smaller than width of their contents.
    – Zarko
    Commented Feb 25, 2020 at 13:33
  • Why you have cells' contents in table body in curly braces? Is this necessary?
    – Zarko
    Commented Feb 25, 2020 at 13:39
  • Thanks for your help ! I think it was done by the online table generator but it's not necessary
    – nicope13
    Commented Feb 25, 2020 at 13:56
  • 1
    Well, than remove them. Also instead C{...} rather use c, table will nicer fit on the page and columns will become centered in columns (now are spill out due to small column widths).
    – Zarko
    Commented Feb 25, 2020 at 13:58
  • I've taken the liberty of editing your code so that it actually compiles. E.g., I added the instruction \usepackage{multirow} and I fixed the syntax of the \multirow directive.
    – Mico
    Commented Feb 25, 2020 at 14:09

2 Answers 2

2

I would like to recommend that you take the following measures:

  • give the table a much more open "look", mainly by omitting all vertical rules and using fewer, but well-spaced horizontal rules. (The latter may be achieved by loading the booktabs package and employing its macros \toprule, \midrule, etc.) I

  • employ a tabularx environment and let the first column automatically insert line breaks in cells as needed

  • use the basic c column type for all ten data columns

  • do not bold-face all header cells unless you feel an acute urge to yell at your readers

  • set \setlength\tabcolsep{4.5pt} to obviate the need for text wrapping in the first column

  • replace \vec{...} with \overset{\longrightarrow}{...}.

This is how the resulting table looks like:

enter image description here

I would like to argue that by giving the table a more open look, the issue of whether or not some cells "look centered" more or less vanishes automatically.

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

%% (omitted all preamble code that doesn't affect the table)

\usepackage{amsmath,amssymb}
\usepackage{tabularx,booktabs,ragged2e,bm,newtxmath} % new packages

\begin{document} 

\begin{table*}
\setlength\tabcolsep{4.5pt} % default: 6pt
\caption{Data quality alteration} \label{tab4}
\begin{tabularx}{\textwidth}{@{} X *{10}{c} @{}}
\toprule
Anomaly & \multicolumn{10}{c@{}}{System variables} \\
\cmidrule(l){2-11}
& \multicolumn{2}{c}{$t_{m}$}
& \multicolumn{2}{c}{$s_{p}$}
& \multicolumn{2}{c}{$o_{v}$}
& \multicolumn{2}{c}{$l_{\mathit{ft}}$}
& \multicolumn{2}{c@{}}{$l_{\mathit{ot}}$} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9} \cmidrule(l){10-11}
& $\overset{\longrightarrow}{DQV}$ & $\overset{\longrightarrow}{IQV}$
& $\overset{\longrightarrow}{DQV}$ & $\overset{\longrightarrow}{IQV}$
& $\overset{\longrightarrow}{DQV}$ & $\overset{\longrightarrow}{IQV}$
& $\overset{\longrightarrow}{DQV}$ & $\overset{\longrightarrow}{IQV}$
& $\overset{\longrightarrow}{DQV}$ & $\overset{\longrightarrow}{IQV}$ \\
\addlinespace
& \{$i_{\textrm{inc}}$\} & \{$\mathit{cd}_{\textrm{err}},\mathit{ed}_{\textrm{coh}}$\}
& \{$i_{\textrm{inc}}$\} & \{$\mathit{cd}_{\textrm{err}},\mathit{ed}_{\textrm{coh}}$\}
& \{$i_{\textrm{inc}}$\} & \{$\mathit{cd}_{\textrm{err}},\mathit{ed}_{\textrm{coh}}$\}
& \{$i_{\textrm{inc}}$\} & \{$\mathit{cd}_{\textrm{err}},\mathit{ed}_{\textrm{coh}}$\}
& \{$i_{\textrm{inc}}$\} & \{$\mathit{cd}_{\textrm{err}},\mathit{ed}_{\textrm{coh}}$\} \\
\midrule
Normal & \{false\} & \{false,0\} & \{false\} & \{false,2\} & \{false\} & \{false,2\} & \{false\} & \{false,0\} & \{false\} & \{false,0\} \\
\addlinespace % \hline
Port scan & \{false\} & \{false,0\} & \{false\} & \{false,2\} & \{false\} & \{false,2\} & \{false\} & \{false,0\} & \{false\} & \{false,0\} \\
\addlinespace % \hline
PLC STOP & \{false\} & \{false,$\bm{18}$\} & \{\textbf{true}\} & \{\textbf{true},$\bm{50}$\} & \{\textbf{true}\} & \{\textbf{true},$\bm{50}$\} & \{false\} & \{false,$\bm{-2}$\} & \{false\} & \{false,$\bm{-2}$\} \\
\addlinespace % \hline
MITM attack on $s_{p}$ & \{false\} & \{\textbf{true},$\bm{29}$\} & \{false\} & \{false,$\bm{50}$\} & \{false\} & \{false,$\bm{50}$\} & \{false\} & \{false,$\bm{-2}$\} & \{false\} & \{false,$\bm{-2}$\} \\
\addlinespace % \hline
MITM attack on $o_{v}$ & \{false\} & \{false,$\bm{-13}$\} & \{false\} & \{false,2\} & \{false\} & \{false,$\bm{50}$\} & \{false\} & \{false,0\} & \{false\} & \{false,0\} \\
\bottomrule
\end{tabularx}
\end{table*}
\end{document} 
3
  • 1
    You are right, it more readable like this. Thanks for your advices, it is my first paper so they are very useful for me
    – nicope13
    Commented Feb 26, 2020 at 7:06
  • I try to adapt your code for an other table but I don't have the expected results. It's a table with 13 columns, 1 for headers and 12 for results. \begin{tabularx}{\textwidth}{@{} X *{10}{c} @{}} will be \begin{tabularx}{\textwidth}{@{} X *{12}{c} @{}} am I right ?
    – nicope13
    Commented Feb 26, 2020 at 8:36
  • @nicope13 - Indeed, to allow for 12 instead of 10 data columns, it's necessary to change *{10}{c} to *{12}{c}. Depending on how wide the 12 data columns are, though, there may be no space "left over" for the header column. Is that the problem you're experiencing? Have you tried inserting the instruction \small, or even \footnotesize, immediately after \begin{table*}? Another tool-of-the-trade might be to change \setlength\tabcolsep{4.5pt} to, say, \setlength\tabcolsep{3pt}.
    – Mico
    Commented Feb 26, 2020 at 8:45
0

Here is the table I want to adapt: enter image description here

The adapted code would be:

\begin{table*}
\setlength\tabcolsep{4.5pt}
\caption{Nodes closeness centrality}\label{tab3}
\begin{tabularx}{\textwidth}{@{} X *{12}{c} @{}}
\toprule
& \multicolumn{2}{c@{}}{Digital subsystems} 
& \multicolumn{5}{c@{}}{Physical subsystems} 
& \multicolumn{5}{c@{}}{System variables}\\
\cmidrule(l){2-3} \cmidrule(l){4-8} \cmidrule(l){9-13}
\addlinespace
Node & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\addlinespace
Node & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabularx}
\end{table*} 

But I don't have the expected result: enter image description here Updated result: enter image description here

2
  • I changed \begin{tabularx}{\textwidth}{@{} X *{12}{c} @{}} with \begin{tabularx}{\textwidth}{@{} X *{12}{X} @{}} and now it is working for the table width but the values are not centered. Maybe I have to defined a new column type ?
    – nicope13
    Commented Feb 26, 2020 at 9:53
  • Ok now it is perfect by defining \newcolumntype{Y}{>{\centering\arraybackslash}X} and change \begin{tabularx}{\textwidth}{@{} X *{12}{X} @{}} by \begin{tabularx}{\textwidth}{@{} X *{12}{Y} @{}}
    – nicope13
    Commented Feb 26, 2020 at 10:01

You must log in to answer this question.

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