0

I stumbled on a strange behavior with tikz. Here is a minimal example:

\documentclass[parskip]{scrartcl}
\usepackage{tikz}

\begin{document} \begin{tikzpicture} \node{ \tikz[remember picture] \coordinate (a); $1+2$ \tikz[remember picture]\coordinate (b); }; \begin{scope} \draw (a.south west) -- (b.south east); \end{scope} \end{tikzpicture} \end{document}

Each time I compile it with pdflatex the produced pdf has a different number of pages... It alternates between 1 and 3 pages.

The compilation always gives me the following warning:

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

The minimal example is an adaptation of the answer of Alain Matthes from this discussion. The behavior also happens with his code.

Is it normal? If not, can I fix it? I would like, as in the previous link, to make a brace under part of a mathematical expression and add text under the brace. The difference with the question asked at the link is that the size of the text under the brace should not impact the mathematical expression (that is why I considered the answer of Alain Matthes).

Zach
  • 653
  • 6
  • 10
  • 3
    You stick tikz macros inside one another. This is known to result in unpredictable behaviour, as far as I know. Why don't you just name your node and refer to its name directly? – Jasper Habicht Nov 29 '21 at 18:26
  • Ok thanks, that is where the bug comes from. – Zach Nov 29 '21 at 18:36

1 Answers1

2

Is this the desired result? (See Jasper Habicht's comment: Don't stack tikz environments.)

Code

\documentclass[parskip]{scrartcl}
\usepackage{tikz}

\begin{document} \begin{tikzpicture} \node (a) {$1+2$}; \draw (a.south west) -- (a.south east); \end{tikzpicture} \end{document}

Result

enter image description here

dexteritas
  • 9,161
  • 1
    Yes it underlines 1+2 thanks. Unfortunately, it does not solve my initial problem but I will ask another question for that ^^. – Zach Nov 29 '21 at 18:39
  • Here is the next one (in case you are interested...): https://tex.stackexchange.com/questions/624399/brace-under-an-expression-without-modifying-its-position – Zach Nov 29 '21 at 18:57