Tikz flowchart overlapping

I am very new to Latex and am trying to create a flowchart. The two nodes of D1 are overlapping completely. The diagrams defined with custom commands are tikz pictures themselves. Another problem I am having is that the labels for the images I want to be on top, but no matter what I try, I can't manage to do it.

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\definecolor{cffffff}{RGB}{255,255,255}
\definecolor{cff6600}{RGB}{255,102,0}
\definecolor{cff8080}{RGB}{255,128,128}

\newcommand{\diagramA}{\begin{tikzpicture}
\begin{scope}[shift={(86.24562,-1.70874)}]
\path[fill=cffffff,fill opacity=0.996,rounded corners=0.0000cm]
(19.1071,13.4336) rectangle (83.1071,77.4336);
\path[draw=black,line join=miter,line cap=butt,fill opacity=0.750,even odd
rule,line width=0.100pt] (19.1071,13.4336) --
(19.1071,77.4336)(27.1071,13.4336) -- (27.1071,77.4336)(35.1071,13.4336) --
(35.1071,77.4336)(43.1071,13.4336) -- (43.1071,77.4336)(51.1071,13.4336) --
(51.1071,77.4336)(59.1071,13.4336) -- (59.1071,77.4336)(67.1071,13.4336) --
(67.1071,77.4336)(75.1071,13.4336) -- (75.1071,77.4336)(83.1071,13.4336) --
(83.1071,77.4336)(19.1071,13.4336) -- (83.1071,13.4336)(19.1071,21.4336) --
(83.1071,21.4336)(19.1071,29.4336) -- (83.1071,29.4336)(19.1071,37.4336) --
(83.1071,37.4336)(19.1071,45.4336) -- (83.1071,45.4336)(19.1071,53.4336) --
(83.1071,53.4336)(19.1071,61.4336) -- (83.1071,61.4336)(19.1071,69.4336) --
(83.1071,69.4336)(19.1071,77.4336) -- (83.1071,77.4336);
\end{scope}
\path[draw=black,fill=cff6600,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (105.3755,11.7660) rectangle
(113.3755,27.7660);
\path[draw=black,fill=cff8080,miter limit=4.00,fill opacity=0.996,line
width=0.114pt,rounded corners=0.0000cm] (113.3540,11.8100) rectangle
(121.4116,19.8675);
\end{tikzpicture}}
\newcommand{\diagramBa}{

\definecolor{cffffff}{RGB}{255,255,255}
\definecolor{cff0000}{RGB}{255,0,0}
\definecolor{cff6600}{RGB}{255,102,0}

\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(86.67178,67.24995)}]
\path[fill=cffffff,fill opacity=0.996,rounded corners=0.0000cm]
(19.1071,13.4336) rectangle (83.1071,77.4336);
\path[draw=black,line join=miter,line cap=butt,fill opacity=0.750,even odd
rule,line width=0.100pt] (19.1071,13.4336) --
(19.1071,77.4336)(27.1071,13.4336) -- (27.1071,77.4336)(35.1071,13.4336) --
(35.1071,77.4336)(43.1071,13.4336) -- (43.1071,77.4336)(51.1071,13.4336) --
(51.1071,77.4336)(59.1071,13.4336) -- (59.1071,77.4336)(67.1071,13.4336) --
(67.1071,77.4336)(75.1071,13.4336) -- (75.1071,77.4336)(83.1071,13.4336) --
(83.1071,77.4336)(19.1071,13.4336) -- (83.1071,13.4336)(19.1071,21.4336) --
(83.1071,21.4336)(19.1071,29.4336) -- (83.1071,29.4336)(19.1071,37.4336) --
(83.1071,37.4336)(19.1071,45.4336) -- (83.1071,45.4336)(19.1071,53.4336) --
(83.1071,53.4336)(19.1071,61.4336) -- (83.1071,61.4336)(19.1071,69.4336) --
(83.1071,69.4336)(19.1071,77.4336) -- (83.1071,77.4336);
\end{scope}
\path[draw=black,fill=cff0000,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (105.8017,80.7247) rectangle
(113.8017,96.7247);
\path[draw=black,fill=cff6600,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (113.8223,80.7392) rectangle
(121.8223,96.7392);

\end{tikzpicture}

}
\newcommand{\diagramBb}{

\definecolor{cffffff}{RGB}{255,255,255}
\definecolor{cff0000}{RGB}{255,0,0}
\definecolor{cff6600}{RGB}{255,102,0}
\definecolor{cff8080}{RGB}{255,128,128}

\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(86.66259,133.81742)}]
\path[fill=cffffff,fill opacity=0.996,rounded corners=0.0000cm]
(19.1071,13.4336) rectangle (83.1071,77.4336);
\path[draw=black,line join=miter,line cap=butt,fill opacity=0.750,even odd
rule,line width=0.100pt] (19.1071,13.4336) --
(19.1071,77.4336)(27.1071,13.4336) -- (27.1071,77.4336)(35.1071,13.4336) --
(35.1071,77.4336)(43.1071,13.4336) -- (43.1071,77.4336)(51.1071,13.4336) --
(51.1071,77.4336)(59.1071,13.4336) -- (59.1071,77.4336)(67.1071,13.4336) --
(67.1071,77.4336)(75.1071,13.4336) -- (75.1071,77.4336)(83.1071,13.4336) --
(83.1071,77.4336)(19.1071,13.4336) -- (83.1071,13.4336)(19.1071,21.4336) --
(83.1071,21.4336)(19.1071,29.4336) -- (83.1071,29.4336)(19.1071,37.4336) --
(83.1071,37.4336)(19.1071,45.4336) -- (83.1071,45.4336)(19.1071,53.4336) --
(83.1071,53.4336)(19.1071,61.4336) -- (83.1071,61.4336)(19.1071,69.4336) --
(83.1071,69.4336)(19.1071,77.4336) -- (83.1071,77.4336);
\end{scope}
\path[draw=black,fill=cff0000,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (105.7925,147.2922) rectangle
(113.7925,163.2922);
\path[cm={{0.0,1.0,-1.0,0.0,(0.0,0.0)}},draw=black,fill=cff6600,miter
limit=4.00,fill opacity=0.996,line width=0.160pt,rounded corners=0.0000cm]
(147.2979,-129.8177) rectangle (155.2979,-113.8177);
\path[draw=black,fill=cff8080,miter limit=4.00,fill opacity=0.996,line
width=0.114pt,rounded corners=0.0000cm] (105.5415,163.1772) rectangle
(113.5991,171.2347);

\end{tikzpicture}

}

\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000,

inner sep=0pt, outer sep=0pt, node distance=2cm]

\tikzstyle{block} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, very thin, inner sep=2mm]

\node [block] (pos) {Possibilities};
\node [block, below of=pos] (D1) {
1:\linebreak[4]
\diagramA
};
\node [block, below of=D1] (D2a) {
1:\linebreak[4]
\diagramBa
};
\node [block, below of=D1] (D2b) {
1:\linebreak[4]
\diagramBb
};

\end{tikzpicture}
\end{document}


Also, I don't think the way I am doing it is ideal, maybe you could point me some things I could do better.

• please make your code snippet compilable (extend it to small but complete document). – Zarko Dec 13 '18 at 21:06
• @Zarko it should be now, I don't know if that's enough to make it compilable, but the rest is still from an example document, so I don't want to put this mess into this as well – Chrisstar Dec 13 '18 at 21:15
• Does it work now? – Chrisstar Dec 13 '18 at 21:17
• I changed something again, maybe now? – Chrisstar Dec 13 '18 at 21:19
• Originally I had the left and right attributes but then it was too far apart so I removed them, but now it's overlapping. Also isn't there a better way than to do it manually? – Chrisstar Dec 13 '18 at 21:31

see if the following re-coding of your flowchart is acceptable to you:

\documentclass[tikz, margin=3.141592mm]{standalone}
\usetikzlibrary{calc, fit, positioning}

\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 6mm,
grid/.style = {draw=gray, very thin, minimum size=2.4mm,
inner sep=0pt, outer sep=0pt},
box/.style args = {#1/#2}{grid, above right,
minimum height=#1*2.4mm, minimum width=#2*2.4mm},% <--- size of grid boxes is
% determined by multiplicators of % grid cells size
% used are in grid cells coloring
mypic/.pic = {
\foreach \x in {1,...,8}
{   \foreach \y in {1,...,8}
{
\node [grid]  (n\x\y) at (.24*\x,.24*\y) {};    % <--- positions of grid boxes
\coordinate (-g\x\y) at (n\x\y.south west);     % <--- coordinates used in grid boxes coloring
}
}
\node (n0)  [left=of n11] {1:};
\node (f) [draw, very thin, rounded corners, inner sep=2mm, fit =(n0) (n88)] {};
\coordinate (-w) at (f.west);       % <-- coordinates of pic,
% needed at eventual drawing of lines between pic
\coordinate (-e) at (f.east);
\coordinate (-n) at (f.north);
\coordinate (-s) at (f.south);
},% end of pic
N/.style={grid, path picture={\pic {mypic};}}
]
\pic (p1) {mypic};
\node [box=1/1,fill=red!30] at (p1-g21) {}; % positioning of \pic
\node [box=2/1,fill=orange] at (p1-g11) {};

\pic (p2) at (-2,-2.8) {mypic};                 % positioning of \pic is estimated:
% x distance ~ pic width/2,
% y distance~ pic height/2with
\node [box=1/1,fill=red!30] at (p2-g18) {};
\node [box=2/1,fill=orange] at (p2-g27) {};

\pic (p3) at ( 2,-2.8) {mypic};
\node [box=1/2,fill=red!30] at (p3-g18) {};
\node [box=1/1,fill=orange] at (p3-g17) {};
\path   let \p1 = ($(p1-w)-(p1-e)$),
\n1 = {veclen(\x1,\y1) } in
node [minimum width=\n1,
draw=gray, very thin, rounded corners, inner sep=2mm,
above=of p1-n] {Possibilities};
\end{tikzpicture}
\end{document}


now the code is quite shorter and clear. for positioning of nodes are used absolute coordinates, which are not so difficult to determine (see comments in code). result is :

colored boxes in grid probably are not correct places nor have desired colors. this i left to you. from given examples it should be straightforward to identify position od box in grid, which you like to color and define desired color

of course, there are other ways to define your nodes ...

edit:

• \pic (stand for small image) is nice possibilities to draw small images defined as \pic {<name>}; which you can include to some main (bigger) tikz picture.
• contain of \pic is defined in its style definition (for it i select name ˙mypic, but you can select own name which is more meaningful to you). definition contains array of nodesgrid, which has namen\xy, where \x and y are determined by used loops.
• names in the first column of array are from n11 (at bottom) to n18 (at top).
• node n0, which contain 1: is positioned relative to the node n11. if you like to change this position, you select othe node (for example n18.
• node style box is defined for purpose oc coloring nodes in array. their size can be simple set by multipicators, whic determine how many grid nodes will cover
• for positioning of box nodes are determined coordinates -g\x\y.
• its not behave as standard node, so you need some percussion at they placement in image (consequently i use absolute coordinates)
• Thank you very much for this, it helps me a lot. How does this mypic/ or box/ work? Could you maybe point me to a reference? Also, is there a way to put the text ("1: ") on the top of the picture? I tried doing it using linebreaks, but it didn't really work – Chrisstar Dec 14 '18 at 13:38
• @Chrisstar, details of tikz you find in its excellent (and huge) manual. for star read part III (Tikz ist kein Zichenprogram). \pic is fine possibility for drawing small picture included in bigger (as i do in your case). in code i have add comments which explain what you asking. position of node with 1: is determined with left=of n11 replace n11 with n18`. – Zarko Dec 14 '18 at 13:45