此 tikz 示例有错误

此 tikz 示例有错误

执行此示例时出现错误

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{center}
    \begin{tikzpicture}
    \draw (0,0) node[below] {$O$};
    \draw (0,0) -- (2,0) node[right] {$A$};
    \draw (0,0) -- (2,2) node[right] {$B$};
    \draw (1,0) arc (0:45:1);
    \draw (22:1.3) node { $ \dfrac{\pi}{4} $ }
    \end{tikzpicture}   
\end{center}

\end{document}

答案1

错误说\dfrac未定义。你需要\usepackage{amsmath}这个。然后你需要\draw用分号结束该语句,所以:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath} % <-- added
\begin{document}

\begin{center}
    \begin{tikzpicture}
    \draw (0,0) node[below] {$O$};
    \draw (0,0) -- (2,0) node[right] {$A$};
    \draw (0,0) -- (2,2) node[right] {$B$};
    \draw (1,0) arc (0:45:1);
    \draw (22:1.3) node { $ \dfrac{\pi}{4} $ }; % <-- added semicolon
    \end{tikzpicture}   
\end{center}

\end{document}

相关内容