\ldots dentro da lista foreach do Tikz

\ldots dentro da lista foreach do Tikz

Modifiquei uma solução dada porcfrnesta postagemDiagrama de caminho usando Tikz.

Meu código fica assim:

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

O problema está nesta linha

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

que fazem a compilação falhar com erro:

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

pois não consigo encontrar uma solução para ter pontos nesse ambiente.

Basicamente quero mostrar que você pode ter um número de "Candidatos" de 1, 2, ..., até n. Mas como posso ter "Candidato..." aí?

Responder1

Você não pode usar tokens não expansíveis para nomear uma coordenada; você pode usar o contador \ino(devidamente adornado para evitar confusões com outras coordenadas).

Também corrigi a formatação com \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}

insira a descrição da imagem aqui

Responder2

Eu sugiro a você uma solução alternativa com um arquivo tikz matrix.

Usei \vdotsem vez de Canditate...porque me parece mais limpo.

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

insira a descrição da imagem aqui

PS = Se você realmente quiser \mathrm{Candidate}\ldots, basta substituí-lo \vdotse adicionar 4,ao \foreach: \foreach \i in {1,2,4,5}.

informação relacionada