Closed lastras closed 5 months ago
Try either \begin{tikzpicture}[baseline=(current bounding box.center)]
or my experimental implementation of valign=M
in https://github.com/lvjr/tabularray/issues/434#issuecomment-1686957209.
By default a tikzpicture
has its baseline at the height of y = 0pt
, see https://tikz.dev/tikz-scopes#pgf./tikz/baseline and https://github.com/lvjr/tabularray/discussions/481.
\begin{tikzpicture}[baseline=(current bounding box.center)]
worked. Thank you!!!
Depending on the content of tikzpicture
, you may also need some negative y-shifting, to make tikzpicture
and text cells centered vertically and visually.
\documentclass{article}
\usepackage{tikz}
\usepackage{tabularray}
\begin{document}
\newcommand{\tikzcell}{%
\begin{tikzpicture}
\draw (0,0) rectangle (3,3);
\draw (0,0) -- (3,3) (0,3) -- (3,0) (0,1.5) -- (3,1.5);
\end{tikzpicture}%
}
\begin{tblr}{colspec={|Q[c]|Q[c]|Q[c]|},rowspec={|Q[m]|Q[m]|Q[m]|}}
{Alpha \\ Alpha} & Beta & Gamma \\
Delta & \tikzcell & {Zeta \\ Zeta} \\
Eta & {Theta \\ Theta} & abc \\
\end{tblr}
Before
\begin{tblr}{
colspec={|Q[c]|Q[c]|Q[c]|},
rowspec={|Q[m]|Q[m]|Q[m]|},
cell{2}{2}={preto=
\tikzset{every picture/.style=
{baseline=(current bounding box.center)}}}
}
{Alpha \\ Alpha} & Beta & Gamma \\
Delta & \tikzcell & {Zeta \\ Zeta} \\
Eta & {Theta \\ Theta} & abc \\
\end{tblr}
Setting \verb|\begin{tikzpicture}[basline={(...)}]|
\begin{tblr}{
colspec={|Q[c]|Q[c]|Q[c]|},
rowspec={|Q[m]|Q[m]|Q[m]|},
cell{2}{2}={preto=
\tikzset{every picture/.style=
{baseline={([yshift=-.75ex]current bounding box.center)}}}}
}
{Alpha \\ Alpha} & Beta & Gamma \\
Delta & \tikzcell & {Zeta \\ Zeta} \\
Eta & {Theta \\ Theta} & abc \\
\end{tblr}
Setting \verb|\begin{tikzpicture}[basline={([yshift=]...)}]|
\end{document}
I am having difficulties centering a tikzpicture vertically. Here's an example where it doesn't seem to work, yet when I add a ```\\''' it works (except that now I added space I didn't want).
Environment: Overleaf, pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex 2022.8.9)