1

I would like to create a table as follows:

expectation

My current code is as follows:

\documentclass[journal]{IEEEtran}
\begin{document}

\label{tab:table_computational_time} 
\noindent\begin{tabularx}{\linewidth} { |
  l |
  >{\raggedright\arraybackslash}X |
  c |
}
  \hline
  \textbf{wafer flow} & \textbf{MIP II model} & \textbf{MRT sequence}  \\
  \hline
  $[2]$  & 198 & 0.11 \\
  \hline
  $[3]$  & 204 & 0.11 \\
  \hline
  $[1,2]$  & 375 & 0.12\\
  \hline
  $[1,3]$  & 367 & 0.13\\
  \hline
  $[1,2,1]$  & 756 & 0.13\\
  \hline
  $[1,2,2]$  & 861 & 0.14\\
  \hline
  $[1,3,1]$  & 732 & 0.13\\
  \hline
  $[1,2,1,1]$  & 1288 & 0.13\\
  \hline
  $[1,3,1,1]$  & 1314 & 0.13\\
  \hline
  $[1,2,1,2]$  & 1538 & 0.15\\
  \hline
  $[1,2,2,1]$  & 1450 & 0.14\\
  \hline
  $[1,2,2,2]$  & 1444 & 0.14\\
  \hline
  $[1,3,2,1]$  & 1387 & 0.15\\
  \hline
  $[1,2,1,1,1]$  & 2381 & 0.13\\
  \hline
\end{tabularx}
\end{document}

However, the current result is as follows.

current result

Can anyone suggest on how to adjust the code in order to:

(a) merge the cell for "wafer flow" and add the "Computational time (seconds)" into the table title?

(b) have all numbers are aligned centered within each cell.

Thank you.

0

3 Answers 3

3

A solution using tabularray package. I think the code is self-explanatory:

\documentclass[journal]{IEEEtran}
\usepackage{lipsum}     % only for dummy text
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
\lipsum[1][1-3]
\begin{table}[ht]\centering
\caption{One option}
\begin{tblr}
{
  colspec={cS[table-format=4]     % 4 integer digits
            S[table-format=1.2]}, % 1 integer and 2 decimal digits
  hlines,vlines,
  row{1,2}={font=\bfseries},
  cell{3-Z}{1}={preto={$[},appto={]$}}, % adding '$[' at the beginning and ']$' at the end of these cells
  cell{1}{2}={c=2}{}, % cell in row 1 and column 2 expands to 2 (c)olumns
  cell{1}{1}={r=2}{}  % cell in row 1 and column 1 expands to 2 (r)ows
}
wafer flow & {{{Computational time (seconds)}}}  \\
           & {{{MIP II model}}} & {{{MRT sequence}}}\\
2          &  198 & 0.11\\
3          &  204 & 0.11\\
1,2        &  375 & 0.12\\
1,3        &  367 & 0.13\\
1,2,1      &  756 & 0.13\\
1,2,2      &  861 & 0.14\\
1,3,1      &  732 & 0.13\\
1,2,1,1    & 1288 & 0.13\\
1,3,1,1    & 1314 & 0.13\\
1,2,1,2    & 1538 & 0.15\\
1,2,2,1    & 1450 & 0.14\\
1,2,2,2    & 1444 & 0.14\\
1,3,2,1    & 1387 & 0.15\\
1,2,1,1,1  & 2381 & 0.13
\end{tblr}
\end{table}

\lipsum[2]
\begin{table}[ht]\centering
\caption{Another one}
\begin{tblr}
{
  colspec={cS[table-format=4]S[table-format=1.2]},
  row{1,2}={font=\bfseries},
  cell{3-Z}{1}={preto={$[},appto={]$}},
  cell{1}{2}={c=2}{},
  hline{1,Z}={0.8pt}, % first and last horizontal lines
  hline{3}={0.4pt},   % third horizontal line
}
wafer flow & {{{Computational time (seconds)}}}  \\
           & {{{MIP II model}}} & {{{MRT sequence}}}\\
2          &  198 & 0.11\\
3          &  204 & 0.11\\
1,2        &  375 & 0.12\\
1,3        &  367 & 0.13\\
1,2,1      &  756 & 0.13\\
1,2,2      &  861 & 0.14\\
1,3,1      &  732 & 0.13\\
1,2,1,1    & 1288 & 0.13\\
1,3,1,1    & 1314 & 0.13\\
1,2,1,2    & 1538 & 0.15\\
1,2,2,1    & 1450 & 0.14\\
1,2,2,2    & 1444 & 0.14\\
1,3,2,1    & 1387 & 0.15\\
1,2,1,1,1  & 2381 & 0.13
\end{tblr}
\end{table}

\lipsum[3]
\end{document}

enter image description here

0

Here is an elementary solution:

(a) for row merging, load the multirow package and use the corresponding command. (b) for alignment. change l to c, and \raggedright to \flushright in the tabularx preamble.

By the way,

  • why use a tabularx where a basic tabular seems to be sufficient?
  • Doing so, to avoid to type hundreds of $, uses an array or load package array replace in the tabular preamble: | l | by |>{$}l<{$}| or |>{$}c<{$}|

MWE combining all these ingredients :

\documentclass[journal]{IEEEtran}
\usepackage{array,multirow,bigstrut}\begin{document}
% \label{tab:computational_time} 
\begin{center}
\begin{tabular}{*{3}{|>{$}c<{$}}|}
% the construct *{3}{...} means repeat 3 times the format ...\hline
\multirow{2}[t 3]*{\textbf{wafer flow}} 
& \multicolumn{2}{c|}{\textbf{computational time (s)}}\\
\cline{2-3}
& \textbf{MIP II model} & \textbf{MRT sequence}  \\
    \hline
    [2]  & 198 & 0.11 \\
    \hline
    [3]  & 204 & 0.11 \\
    \hline
    [1,2] & 375 & 0.12\\
    \hline
    [1,3] & 367 & 0.13\\
    \hline
    [1,3,1,1] & 1314 & 0.13\\
\hline
\end{tabular}
\end{center
\end{document}

Note: here, the {center} environment ensure centering in the current column. To get a numbered tabke with caption and label,insert it in a floating {table} (or {table*},full page-width centering) and replace the environment {center} by the \centering command inside the table. The (disabled) \label does make sense only in such a numbered environment.

EDIT The @juan answer is a less elementary but much more powerful solution. I use and recomnand it for complex designs, but perhaps not for the rather simple question from the OP.

2
  • Thank you, @Jhor. The code worked, however there was error message: "unclosed $ found at close group }" and "unexpected close group } found after $" on the line: }{*{3}{|>{$}c<{$}}|}. In this case, what should I do? thank you. Commented Jun 28, 2023 at 2:17
  • I can't reproduce the reported error. With copy-paste the MWE, i don't get any error nor warning. Did you load the three package in my MWE ? Is your LaTeX up-to-date ?
    – Jhor
    Commented Jun 28, 2023 at 8:50
0

With {NiceTabular} of nicematrix.

\documentclass[journal]{IEEEtran}
\usepackage{nicematrix,siunitx}

\begin{document}

\sisetup{table-format=4.0}

\label{tab:table_computational_time} 
\noindent\begin{NiceTabular}{c X[S] c}[hvlines,cell-space-limits=3pt]
  \RowStyle[nb-rows=2]{\bfseries}
  \Block{2-1}{wafer flow} & {\Block{1-2}{Computational time (seconds)}} \\
                          & {MIP II model} & MRT sequence  \\
  $[2]$  & 198 & 0.11 \\
  $[3]$  & 204 & 0.11 \\
  $[1,2]$  & 375 & 0.12\\
  $[1,3]$  & 367 & 0.13\\
  $[1,2,1]$  & 756 & 0.13\\
  $[1,2,2]$  & 861 & 0.14\\
  $[1,3,1]$  & 732 & 0.13\\
  $[1,2,1,1]$  & 1288 & 0.13\\
  $[1,3,1,1]$  & 1314 & 0.13\\
  $[1,2,1,2]$  & 1538 & 0.15\\
  $[1,2,2,1]$  & 1450 & 0.14\\
  $[1,2,2,2]$  & 1444 & 0.14\\
  $[1,3,2,1]$  & 1387 & 0.15\\
  $[1,2,1,1,1]$  & 2381 & 0.13\\
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

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