tabularray - 如何使文本和图像居中

tabularray - 如何使文本和图像居中

我的目标是让所有文本和图像在单元格中水平和垂直居中。我应该提供哪些选项来tabularray实现此目的?

我已经接近了,但是垂直居中仍然不起作用:

                在此处输入图片描述

\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}

我并不坚持使用tabularray- 如果有更合适的包/宏,请告诉我。

答案1

您需要将图像基线移动到其垂直中心。例如,通过使用包adjustbox

\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}

在此处输入图片描述

答案2

这是使用 的一种可能性graphbox,它提供了align的选项\includegraphics。我还切换到了 的当前语法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}

桌子

相关内容