当开头和结尾都只有一个 $ 时,缺少 $ 插入

当开头和结尾都只有一个 $ 时,缺少 $ 插入

我收到了一个奇怪的错误,但我似乎没有做错什么。

这是我的代码:

\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}

在第 9 行,即

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

它说插入了缺少$但我发誓这是正确的。

答案1

您必须使用$ ... $for \frac-> \phantom{$\frac{...}{...}$}}

MWE 已完成您的定义这里

修改:

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

梅威瑟:

\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}

相关内容