15

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?

17

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.