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... 同じ名前の 3 番目のスタイルでこれを削除したところ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}

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

関連情報