我定义了一个新命令,其中有 7 个参数。其中三个是“node”的一些选项。由于这些参数包括“node”的一些选项,我定义了另外两个由这些选项组成的新命令。但是当我想编译文件时,它无法编译!你能帮我纠正代码中的错误吗!这是我的代码:
\documentclass[border= 5 pt]{standalone}
\usepackage{times,comment}
\usepackage{tikz}
\usepgflibrary{arrows}
\usetikzlibrary{shapes.callouts}
\newcommand{\level}[7]{
\draw [purple] ( 3.1 , #2 ) -- ( 3.6 , #2 ) node[ #3 ]{ \tiny #2 };
\draw [black,densely dotted] ( 3.6 , #2 ) -- ( 3.9 , #4 );
\draw [black] ( 3.9 , #4 ) node [red, #5]{\tiny #1} -- ( 4.9 , #4 ) node[ #5 ]{ \tiny #4 };
\draw [black,densely dotted] ( 4.9 , #4 ) -- ( 5.2 , #6 );
\draw [blue] ( 5.2 , #6 ) -- ( 5.7 , #6 ) node[ #7]{\tiny #6 };
}
\newcommand{\ab}{above, midway, yshift=-3, xshift=6}
\newcommand{\be}{below, midway, yshift= 3, xshift=6}
\begin{document}
\begin{tikzpicture}
\level{$ 2 $}{2.176}{\ab}{2.541}{\ab}{2.176}{\ab}
\level{$ 3 $}{3.767}{\be}{3.808}{\be}{3.676}{\be}
\level{$ 4 $}{3.947}{\ab}{4.134}{\ab}{3.947}{\ab}
\level{$ 5 $}{5.804}{\be}{5.631}{\be}{5.804}{\be}
\level{$ 6 $}{6.047}{\ab}{5.879}{\ab}{6.048}{\ab}
\end{tikzpicture}
\end{document}
答案1
不确定这是否是预期的输出,但使用样式不会引发错误:
\documentclass[border= 5 pt]{standalone}
\usepackage{times,comment}
\usepackage{tikz}
\usepgflibrary{arrows}
\usetikzlibrary{shapes.callouts}
\newcommand{\level}[7]{
\draw [purple] ( 3.1 , #2 ) -- ( 3.6 , #2 ) node[ #3 ]{ \tiny #2 };
\draw [black,densely dotted] ( 3.6 , #2 ) -- ( 3.9 , #4 );
\draw [black] ( 3.9 , #4 ) node [red, #5]{\tiny #1} -- ( 4.9 , #4 ) node[ #5 ]{ \tiny #4 };
\draw [black,densely dotted] ( 4.9 , #4 ) -- ( 5.2 , #6 );
\draw [blue] ( 5.2 , #6 ) -- ( 5.7 , #6 ) node[ #7]{\tiny #6 };
}
\tikzset{
ab/.style={above, yshift=-3, xshift=6},
be/.style={below, yshift= 3, xshift=6},
}
\begin{document}
\begin{tikzpicture}
\level{$ 2 $}{2.176}{ab}{2.541}{ab}{2.176}{ab}
\level{$ 3 $}{3.767}{be}{3.808}{be}{3.676}{be}
\level{$ 4 $}{3.947}{ab}{4.134}{ab}{3.947}{ab}
\level{$ 5 $}{5.804}{be}{5.631}{be}{5.804}{be}
\level{$ 6 $}{6.047}{ab}{5.879}{ab}{6.048}{ab}
\end{tikzpicture}
\end{document}
答案2
我会用 Ti钾定义样式的 Zy 方式。
\documentclass[border= 5 pt]{standalone}
\usepackage{times,comment}
\usepackage{tikz}
\usepgflibrary{arrows}
\usetikzlibrary{shapes.callouts}
\newcommand{\level}[7]{
\draw [purple] ( 3.1 , #2 ) -- ( 3.6 , #2 ) node[ #3 ]{ \tiny #2 };
\draw [black,densely dotted] ( 3.6 , #2 ) -- ( 3.9 , #4 );
\draw [black] ( 3.9 , #4 ) node [red, #5]{\tiny #1} -- ( 4.9 , #4 ) node[ #5 ]{ \tiny #4 };
\draw [black,densely dotted] ( 4.9 , #4 ) -- ( 5.2 , #6 );
\draw [blue] ( 5.2 , #6 ) -- ( 5.7 , #6 ) node[ #7]{\tiny #6 };
}
\tikzset{ab/.style={above, midway, yshift=-3, xshift=6},
be/.style={below, midway, yshift= 3, xshift=6}}
\begin{document}
\begin{tikzpicture}
\level{$ 2 $}{2.176}{ab}{2.541}{ab}{2.176}{ab}
\level{$ 3 $}{3.767}{be}{3.808}{be}{3.676}{be}
\level{$ 4 $}{3.947}{ab}{4.134}{ab}{3.947}{ab}
\level{$ 5 $}{5.804}{be}{5.631}{be}{5.804}{be}
\level{$ 6 $}{6.047}{ab}{5.879}{ab}{6.048}{ab}
\end{tikzpicture}
\end{document}