我定义这个命令
\newcommand{\exercice}[3]{
{\bf Exercice #1.} {#2}
\bigskip{\textit{\underline{Solution}.}} #3
\begin{center}------------------------------------
\end{center}
}
然后我使用 tikz 库
\exercice
{6}
{The graph:
\begin{figure}[h]
\centering
\shorthandoff{<>} %To avoidinterference with Babel
\begin{tikzpicture}[scale=1,>=stealth,thick,estilo/.style={circle,draw,inner sep=0.5mm,fill=gray!50},theshift/.style={xshift=9cm,yshift=0cm}]
\node[estilo] (node1) at (0,0) {1};
\node[estilo] (node2) at (4,2) {2};
\node[estilo] (node3) at (4,-2) {3};
\node[estilo] (node4) at (8,0) {4};
\draw[->] (node1) node[left]{$[3]\ $} -- node[left]{$\ (0,3,5)\ $} (node2);
\draw[->] (node2) to [bend right=30] node[left]{$\ (0,1,2)\ $} (node3);
\draw[->] (node3) to [bend right=30] node[right]{$\ (0,1,2)\ $} (node2);
\draw[->] (node1) -- node[left]{$\ (1,3,2)\ $} (node3);
\draw[->] (node2) -- node[right]{$\ (1,2,-1)\ $} (node4) node[right]{$\ [-3]$};
\draw[->] (node3) -- node[right]{$\ (0,5,3)\ $} (node4);
\end{tikzpicture}
\shorthandon{<>} %To avoidinterference with Babel
\end{figure}
}
{
}
我得到了这个错误
“\language@active@arg> 的参数有一个额外的 }”
答案1
失败的原因与命令参数中不能逐字逐句的原因相同
\shorthandoff{<>} %To avoidinterference with Babel
会使其<>
不处于活动状态,但由于它们已被读取为命令的参数,因此标记已与活动字符相关,并且更改它为时已晚。
无关,但请注意
The graph:
\begin{figure}[h]
这figure
是一个浮动环境,因此可能会浮动到另一个页面,冒号后面不会留下任何内容。最好始终通过标题编号引用图片。