1

I have a table with images and text and I want to align them to the centre of the cells they're in. Most questions like this one have answers which first fix the cell size and then centre its contents.

How can I do this without having to fix the dimensions of the cell and just align contents of every cell to its centre (I'm specifically referring to vertical alignment since horizontal alignment is taken care of by |c|c|...)

 \begin{table}[H]
    \centering
    \begin{tabular}{c|c|c|c|c}

    \hline \includegraphics[height=1in]{IMG1.jpg} & 1 & 2 & 2 kHz & 1 kHz \\

    \hline \includegraphics[height=1in]{IMG2.jpg} & 1 & 3 & 3 kHz & 1 kHz \\

    \hline \includegraphics[height=1in]{IMG3.jpg} & 2 & 5 & 5 kHz & 2 kHz \\

    \hline

\end{tabular}
\caption{random caption}

\end{table}

This is what the code for my table looks like. The only problem is, in every cell, the image is vertically aligned to the top and the text is vertically aligned to the bottom. How can I fix this?

TeXnician
  • 33,589
TEC0001
  • 13

1 Answers1

2

do you looking for something like this:

enter image description here

a complete small document (called mwe: minimal working example), is:

\documentclass[margin=3mm]{standalone}
\usepackage[export, demo]{adjustbox} % it also load "graphicx"
                                     % in real document delete option "demo"
\usepackage{siunitx}                 % added for used units

\begin{document}
\begin{tabular}{c|c|c|c|c}
\hline 
\includegraphics[height=1in, valign=c, margin=0pt 6pt 0pt 6pt]{IMG1.jpg} & 1 & 2 & \SI{2}{kHz} & \SI{1}{kHz} \\
\hline 
\includegraphics[height=1in, valign=c, margin=0pt 6pt 0pt 6pt]{IMG2.jpg} & 1 & 3 & \SI{3}{kHz} & \SI{1}{kHz} \\
\hline 
\includegraphics[height=1in, valign=c, margin=0pt 6pt 0pt 6pt]{IMG3.jpg} & 2 & 5 & \SI{5}{kHz} & \SI{2}{kHz} \\
\hline
\end{tabular}

\end{document}

table code as well necessary preamble should be simple to transfer in your real document.

Zarko
  • 296,517