1

Hi and many thanks in advance!

I'm trying to figure out why an empty macro definition takes up space within the label of a tikz node and prevents the intended alignment. (I cannot avoid an empty macro, since its definition is extracted out of a list, which can contain emtpy entries.) Please consider the following MWE, where the labels should be left-aligned on the vertical line:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[every node/.style={anchor=west, inner sep=0}]
    \draw[gray] (0,1) -- (0,-2);
    \def\a{One!}\def\b{And two!}
    \node at (0,0) {\fbox{\a}\fbox{\b}};
    \def\a{}\def\b{Only two!}
    \node at (0,-1) {\fbox{\a}\fbox{\b}};
\end{tikzpicture}
\end{document}

Pontis
  • 269

1 Answers1

4

\fbox has a border of \fboxsep. But you can test if you command is empty:

\documentclass{article}
\usepackage{tikz,etoolbox}

\begin{document}
\begin{tikzpicture}[every node/.style={anchor=west, inner sep=0}]
    \draw[gray] (0,1) -- (0,-2);
    \def\a{One!}\def\b{And two!}
    \node at (0,0) {\fbox{\a}\fbox{\b}};
    \def\a{}\def\b{Only two!}
    \node at (0,-1) {\ifdefempty{\a}{}{\fbox{\a}}\fbox{\b}};
\end{tikzpicture}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Thanks - I'm ashamed! I thought the MWE could reproduce the behaviour of my real problem (actually without \fbox), but I just realised that the Python script I generate the latex file with is buggy. – Pontis Dec 02 '19 at 23:06