lmm_5000
lmm_5000

Reputation: 149

How to center my text vertically in a table environment?

I have a table with 3 columns where the first 2 columns are pictures and the 3rd is my comment on those pictures, but the comment "drowns", it is down at the bottom of the cell.

I have tried with m{2cm} instead of c:

\begin{tabularx}{\textwidth}{c c m{2cm}}

but no change.

enter image description here

\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
    \begin{tabularx}{\textwidth}{c c c}

     \textbf{O-Na} & \textbf{Na-Y} & \textbf{Comments} \\

     \includegraphics[width=0.3\linewidth]{pic1.png} & 
     \includegraphics[width=0.3\linewidth]{pic2.png} & 
     My comments. \\
    \end{tabularx}
\end{table}

My text is at the bottom of the cell.

Upvotes: 4

Views: 1935

Answers (1)

The graphbox provides the handy align=c option to vertically centre images:

\documentclass{article}

\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{graphbox} 
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

\begin{document}

\begin{table}
\caption{Caption if needed}
\label{tab:lastcheck}
    \begin{tabularx}{\textwidth}{XXX}
     \thead{O-Na} & \thead{Na-Y} & \thead{Comments} \\
     \includegraphics[width=\linewidth,align=c]{example-image-duck} & 
     \includegraphics[width=\linewidth,align=c]{example-image-duck} & 
     My comments. \\
    \end{tabularx}
\end{table}

\end{document}

enter image description here

Upvotes: 5

Related Questions