Vertical Alignment – How to Align Cells Vertically in Tabularray

tabularrayvertical alignment

I've run into a problem that I can't seem to find a solution. I am using package tabularray, since I have some long tables. My table has a mix of figures and text, and I would like the left-most column to be aligned in the middle and center. However, I have tried using column{1} = {valign=m}, cell{2}{1} = {m} and also \SetRow{m}, and other options (renewcommand, using package adjustbox) to no avail.

Below is a simplified code and the output.

\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage{tabularray}
\NewColumnType{M}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{graphicx}

\begin{document}
\begin{longtblr}[
    caption = {My Table},
    ]{width=\textwidth,
        colspec = {| M{0.15\textwidth} | M{0.4\textwidth} | M{0.4\textwidth}|},
        rowhead = 1,
        row{even} = {gray9},
        row{1} = {white},
        cell{2}{1} = {m},
%       column{1} = {valign=m},
    }
    \hline
    \textbf{Column 1} & \textbf{Column 2} & \textbf{Column 3} \\ \hline
    
    This cell should be centered vertically
    & {\includegraphics[width=0.35\textwidth]{example-image} \\ Text that can contain multiple lines but maybe not}
    & {\includegraphics[width=0.35\textwidth]{example-image} \\ Text that can contain multiple lines but maybe not} \\ \hline
    
\end{longtblr}

More text here.
\end{document}

Output

Best Answer

Using tabularray package, you should use its syntax, which is quit different form syntax of " classic" table packages. For details see package documentation:

\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{graphicx}

\begin{document}
    \begin{longtblr}[
caption = {My Table},
  label ={tab:l??}]{hlines, vlines,
                    colspec = {X[0.4,c,m] X[h,j] X[h,j]},
                    rowhead = 1,
                    row{even} = {gray9},
                    row{1} = {font=\bfseries, bg=white},
                    }
Column 1    & Column 2  & Column 3                          \\
This cell should be centered vertically
    &   \includegraphics[width=\linewidth]{example-image}\par
        Text that can contain multiple lines but maybe not
    &   \includegraphics[width=\linewidth]{example-image}\par
        Text that can contain multiple lines but maybe not  \\
\end{longtblr}

More text here.
\end{document}

enter image description here

If you prefer that text below image is horizontally centered, that use the following colspec:

colspec = {X[0.4,c,m] X[h,c]| X[h,c]},

For mor vertical padding in rows, you can add to table preamble option rowsep=<desired amount>. Default value is 2pt. Similarly you can change column separation by colsep=<desired amount> (default is 6pt). For example, considering equal separation between columns and rows gives:

\documentclass{article}
\usepackage{array}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{graphicx}

\begin{document}
    \begin{longtblr}[
caption = {My Table},
  label ={tab:l??}]{hlines, vlines,
                    colspec = {X[0.4,c,m] X[h,j] X[h,j]},
                    rowhead = 1,
                    row{even} = {gray9},
                    row{1} = {font=\bfseries, bg=white},
                    %
                    colsep=4pt, rowsep=4pt,  % <-----
                    }
Column 1    & Column 2  & Column 3                          \\
This cell should be centered horizontaly and vertically
    &   \includegraphics[width=\linewidth]{example-image-duck}\par
        Text that can contain multiple lines but maybe not
    &   \includegraphics[width=\linewidth]{example-image-duck}\par
        Text that can contain multiple lines but maybe not  \\
\end{longtblr}

More text here.
\end{document}

enter image description here