1

I would like to create a table in www.overleaf.com with compiler pdfLaTeX TeX Live version 2022.

Here is the code.

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

\begin{table}[h] \captionof{table}{Table of $q$ and $z$} \label{tab:table_q_and_z} \noindent \begin{tabularx}{\columnwidth} { | c | c | >{\raggedright\arraybackslash}X |} \hline \textbf{Steps} & \textbf{$q_i$} & \textbf{Definition of $z_i$} \ \hline \multirow{$i \leq (n-1)$} & $q_i$ = 0 & $z_i$ = number of \emph{emptied} chambers at the \emph{cleaning} place $i \leq (n-1)$ \ \cline{2-3} & \centering $q_i$ = 1 & $z_i$ = number of \emph{loaded} chambers at the \emph{processing} place $i \leq (n-1)$ \ \hline $i=n$ & $q_{n}$ = 0 & $z_n$ = number of \emph{loaded} chambers at the \emph{processing} place $n$ \ \cline{2-3} & $q_{n}$ = 1 & $z_{n}$ = number of \emph{emptied} chambers at the \emph{cleaning} place $n$ \ \hline \end{tabularx} \end{table}

\end{document}

There is an error : "Undefined Control Sequence" as follows.

error

However the table printed well as follows.

result

Can anyone tell me what needs to be revised on the code, please?

Thank you.

2 Answers2

3

There are several problems.

First, the macro \captionof is defined in the caption package, but this package isn't loaded in the preamble. Since the caption package isn't fully compatible with the IEEEtran document class, you are probably doing well not loading it. The remedy? Just, replace

\captionof{table}{Table of $q$ and $z$}

with

\caption{Table of $q$ and $z$}

Second, you aren't loading the tabularx and multirow packages, which define the tabularx environment and \multirow macro, respectively, which also occur in your test document.

Third, you're not using \multirow correctly. It takes 3 arguments, not one.

Fixing these issues and performing some more cleanup -- such as deleting a stray \centering directive, deleting the unnecessary \noindent directive, and changing \textbf{$q_i$} to $\bm{q}_i$ in the header row -- results in the following output.

Finally, not an error per se, but a reasonably salient stylistic issue: The IEEEtran document class employs Times Roman as the main text font family, but uses Computer Modern as the main math font family. Times Roman and Computer Modern don't mesh particularly well, aesthetically speaking. You may want to consider running

\usepackage{newtxtext,newtxmath}

in the preamble to employ mutually compatible Times Roman text and math font families.

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{tabularx,multirow,bm}
\renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document}

\begin{table}[h] \caption{Table of $q$ and $z$} \label{tab:table_q_and_z} % \noindent % <-- has no effect \begin{tabularx}{\columnwidth} { | c | c | >{\raggedright\arraybackslash}X |} \hline \textbf{Steps} & $\bm{q}i$ & \textbf{Definition of $\bm{z}_i$} \ \hline \multirow{3}{}{$i \leq (n-1)$}
& $q_i$ = 0 & $z_i$ = number of \emph{emptied} chambers at the \emph{cleaning} place $i \leq (n-1)$ \ \cline{2-3} & $q_i$ = 1 & $z_i$ = number of \emph{loaded} chambers at the \emph{processing} place $i \leq (n-1)$ \ \hline \multirow{3}{
}{$i=n$}
& $q
{n}$ = 0 & $z_n$ = number of \emph{loaded} chambers at the \emph{processing} place $n$ \ \cline{2-3} & $q_{n}$ = 1 & $z_{n}$ = number of \emph{emptied} chambers at the \emph{cleaning} place $n$ \ \hline \end{tabularx} \end{table}

\end{document}

Mico
  • 506,678
2

With tabularray package the table code is simple and short:

\documentclass[journal]{IEEEtran}
\usepackage{tabularray}
\usepackage{bm}

\begin{document} \begin{table}[ht] \caption{Table of $q$ and $z$} \label{tab:table_q_and_z} \begin{tblr}{hlines, vlines, colspec = { *{2}{Q[c, mode=math]} X[j, m, cmd=\hangindent 1.5em\hangafter 1]}, cell{even[2]}{1} = {r=2}{}, row{1} = {font=\bfseries, mode=text} } Step & $\bm{q}i$ & Definition of $\bm{z}_i$ \ i \leq (n-1) & q_i = 0 & $z_i$: number of \emph{emptied} chambers at the \emph{cleaning} place $i \leq (n-1)$ \ & q_i = 1 & $z_i$: number of \emph{loaded} chambers at the \emph{processing} place $i \leq (n-1)$ \ i=n & q{n} = 0 & $z_n$: number of \emph{loaded} chambers at the \emph{processing} place $n$ \ & q_{n} = 1 & $z_n$: number of \emph{emptied} chambers at the \emph{cleaning} place $n$ \ \end{tblr} \end{table} \end{document}

enter image description here

or without option cmd=\hangindent 1.5em\hangafter 1 in the third column specifications:

enter image description here

Zarko
  • 296,517