
Usando el siguiente código (de la respuesta aesta pregunta) para dibujar cuadros usando 2 bucles \foreach; y definir las posiciones iniciales de ambos (yshift=.4cm y yshift=4.4cm). Quiero que los cuadros azules comiencen automáticamente donde terminan los cuadros rojos.
¿Es posible combinarlos en un solo bucle?
Me refiero a usar un bucle \foreach para dibujar los 4 cuadros rojos inferiores y luego continuar con los 2 cuadros azules superiores.
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{frame}[t]
\frametitle{}
\newsavebox{\recAr}
\savebox{\recAr}{%
\begin{tikzpicture}[scale=.6]
\draw [thick, black, fill=red] (0,0) rectangle +(1,1.24);
\end{tikzpicture}}
\newsavebox{\recAb}
\savebox{\recAb}{%
\begin{tikzpicture}[scale=.6]
\draw [thick, black, fill=blue!60!white] (0,0) rectangle +(1,1.24);
\end{tikzpicture}}
\begin{tikzpicture}[scale=.8, transform shape]
\draw [line width=.4mm, black, dashed] (0,5.8) -- +(0:11) (0,0) -- +(0:11) node [pos=.68] (A) {};
\foreach \X in {0,1,2,3}
{\node[yshift=.4cm] (y-\X) at (A|-0,\X){\usebox{\recAr}};}
\foreach \X in {0,1}
{\node[yshift=4.4cm] (y-\X) at (A|-0,\X){\usebox{\recAb}};}
\end{tikzpicture}
\end{frame}
\end{document}
Respuesta1
Sólo con bucle parcial y basado enmi respuestala solución es sencilla:
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{chains,
positioning}
\begin{document}
\begin{frame}[t, fragile]
\frametitle{}
\begin{tikzpicture}[
node distance = 1mm and 55mm,
start chain = going below,
box/.style = {draw, thick, fill=#1,
minimum width=6mm, minimum height=12mm,
inner sep=0pt, outer sep=0mm,
on chain}
]
\node (n1) [box=blue] {};
\node (n2) [box=blue] {};
\node (n3) [below=1ex of n2, % when you need additional space, otherwide omit this option
box=red] {}; %
\foreach \i in {4,5,6}
\node (n\i) [box=red] {};
\coordinate[left=of n1.north] (a); % for shift node to the right
\draw [line width=.4mm, dashed]
(a) -- ++ (11,0)
(a |- n6.south) -- ++ (11,0);
\end{tikzpicture}
\end{frame}
\end{document}
Respuesta2
Se agregó Dunno's
una recomendación para crear la solución según los requisitos del OP.
Simplemente puedes repetir las variables:
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{positioning}
\begin{document}
\begin{frame}[t]
\frametitle{}
\newsavebox{\recAr}
\savebox{\recAr}{%
\begin{tikzpicture}[scale=.6]
\draw [thick, black, fill=red] (0,0) rectangle +(1,1.24);
\end{tikzpicture}}
\newsavebox{\recAb}
\savebox{\recAb}{%
\begin{tikzpicture}[scale=.6]
\draw [thick, black, fill=blue!60!white] (0,0) rectangle +(1,1.24);
\end{tikzpicture}}
\begin{tikzpicture}[scale=.8, transform shape]
\draw [line width=.4mm, black, dashed] (0,5.8) -- +(0:11) (0,0) -- +(0:11) coordinate[pos=.68,alias=y-6] (A) {}; \path foreach \X [remember=\X as \LastX (initially 6)] in {5,4,...,0}{ node[above=1.5mm of y-\LastX,outer sep=0pt,inner sep=0pt] (y-\X) {\ifnum \X>3 \usebox{\recAb} \else \usebox{\recAr} \fi}};
\end{tikzpicture}
\end{frame}
\end{document}
Llegar:
PD: Hice el código de tal manera que solo uno yshift
sea necesario, haciendo así yshift
común tanto el cuadro azul como el rojo.