1

I get a weird error but I don't seem to do anything wrong.

Here is my code:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,fit}

\begin{document}

\begin{tikzpicture}[remember picture]
    \node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{\phantom{\frac{10}{20}}}$};
    \node[boxed,above left=2mm and 2mm of n7] (n1) {\phantom{10}};
    \node[boxed,above right=2mm and 2mm of n7] (n6) {\phantom{10}};
    \node[boxed,above=13mm of n7] (n10) {\phantom{10}};
    \draw[shrt] (n1) -- (n7);
    \draw[shrt] (n6) -- (n7);
    \draw[shrt] (n10.south east) -- (n6);
    \node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
    \draw[shrt] ([x-]n10.south west) -- ([x-]n1n9.north);
    \draw[shrt] ([x+]n10.south west) -- ([x+]n1n9.north);
\end{tikzpicture}
\end{document}

On the 9th line, ie.,

\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{\phantom{\frac{10}{20}}}$};

it says Missing $ inserted but I swear this is correct.

  • 3
    I see another problem: my pdflatex tells me, that \tikznode is an 'undefined control sequence'. – Jürgen Mar 10 '17 at 05:59
  • 1
    As Jurgen said, since in 1161 pages of TikZ & PGF Manual there's no trace of a command named \tikznode I suppose you have defined it in some way. If you don't post a COMPLETE minimal working example (MWE), we can't help you. – CarLaTeX Mar 10 '17 at 07:38
  • Note that nesting tikzpictures (e.g. a \tikz inside a \node), doesn't always work properly, so if you can avoid it, do that. See for example http://tex.stackexchange.com/questions/46598 and http://tex.stackexchange.com/questions/40192 – Torbjørn T. Mar 10 '17 at 08:52

1 Answers1

8

You have to use $ ... $ for \frac -> \phantom{$\frac{...}{...}$}}.

MWE compledted with your definitions here.

Modifications:

\node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{\phantom{$\frac{10}{20}$}}$};

MWE:

\documentclass{article}
\usepackage{mathtools}% not necessary here
\usepackage{tikz}

\usetikzlibrary{positioning,shapes,fit}
\newcommand\tikznode[3][]%
   {\tikz[baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }
\tikzset
   {boxed/.style={draw,minimum size=0pt,inner sep=1pt},
    shrt/.style={shorten >=1pt, shorten <=1pt},
    x-/.style={xshift=-0.5pt},
    x+/.style={xshift=0.5pt}
   }

\begin{document}
\begin{tikzpicture}[remember picture]
    \node{$\tikznode{n9}{9}+\tikznode{n7}{7}=\tikznode[boxed]{n16}{\phantom{$\frac{10}{20}$}}$};
    \node[boxed,above left=2mm and 2mm of n7] (n1) {\phantom{10}};
    \node[boxed,above right=2mm and 2mm of n7] (n6) {\phantom{10}};
    \node[boxed,above=13mm of n7] (n10) {\phantom{10}};
    \draw[shrt] (n1) -- (n7);
    \draw[shrt] (n6) -- (n7);
    \draw[shrt] (n10.south east) -- (n6);
    \node[ellipse,draw,fit=(n1) (n9),inner sep=1pt] (n1n9) {};
    \draw[shrt] ([x-]n10.south west) -- ([x-]n1n9.north);
    \draw[shrt] ([x+]n10.south west) -- ([x+]n1n9.north);
\end{tikzpicture}
\end{document}
Bobyandbob
  • 4,899