Tikz 新命令与 \draw 错误

Tikz 新命令与 \draw 错误

我在序言中写了以下内容newcommand,以内联文本的形式创建较小的网络图:

\usepackage{tikz}
\def\unit{0.05}
\def\uppernode{(.25,.33)}
\def\lowerrightnode{(.5,0)}
\newcommand{\opentri}{%
\begin{tikzpicture}%
  \draw[fill=black] (0,0) circle (\unit) \uppernode circle (\unit) \lowerrightnode circle (\unit);%
  \draw (0,0) -- \uppernode -- \lowerrightnode;%
\end{tikzpicture}}
\newcommand{\closedtri}{%
\begin{tikzpicture}%
  \draw [fill=black] (0,0) circle (\unit) \uppernode circle (\unit) \lowerrightnode circle (\unit);%
  \draw (0,0) -- \uppernode -- \lowerrightnode -- (0,0);%
\end{tikzpicture}}

但是,当我使用\closedtriand/or \opentri(在 Overleaf 中)时,行中出现undefined control sequence错误,并且日志中输出以下错误:

\closedtri ->\begin {tikzpicture}\draw 
                                       [fill=black] (0,0) circle (\unit ) \u...
l.326 ... metrics for closed triangle \closedtri.}
                                                  \vspace{1cm}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\closedtri ...owerrightnode circle (\unit );\draw 
                                                  (0,0) -- \uppernode -- \lo...
l.326 ... metrics for closed triangle \closedtri.}
                                                  \vspace{1cm}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

知道这是什么原因造成的吗?

这是完整文件(不包含任何错误的文本部分)。错误出现在图片的标题中:

\documentclass{article}

% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]{babel}
% Set page size and margins
% Replace `letterpaper' with `a4paper' for UK/EU standard size
\usepackage[%
    letterpaper,%
    top=2cm,%
    bottom=2cm,%
    left=3cm,%
    right=3cm,%
    marginparwidth=1.75cm%
]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{authblk}

\usepackage{tikz}
\def\unit{0.05}
\def\uppernode{(.25,.33)}
\def\lowerrightnode{(.5,0)}
\newcommand{\opentri}{%
\begin{tikzpicture}%
  \draw[fill=black] (0,0) circle (\unit) \uppernode circle (\unit) \lowerrightnode circle (\unit);%
  \draw (0,0) -- \uppernode -- \lowerrightnode;%
\end{tikzpicture}}
\newcommand{\closedtri}{%
\begin{tikzpicture}%
  \draw [fill=black] (0,0) circle (\unit) \uppernode circle (\unit) \lowerrightnode circle (\unit);%
  \draw (0,0) -- \uppernode -- \lowerrightnode -- (0,0);%
\end{tikzpicture}}


\title{Title}
\author[1]{Pablo Lozano}
\date{}

\begin{document}
\maketitle

\section{Figures}

In Figures~\ref{fig:three-baseline-diffInit-diffLr-complete} and \ref{fig:three-baseline-diffInit-diffLr-path} we observe that...
\begin{figure}[htbp]
\centering
\includegraphics[width=1.\textwidth]{figures/three/base/data_base_replace_diffInit_diffLr_usingRandom_usingGoodDistr_complete/metrics_evo_60_avg.png}
\caption{\label{fig:three-baseline-diffInit-diffLr-complete}Baseline model metrics for closed triangle \closedtri.}\vspace{1cm}
\includegraphics[width=1.\textwidth]{figures/three/base/data_base_replace_diffInit_diffLr_usingRandom_usingGoodDistr_path/metrics_evo_60_avg.png}
\caption{\label{fig:three-baseline-diffInit-diffLr-path}Baseline model metrics for open triangle \opentri.}
\end{figure}

相关内容