2개의 다른 위치에 2개의 \foreach 루프 배치

2개의 다른 위치에 2개의 \foreach 루프 배치

답변에서 다음 코드를 사용하여이 질문

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning, chains}
\begin{document}
\begin{frame}[fragile, t]
\frametitle{}
\begin{tikzpicture}[scale=.8, transform shape,
node distance = 1mm and 60mm,
  start chain = going below,
   boxa/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=7.1mm,
             inner sep=0pt, outer sep=0.96mm,
             on chain},
   boxb/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=7.1mm,
             inner sep=0pt, outer sep=0.96mm,
             on chain},
   boxc/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=12.7mm,
             inner sep=0pt, outer sep=0.6mm,
             on chain},
]
\draw [line width=.4mm, black, dashed] (0,5.8) -- +(0:11) (0,0) -- +(0:11) node [pos=.28] (B) {\Large B} node [pos=.68] (A) {\Large A};

\node at ([shift={(90:5.4cm)}]A.center) (n1) [boxa=blue!60!white] {};
\node (n2) [boxa=blue!60!white] {};
\foreach \i in {3,...,6}
\node (n\i) [boxb=red!60!white] {};
\foreach \i in {0,...,3}
\node at ([shift={(90:5.4cm)}]B.center) (n\i) [boxc=green!60!white] {};
\end{tikzpicture}
\vskip -9.45cm
\hskip 2.22cm
\begin{tikzpicture}[scale=.8, transform shape,
node distance = 1mm and 60mm,
  start chain = going below,
   boxc/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=12.7mm,
             inner sep=0pt, outer sep=0.6mm,
             on chain},
]
\foreach \i in {0,...,3}
\node (n\i) [boxc=violet!60!white] {};
\end{tikzpicture}
\end{frame}
\end{document}

B 노드 위치에 녹색 상자를 배치하고 싶습니다. 나는 코드를 사용했다

    \foreach \i in {0,...,3}
\node at ([shift={(90:5.4cm)}]B.center) (n\i) [boxc=green!60!white] {};

그러나 이것은 작동하지 않았습니다. 어떻게 할 수 있습니까?

나는 그것들을 올바르게 배치하는 방법을 알 수 없었습니다. 다른 tikzpicture의 보라색 상자에 대해 했던 것처럼 수동으로 수행해야 했습니다.

여기에 이미지 설명을 입력하세요

답변1

나는 방금 당신의 문제를 깨달았습니다 ... 당신의 문제는 당신이 옵션으로 이 스타일을 정의했다는 것입니다 on chain... 이름이 지정된 세 번째 동일한 스타일에서 그것을 제거했으며 boxd결과는 다음과 같습니다.

\documentclass{article}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{positioning, chains}
\begin{document}
\begin{tikzpicture}[scale=.8, transform shape,
node distance = 1mm and 60mm,
  start chain = going below,
   boxa/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=7.1mm,
             inner sep=0pt, outer sep=0.96mm,
             on chain},
   boxb/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=7.1mm,
             inner sep=0pt, outer sep=0.96mm,
             on chain},
   boxc/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=12.7mm,
             inner sep=0pt, outer sep=0.6mm,
             on chain},
   boxd/.style = {draw, thick, fill=#1,
             minimum width=6mm, minimum height=12.7mm,
             inner sep=0pt, outer sep=0.6mm},
]
\draw [line width=.4mm, black, dashed] (0,5.8) -- +(0:11) (0,0) -- +(0:11) node [pos=.28] (B) {\Large B} node [pos=.68] (A) {\Large A};

\node at ([shift={(90:5.4cm)}]A.center) (n1) [boxa=blue!60!white] {};
\node (n2) [boxa=blue!60!white] {};
\foreach \i in {3,...,6}
\node (n\i) [boxb=red!60!white] {};
\foreach \i in {0,...,3}
\node at ([shift={(90:5.4cm)}]B.center) (n\i) [boxc=green!60!white] {};
\foreach \i in {0,...,3}
\node (l\i)at ($(0,-0.75)+({0.28*11},{-\i*1.5})$)  [boxd=green!60!white] {};
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보