\ldots innerhalb der Tikz-Foreach-Liste

\ldots innerhalb der Tikz-Foreach-Liste

Ich habe eine Lösung modifiziert voncfrin diesem BeitragPfaddiagramm mit Tikz.

Mein Code sieht folgendermaßen aus:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,calc,positioning} 
\begin{document}
 \begin{tikzpicture}
     [
    rect/.style={draw, text centered},
     >={Stealth[]}
     ]
     \node (input) {Input};
     \node [rect, right=of input] (gen) {Generator};
     \node [above right=of gen] (C1) {$Candidate_1$};
     \node [below right=of gen] (Cn) {$Candidate_n$};
     \node [rect, below right=of C1] (eval) {Evaluator};
     \node [right=of eval] (output) {Optimal Output};
     \foreach \i [count=\ino] in {Candidate_2,Candidate\ldots}
     {
      \node at ($(C1)!\ino/3!(Cn)$) (\i) {$\i$};
      \draw [->] (gen) -- (\i);
      \draw [->] (\i) -- (eval);
      }
      \foreach \i/\j in {input/gen,gen/C1,gen/Cn,C1/eval,Cn/eval,eval/output} \draw [->] (\i) -- (\j);
    \end{tikzpicture}
\end{document}

Das Problem liegt in dieser Zeile

\foreach \i [count=\ino] in {Candidate_2,Candidate\ldots}

die dazu führen, dass die Kompilierung mit dem Fehler fehlschlägt:

! Missing \endcsname inserted.                      
<to be read again>        
                   \protect                         
l.20       }              

da ich keine Lösung finde, in dieser Umgebung Punkte zu haben.

Ich möchte grundsätzlich zeigen, dass es eine Anzahl von „Kandidaten“ von 1, 2, … bis n geben kann. Aber wie kann ich dort „Kandidat …“ unterbringen?

Antwort1

Sie können keine nicht erweiterbaren Token zum Benennen einer Koordinate verwenden. Sie können den Zähler verwenden \ino(entsprechend ausgestattet, um Verwechslungen mit anderen Koordinaten zu vermeiden).

Ich habe auch die Formatierung mit korrigiert \mathrm.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,positioning}

\begin{document}

\begin{tikzpicture}[
  rect/.style={draw, text centered},
  >={Stealth[]},
]
\node (input) {Input};
\node [rect, right=of input] (gen) {Generator};
\node [above right=of gen] (C1) {$\mathrm{Candidate}_1$};
\node [below right=of gen] (Cn) {$\mathrm{Candidate}_n$};
\node [rect, below right=of C1] (eval) {Evaluator};
\node [right=of eval] (output) {Optimal Output};
\foreach \i [count=\ino] in {\mathrm{Candidate}_2,\mathrm{Candidate}\ldots}
  {
   \node at ($(C1)!\ino/3!(Cn)$) (c\ino) {$\i$};
   \draw [->] (gen) -- (c\ino);
   \draw [->] (c\ino) -- (eval);
  }
\foreach \i/\j in {input/gen,gen/C1,gen/Cn,C1/eval,Cn/eval,eval/output} \draw [->] (\i) -- (\j);
\end{tikzpicture}

\end{document}

Bildbeschreibung hier eingeben

Antwort2

Ich schlage Ihnen eine alternative Lösung mit einem vor tikz matrix.

Ich habe \vdotsanstelle von verwendet Canditate..., weil es mir sauberer erscheint.

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,calc,positioning, matrix} 

\begin{document}

 \begin{tikzpicture}
     [
    rect/.style={draw, text centered},
     >={Stealth[]}
     ]
      \matrix[%
        matrix of nodes,
        nodes={inner sep=4pt},
        inner sep=0pt,
        column sep=30pt,
        row sep= 10pt,
        ] (C) {%
        & & $\mathrm{Candidate}_{1}$ \\ 
        & & $\mathrm{Candidate}_{2}$ \\[-15pt]
        Input & |[rect]| Generator & & |[rect]| Evaluator & Optimal Output \\[-15pt]
        & & $\vdots$ \\
        & & $\mathrm{Candidate}_{n}$ \\ 
      };
              \foreach \i  in {1,2,5}
      {%
      \draw [->] (C-3-2) -- (C-\i-3);
      \draw [->] (C-\i-3) -- (C-3-4);
      }
      \draw [->] (C-3-1) -- (C-3-2);
      \draw [->] (C-3-4) -- (C-3-5);         
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

PS = Wenn Sie es unbedingt möchten , \mathrm{Candidate}\ldotsersetzen Sie es einfach durch \vdotsund fügen Sie 4,es dem hinzu \foreach:.\foreach \i in {1,2,4,5}

verwandte Informationen