Tikz foreach リスト内の \ldots

Tikz foreach リスト内の \ldots

私は、cfrこの投稿でTikz を使用したパス図

私のコードは次のようになります:

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

問題はこの行にあります

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

コンパイルがエラーで失敗する原因:

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

その環境でドットを配置する解決策が見つからないためです。

基本的に、1、2、...、n までの「候補」の数があることを示したいと思います。しかし、そこに「候補...」を含めるにはどうすればよいでしょうか?

答え1

座標の名前を付ける際に、拡張不可能なトークンを使用することはできません。カウンター\ino(他の座標との混同を避けるために適切に装飾したもの) を使用できます。

書式も修正しました\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}

ここに画像の説明を入力してください

答え2

を使用した代替ソリューションを提案しますtikz matrix

よりすっきりしているように思えたので、\vdotsの代わりにを使用しました。Canditate...

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

ここに画像の説明を入力してください

PS = どうしても必要な場合は\mathrm{Candidate}\ldots、 を に置き換えてに\vdots追加してください。4,\foreach\foreach \i in {1,2,4,5}

関連情報