如何在節點外部的標籤中加入數學表達式?

如何在節點外部的標籤中加入數學表達式?

在節點內加入數學表達式作為標籤效果很好:

\begin{figure}
\begin{tikzpicture}[]
    \node[circle, draw] (c1) [label=left: text] {};
    \node[block, draw, right = of c1] (e1) {$1*1=1$};  
    \draw[->] (c1) -- (e1);
\end{tikzpicture}
\end{figure}

但是,如果我想將數學表達式放在節點旁邊(就像我對上面的“文字”標籤所做的那樣),它將無法編譯:

\begin{figure}
\begin{tikzpicture}[]
    \node[circle, draw] (c1) [label=left: text] {};
    \node[block, draw, right = of c1] (e1) [label=right: $1*1=1$] {};  
    \draw[->] (c1) -- (e1);
\end{tikzpicture}
\end{figure}

關於如何讓它發揮作用有什麼想法嗎?

答案1

將數學表達式包含進去{}來解決您的問題

解釋

作為@Zarko 在他的評論中解釋道問題不是數學表達式本身,而是符號=,因為這會導致tikz錯誤地解析您的選項。透過{}表達式周圍的附加層,=將會對 tikz 隱藏。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{figure}
\begin{tikzpicture}[]
    \node[circle, draw] (c1) [label=left: text] {};
    \node[draw, right = of c1] (e1) [label=right: {$1*1=1$}] {};  
    \draw[->] (c1) -- (e1);
\end{tikzpicture}
\end{figure}



\end{document}

相關內容