# Robust command for tikz yshift

I created a robust command declared in preamble to include a small figure in the text.

\DeclareRobustCommand\mytikzcell{\tikz  \tikzset{b2block/.style = {rectangle split, rectangle split parts=1,
draw, rectangle split horizontal=false,inner ysep=0pt, yshift=-1cm, line width=0.05em, text width=4em, align=center, rectangle split part fill={blue!30}}} \vspace{4em} \node[b2block] {
\nodepart{one} {\mystrutcopy \tiny  $\langle 1, [\tikz\draw[magenta,fill=magenta] circle (.5ex); \tikz\draw[olive,fill=olive] circle (.5ex);], \bot \rangle$ \enskip {$3$}}};}


This works as I expect and I can use it in my text by calling \mytikzcell.

However, the cell is not aligned with the text. There is some space at the bottom of the figure and I want to make sure that the figure bottom is in line with the bottom the the text. How can I do that? I tried to use yshift and \vspace but it doesn't seem to work.

• Welcome! Are you looking for the baseline option? – user121799 Dec 19 '18 at 21:42

Welcome to TeX.SE! Your code is nesting tikzpictures, which should be strictly avoided. yshift has no effect in your setting, and you may be looking for baseline. Also you should post a complete code that starts with \documentclass and ends with \end{document}, like this here.

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\newsavebox{\bullone}
\newsavebox{\bulltwo}
\sbox\bullone{\tikz{\draw[magenta,fill=magenta] circle (.5ex);}}
\sbox\bulltwo{\tikz{\draw[olive,fill=olive] circle (.5ex);}}
\tikzset{b2block/.style = {rectangle split, rectangle split parts=1,
draw, rectangle split horizontal=false,inner ysep=0pt,  line width=0.05em, text width=5em, align=center, rectangle split part fill={blue!30}}}
\DeclareRobustCommand\mytikzcell{\tikz[baseline=(tmp.base)]
{ \node[b2block] (tmp) {
\nodepart{one} {\strut \tiny  $\langle 1, [\usebox\bullone \usebox\bulltwo ], \bot \rangle$ \enskip
{$3$}}};}}
\begin{document}
(as shown here and there \mytikzcell )
\end{document}


My crystal ball got stolen, so I have no clue what \mystrutcopy is.

You can play with the baseline also to adjust the, well, base lines of the circles, and to align the box with the bottom of the text.

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\newsavebox{\bullone}
\newsavebox{\bulltwo}
\sbox\bullone{\tikz[baseline=-1pt]{\draw[magenta,fill=magenta] circle (.5ex);}}
\sbox\bulltwo{\tikz[baseline=-1pt]{\draw[olive,fill=olive] circle (.5ex);}}
\tikzset{b2block/.style = {rectangle split, rectangle split parts=1,
draw, rectangle split horizontal=false,inner ysep=0pt,  line width=0.05em, text width=5em, align=center, rectangle split part fill={blue!30}}}
\DeclareRobustCommand\mytikzcell{\tikz[baseline=(tmp.south)]
{ \node[b2block] (tmp) {
\nodepart{one} {\strut \tiny  $\langle 1, [\usebox\bullone \usebox\bulltwo ], \bot \rangle$ \enskip
{$3$}}};}}
\begin{document}
(as shown here and there \mytikzcell )
\end{document}


• This is extremely close to what I want! Is there way that the bottom of the box is aligned with bottom of the other words? I'll be careful to post a minimal complete example from now on :-) – karmanaut Dec 19 '18 at 22:04
• @karmanaut Yes, use baseline=(tmp.south) instead of baseline=(tmp.base). – user121799 Dec 19 '18 at 22:09
• OMG! This is terrific! I can get the alignment! Thank you! – karmanaut Dec 19 '18 at 22:21