Jakov
Jakov

Reputation: 61

Vertical and horizontal cell centering in LaTex table

I am making a LaTex table and have trouble centering text (and images) inside cells themselves. The table as a whole is centered on the page, but what I want is that text and images in every cell are centered both vertically and horizontally.

This is my code

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}

\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
\rowcolor[HTML]{C0C0C0} 
\textbf{Particle}             & \textbf{Orientation} & \textbf{Symbol} & \textbf{Letter}    \\[4ex] \hline
                              & in                &         {\includegraphics[scale=0.8]{im/inel.jpg}}           & $u$                \\[2ex] \cline{2-4} 
\multirow{-2}{*}{fermion}     & out               &         {\includegraphics[scale=0.8]{im/outel.jpg}}          & $\overline{u}$      \\[2ex] \hline
                              & in                &         {\includegraphics[scale=0.8]{im/inpoz.jpg}}          & $\overline{v}$      \\[2ex] \cline{2-4} 
\multirow{-2}{*}{antifermion} & out               &         {\includegraphics[scale=0.8]{im/outpoz.jpg}}         & $v$                \\[2ex] \hline
                              & in                &         {\includegraphics[scale=0.8]{im/inph.jpg}}           & $\epsilon_\mu$     \\[2ex] \cline{2-4} 
\multirow{-2}{*}{foton}       & out               &         {\includegraphics[scale=0.8]{im/outph.jpg}}          & $\epsilon_{\mu}^*$ \\[2ex] \hline
\end{tabular}
\end{table}
\end{document}

This is what my code gives me (also notice how some lines are obscured by the images - that is not how I wanted it):

enter image description here

And, this is what I want:

enter image description here

Any help is welcome! Thank you

Upvotes: 3

Views: 4852

Answers (1)

You are already loading the tabularray package, just use it instead of a tabular:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\begin{document}
\begin{table}[H]
\centering
\begin{tblr}{
  cells={valign=m,halign=c},
  row{1}={bg=lightgray,font=\bfseries,rowsep=8pt},
  colspec={QQQQ},
  hlines,
  vlines
}
Particle & Orientation & Symbol & Letter\\
\SetCell[r=2]{} fermion& in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $u$ \\ 
                       & out & \includegraphics[scale=0.5,valign=c]{example-image-duck}& $\overline{u}$ \\ 
\SetCell[r=2]{} antifermion & in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\overline{v}$ \\ 
                       & out & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $v$ \\ 
\SetCell[r=2]{} photon & in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\epsilon_\mu$ \\ 
                       & out & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\epsilon_{\mu}^*$ \\ 
\end{tblr}
\end{table}
\end{document}

enter image description here

Upvotes: 4

Related Questions