1

I am playing with the code adapted from here.

\documentclass{article}
\usepackage{tikz}
\tikzset{
   nodeline/.style={midway, rotate=#1, minimum height=3.5mm, minimum       width=2.5mm}, 
 }

\newcommand\trigram[2]{%
\begin{scope}[rotate=#1]% around={#1:(0,0)}
\def\alenanno{w}  %if it is ying
\clip (-1.1,3) -- (1.1,3) -- (0,0) -- cycle;
\foreac \x [count=\xx starting from 0, evaluate=\xx as \y using (1.75+.5*\xx)] in #2{%
  \ifx\x\alenanno
  \draw[line width=3mm] (-1.2,\y) -- (1.2,\y) node[nodeline=#1,fill=white] {};
  \else
  \draw[line width=3mm] (-1.2,\y) -- (1.2,\y);
  \fi
}
\end{scope}
}

\begin{document}
   \begin{tikzpicture}
   \trigram{0}{b,w,w};
   \end{tikzpicture}
\end{document}

When I compile, I am getting following error without output. Can anybody help with this?

ERROR: Undefined control sequence.
--- TeX said ---
 \trigram ...-- (1.1,3) -- (0,0) -- cycle; \foreac 
                                              \x [count=\xx starting    fro...l.23   \trigram{0}{b,w,w}
                     ;
1
  • 3
    Welcome to TeX.SE! You have a typo in the code. It's \foreach, not \foreac. Commented Jan 24, 2019 at 20:18

1 Answer 1

5

You spelled \foreach wrong and you are missing a set of braces around #2.

\documentclass{article}
\usepackage{tikz}
\tikzset{
   nodeline/.style={midway, rotate=#1, minimum height=3.5mm, minimum       width=2.5mm}, 
 }

\newcommand\trigram[2]{%
\begin{scope}[rotate=#1]% around={#1:(0,0)}
\def\alenanno{w}  %if it is ying
\clip (-1.1,3) -- (1.1,3) -- (0,0) -- cycle;
\foreach \x [count=\xx starting from 0, evaluate=\xx as \y using (1.75+.5*\xx)] in {#2} {%
  \ifx\x\alenanno
  \draw[line width=3mm] (-1.2,\y) -- (1.2,\y) node[nodeline=#1,fill=white] {};
  \else
  \draw[line width=3mm] (-1.2,\y) -- (1.2,\y);
  \fi
}
\end{scope}
}

\begin{document}
   \begin{tikzpicture}
   \trigram{0}{b,w,w};
   \end{tikzpicture}
\end{document}

enter image description here

3
  • Thanks for the quick fix. I messed up the spelling for foreach. But the curly bracket was the devil!
    – Tony Tan
    Commented Jan 24, 2019 at 20:42
  • 1
    @TonyTan You can also leave out the braces around #2, but then you have to use \trigram{0}{{b,w,w}}; Commented Jan 24, 2019 at 20:56
  • @marmot Sorry but I no longer waste my time drawing other people's pictures. Commented Jan 24, 2019 at 22:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .