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}

관련 정보