2

How can I make these numbers center aligned in the row?
Also please suggest if you see something better to imporve it.
(I also wonder if vertical lines look good or not or should I remove them)

EDIT: I'm sorry that I did not mention it clearly that the paper is two column format but the table is expanding on two columns combined instead of one column.

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
%\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{booktabs,capt-of}
\usepackage{newtxtext, newtxmath}
\usepackage{array}
\usepackage{parskip}
\usepackage{mathtools}

\begin{document}

 \begin{table*}[!t]
  \centering
  \caption{}
  \label{}
  \begin{tabular}{c|c|c|c}
                            \toprule
\textbf{No} &\textbf{C1}  &\textbf{C3}&\textbf{C4} \\\midrule
1    & \begin{minipage}[t]{0.3\textwidth}
  \includegraphics[width=\linewidth]{example-image-a}

  \label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
  \includegraphics[width=\linewidth]{example-image-b}

  \label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
  \includegraphics[width=\linewidth]{example-image-c}

  \label{fig:third}
\end{minipage}\\\midrule

2    & \begin{minipage}[t]{0.3\textwidth}
  \includegraphics[width=\linewidth]{example-image-a}

  \label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
  \includegraphics[width=\linewidth]{example-image-b}

  \label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
  \includegraphics[width=\linewidth]{example-image-c}

  \label{fig:third}
\end{minipage}\\\midrule
\end{tabular}

\end{table*} 

\end{document}
6
  • 1
    One possibility: change all image wrappers \begin{minipage}[t]{0.3\textwidth} to \begin{minipage}[c]{0.3\textwidth}. Jul 7, 2022 at 3:06
  • @muzimuzhiZ thanks, that wokrs. Do you have a solution for Overfull \hbox problem?
    – hana
    Jul 7, 2022 at 3:51
  • @hana - Yould replace \begin{tabular}{c|c|c|c} with \begin{tabular}{@{} cccc @{}}.
    – Mico
    Jul 7, 2022 at 3:58
  • 2
    If you want a table that spans multiple pages you'll have to use a longtable environment from the longtable package, or similar environment from a package with similar capabilities (e.g., longtblr from tabularray).
    – frabjous
    Jul 7, 2022 at 4:06
  • 2
    @hana — Overfull rows and pages are two separate matters. You had asked in a comment how to fix the overfull hbox issue, and my Comment addressed that question .
    – Mico
    Jul 7, 2022 at 4:58

3 Answers 3

5

You want to remove the [t], but there's a much simpler way to do it with adjustbox.

\documentclass[journal]{IEEEtran}
\usepackage{amsmath,amsfonts}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{array}
\usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
%\usepackage{textcomp}
\usepackage{stfloats}
\usepackage{url}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{cite}
\usepackage{booktabs,capt-of}
\usepackage{newtxtext, newtxmath}
\usepackage{array}
\usepackage{parskip}
\usepackage{mathtools}

\begin{document}


\begin{table*}
\centering
\caption{A caption}
\label{label}

% local settings for the particular table
\setlength{\tabcolsep}{0pt}% let TeX compute the horizontal space
\setlength{\aboverulesep}{\belowrulesep}
%%%

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}cccc}
\toprule
\textbf{No} &\textbf{C1}  &\textbf{C3}&\textbf{C4} \\\midrule
1
& \includegraphics[valign=c,width=0.3\textwidth]{example-image-a}
& \includegraphics[valign=c,width=0.3\textwidth]{example-image-b}
& \includegraphics[valign=c,width=0.3\textwidth]{example-image-c}
\\
%\addlinespace
\midrule
2
& \includegraphics[valign=c,width=0.3\textwidth]{example-image-a}
& \includegraphics[valign=c,width=0.3\textwidth]{example-image-b}
& \includegraphics[valign=c,width=0.3\textwidth]{example-image-c}
\\
\bottomrule
\end{tabular*}

\end{table*} 

\end{document}

Note that the \label command you have inside minipage do essentially nothing else than referring to the same caption. Better just a global one. Also the \hfill commands did nothing.

By the way, vertical rules in tables are evil.

enter image description here

1
  • graphbox introduces a similar valign option and is perhaps lighter than adjustbox. Jul 7, 2022 at 8:15
3

I sometimes use the following macro based on \raisebox{}[][]{}

\raisebox{-0.5\totalheight}[0.5\totalheight][0.5\totalheight]{<image>}

enter image description here

but it might need some adjustment for small images.

Explanation.

Each object in latex is within a box, an invisible container, including images. Each box has three properties: a baseline, height (vertical space above the baseline) and depth (vertical space below the baseline). AFAIK a baseline of an image is always set at its bottom. Since a baseline of texts is also set at the bottom, you will get this undesired effect.

In the macro above, \raisebox{v-len}[new height][new depth]{content} simply redefines a default box created by latex, hence the macro set a baseline of each image at its centre. If you look closely at the image, you will see a centre of each image is at the bottom of texts; this is where both baselines are. For very small images, the macro may need tuning. Also, [new height] and [new depth] do not have to add to 1\totalheight, larger factors will add extra vertical space as total height will be increased. For instance, the code below will centre images and adds little vertical space

\newcommand\RI[1]{\raisebox{-0.48\totalheight}[0.55\totalheight][0.52\totalheight]{#1}}

enter image description here

\documentclass[journal]{IEEEtran}
% \usepackage{amsmath,amsfonts}
% \usepackage{algorithmic}
% \usepackage{algorithm}
% \usepackage{array}
% \usepackage[caption=false,font=normalsize,labelfont=sf,textfont=sf]{subfig}
%\usepackage{textcomp}
% \usepackage{stfloats}
% \usepackage{url}
% \usepackage{verbatim}
\usepackage{graphicx}
% \usepackage{cite}
\usepackage{booktabs,capt-of}
% \usepackage{newtxtext, newtxmath}
% \usepackage{array}
% \usepackage{parskip}
% \usepackage{mathtools}

\newcommand\RI[1]{\raisebox{-0.5\totalheight}[0.5\totalheight][0.5\totalheight]{#1}}

\begin{document}

 \begin{table*}[!t]
  \centering
  \caption{}
  \label{}
  \begin{tabular}{c|c|c|c}
                            \toprule
\textbf{No} &\textbf{C1}  &\textbf{C3}&\textbf{C4} \\\midrule
1    & \begin{minipage}[t]{0.3\textwidth}
  \RI{\includegraphics[width=\linewidth]{example-image-a}}

  \label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
  \RI{\includegraphics[width=\linewidth]{example-image-b}}

  \label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
  \RI{\includegraphics[width=\linewidth]{example-image-c}}

  \label{fig:third}
\end{minipage}\\\midrule

2    & \begin{minipage}[t]{0.3\textwidth}
  \RI{\includegraphics[width=\linewidth]{example-image-a}}

  \label{fig:first}
\end{minipage}%
\hfill % maximize the horizontal separation
&\begin{minipage}[t]{0.3\textwidth}
  \RI{\includegraphics[width=\linewidth]{example-image-b}}

  \label{fig:second}
\end{minipage}%
\hfill
&\begin{minipage}[t]{0.3\textwidth}
  \RI{\includegraphics[width=\linewidth]{example-image-c}}

  \label{fig:third}
\end{minipage}\\\midrule
\end{tabular}

\end{table*} 

\end{document}
3

With tabularray (for X[c,m] columns) and adjustbox (for valign and \adjincludegraphics) packages the code is short and simple:

\documentclass[journal]{IEEEtran}
\usepackage{newtxtext, newtxmath}
\usepackage[export]{adjustbox}   % it load graphicx too
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table*}[!t]
\caption{Table with images}
\label{tab:image}
    \adjustboxset{width=\linewidth, valign=M}  
\begin{tblr}{hlines, vlines,
             colsep=3pt,
             colspec= {c *{3}{X[c,m]} },
             row{1} = {font=\bfseries},
             rowsep = 3pt,
             }
No  &   C1  &   C3  &   C4  \\  
1   & \adjincludegraphics{example-image-a}
            & \adjincludegraphics{example-image-b}
                    & \adjincludegraphics{example-image-c}  \\
2   & \adjincludegraphics{example-image-a}
            & \adjincludegraphics{example-image-b}
                    & \adjincludegraphics{example-image-c}
\end{tblr}
    \end{table*}
\end{document}
  • By valign is possible to move baseline of an image. With option M (or v) you can move their baseline to vertical center of image.
  • Columns X[c,m] horizontal (c option) and vertical (m option) centers theirs contents.
  • Using \adjincludegraphics instruction is possible set common option of image options: valign=M, and width=\linewidth. -Since by valign is moved images baselined to vertical center, now all cells contents in now is vertical centered.

enter image description here

You must log in to answer this question.

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