4

I have defined a new command in which there are 7 arguments. Three of them are some options for "node". Since these arguments include some options for "node", I have defined two other new commands consisting of those options. But when I want to compile the file, It does not compile! Could you please help me with correcting my mistakes in the code! Here is my code:

\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
    Use ,font=\tiny in the node options instead of \tiny #2 – percusse Jul 8 '18 at 15:38
3

Not sure it's the expected output, but using styles doesn't raise errors:

\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}

enter image description here

  • dear egreg, it does not work completely. But it was a smart suggestion. – HS8637 Jul 8 '18 at 16:53
0

I would use the TikZy way of defining the styles.

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.