6

My goal is to have all text and images centered horizontally and vertically in their cells. Which options should I give to tabularray to achieve this?

I am getting close, but the vertical centering is still not working:

                enter image description here

\documentclass[10pt,a4paper]{scrreprt} 
\usepackage{fullpage}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\usepackage{tabularray}

\begin{document}

\begin{table}[h!]
    \centering
    \begin{tblr}{ | Q[c,3.5cm] | Q[c,3.5cm] | Q[c,3.5cm] | Q[c,3.5cm] | }
    \hline
    \SetCell[c=2]{} Heading 1 & & \SetCell[c=2]{} Heading 2 & \\
    \hline

    Lorem Ipsum & \includegraphics[height=1.6cm]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm]{example-image} \\ 
    \hline 
    Lorem Ipsum & \includegraphics[height=1.6cm]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm]{example-image} \\ 
    \hline
    Lorem Ipsum & \includegraphics[height=1.6cm]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm]{example-image} \\ 
    \hline 
    \end{tblr}
\end{table}

\end{document}

I do not insist on using tabularray - if there is a more adquate package/macro, please let me know.

2 Answers 2

8

You need to move image baseline to its vertical center. For example by use of the adjustbox package:

\documentclass[10pt,a4paper]{scrreprt}
\usepackage{fullpage}

\usepackage[export]{adjustbox}
\usepackage{tabularray}

\begin{document}

\begin{table}[h!]
    \centering
    \begin{tblr}{ | Q[c,3.5cm] | Q[c,3.5cm] | Q[c,3.5cm] | Q[c,3.5cm] | }
    \hline
    \SetCell[c=2]{} Heading 1 & & \SetCell[c=2]{} Heading 2 & \\
    \hline

    Lorem Ipsum & \includegraphics[height=1.6cm, valign=c]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm, valign=c]{example-image} \\
    \hline
    Lorem Ipsum & \includegraphics[height=1.6cm, valign=c]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm, valign=c]{example-image} \\
    \hline
    Lorem Ipsum & \includegraphics[height=1.6cm, valign=c]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm, valign=c]{example-image} \\
    \hline
    \end{tblr}
\end{table}

\end{document}

enter image description here

6

Here's one possibility using graphbox, which provides the align option to \includegraphics. I also switched to the current syntax of tabularray.

\documentclass[10pt,a4paper]{article} 
\usepackage{graphicx}
\usepackage{graphbox}
\usepackage{tabularray}

\begin{document}

\begin{table}[h!]
    \centering
    \begin{tblr}{
        colspec={Q[c,3.5cm]Q[c,3.5cm]Q[c,3.5cm]Q[c,3.5cm]},
        vlines,
        hlines,
        cell{1}{1,3}={c=2}{c},
    }
    Heading 1 & & Heading 2 & \\
    Lorem Ipsum & \includegraphics[height=1.6cm, align=m]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm, align=m]{example-image} \\ 
    Lorem Ipsum & \includegraphics[height=1.6cm, align=m]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm, align=m]{example-image} \\ 
    Lorem Ipsum & \includegraphics[height=1.6cm, align=m]{example-image} & Lorem Ipsum & \includegraphics[height=1.6cm, align=m]{example-image} \\ 
    \end{tblr}
\end{table}

\end{document}

table

1
  • 2
    Minor nitpick: align=m seems to place the text slightly above the horizontal centerline. Changing to align=c looks better, IMO. Commented Feb 3, 2023 at 5:16

You must log in to answer this question.

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