25

I was trying to use an equal sign within a TikZ picture as a subcaption of an inner TikZ picture for comparing two images.

Here is my code:

\documentclass{report}

\usepackage{amsmath} 
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{positioning}

\begin{document}

    \begin{tikzpicture}
        \coordinate (p1) at (0,0);
        \coordinate (p2) at (-3,0);

        \node[label=below:$\mathcal{L}(B)$] (left) 
        {
            \begin{tikzpicture}[framed,scale=0.56]
                \draw (p1) -- (p2);
            \end{tikzpicture}   
        };
        \node[label=below:$\mathcal{L}^*(B)\text{$=$}\mathcal{L}(D)$,right=of left]
        {
            \begin{tikzpicture}[framed,scale=0.56]
                \draw (p2) -- (p1);
            \end{tikzpicture}
        };
    \end{tikzpicture}

\end{document}

My workaround was to use \text{$=$}. A plain equal sign instead of this will produce and error. I think TikZ recognizes this equal sign a separator of a key-value-pair of an attribute. Is there a right way to produce a plain equal-sign without this workaround?

3

2 Answers 2

28

As already pointed out by Jake, the = is detected by TikZ that parses the options based on , and =.

This works:

\node[label=below:{$\mathcal{L}^*(B)=\mathcal{L}(D)$}]

As well as that:

\node[label={below:$\mathcal{L}^*(B)=\mathcal{L}(D)$}]

If you want to include a : in the label but do not specify a direction (here: below), then you will need to protect the colon, too:

\tikzset{label position=below}
\node[label=here's{:} a colon]

The same bracing is needed if you use , (in a label and elsewhere), for example:

\tikzset{nodes={draw, fill, font=\tiny}}

Defining a macro \equal as

\newcommand*{\equal}{=}

hides the = from the parser, too, but may not be the favorite way to input formulas.

\node[label=below:$\mathcal{L}^*(B)\equal\mathcal{L}(D)$]

At least the spacing is correct as opposed to that work-around of \text{$=$} where the braces { } from \text hides = from the parser as well. Note that $L{=}L$ still produces wrong spacing and isn’t an option here.

-1

this works nicely in my case

\documentclass {standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
     for tree={l+=1cm} % increase level distance
        [ $X_n  \mapsto {\lim_{n=\infty} X_n=X^*} $
        [left[lleft $a+b$ ][lright]]
        [right[rleft][rright]]
      ]
 \end{forest}
\end{document}

The trick is to apply {} barackets.

1
  • The question already has this answer. -I do not see that your code is relevant for the problem other than { and }. Jan 2, 2021 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .