I will replicate @xport's answer with my new LaTeX3 package tabularray
. It is much easier while the images are still exactly vertically centered using this method.
Specifically, the values m
or h
are passed to the valign=
key which centers the content, which can be found in section 2.5 Rows and Columns in the documentation.
\documentclass{article}
\usepackage[a4paper,vmargin=2cm,hmargin=1cm]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tabularray}
\setlength{\parindent}{0pt}
\newcommand{\dummy}{%
It is practically a big lie that \LaTeX\
makes you focus on the content without
bothering about the layout.%
}
\newcommand\xx{$\displaystyle\frac{a+b}{a-b}=0$}
\newcommand\yy{$\displaystyle\int_a^bf(x)\,\textrm{d}x=\frac{a-b}{a+b}$}
\newcommand\zz{\fcolorbox{cyan3}{yellow9}{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{\dummy}}}
\begin{document}
\noindent
\begin{tblr}{
colspec = {X[c,h]X[c]X[c]X[c]},
stretch = 0,
rowsep = 6pt,
hlines = {red5, 1pt},
vlines = {red5, 1pt},
}
\includegraphics[width=0.22\textwidth]{example-image-a} & \xx & \yy & \zz \\
\includegraphics[width=0.22\textwidth]{example-image-b} & \xx & \yy & \zz \\
\end{tblr}
\bigskip
\begin{tblr}{
colspec = {X[c,m]X[c,m]X[c,m]X[c,m]},
cell{1}{3} = {c=2}{c}, % multicolumn
cell{2}{1} = {c=2}{c}, % multicolumn
cell{3}{2} = {c=2}{c}, % multicolumn
cell{4}{1} = {c=4}{c}, % multicolumn
rowsep = 6pt,
hlines = {red5, 1pt},
vlines = {red5, 1pt}, % vlines can not pass through multicolumn cells
}
\yy & \yy & \yy & \\
\yy & & \yy & \yy \\
\yy & \yy & & \yy \\
\yy & & & \\
\end{tblr}
\end{document}

p{...}
aligns the content toward the top,m{...}
aligns the content toward the center, whileb{...}
aligns it toward the bottom.p
specifier is standard.