help with tikz diagram 2
help with tikz diagram 2
I tried to adopt the solutions (from previous question) to five different yet quite similar diagrams which worked pretty well. However, I still have some questions.
How do I have to change the code so the lines are in one line?
Same as in one.
I need to write some text there. I tried it with the node command which didn't work well. Which command do I need to use?
4.&5. I should make some annotations within the diagram. I tried to make the speech bubbles with node shapes but without success.
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric,
chains,
calc,
fit,
arrows.meta,
backgrounds,
quotes,
matrix
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style=
text width=3cm,
align=center,
draw
,
diam/.style=
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white
,
basecirc/.style=
circle,
draw,
align=center,
text width=1.5cm
,
persohnlich/.style=
basecirc,
fill=black!60,
text=white
,
finanziell/.style=
basecirc,
fill=black!30
,
keine/.style=
basecirc,
fill=white
,
]
beginscope[
start chain=groups,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node freiwillig, nur Katastrophen-\schutz;
node freiwillig, nur Katastrophen-\schutz;
endscope
node [diam, below=2cm of values-1] (tauglich) sicherheits-\dienst\-tauglich?;
node [diam, right=4.2 of tauglich, inner sep=-2pt] (IV) IV bzw.\Integritäts-\schädigung\>40%?;
node [keine, right=0.75cm of IV] (EG) keine\Ersatz-\abgabe;
node [diam, below=of tauglich] (Gewissen) mit\Gewissen\vereinbar?;
node [finanziell, at=(IV|-Gewissen)] (Ersatzabgabe) Ersatz-abgabe;
node [persohnlich, below=of Gewissen] (Armee) Armee;
node [finanziell, right=0.3 of Armee, , left color=black!60, right color=black!30,shading angle=90] (Schutz) Katastrophen-\schutz;
draw [-Triangle, line width=2mm] (values-1) -- coordinate (mid) (tauglich);
draw [dashed, ultra thick] (values-2) |- (mid);
draw [dashed, thick] (values-3) -- (values-3 |- mid) ;
draw [dashed, thick] (values-4) |- (values-2 |- mid);
coordinate (a) at (2.2,-11);
coordinate (b) at (0,-7.2);
draw [thick] [-] (a) |- (b);
coordinate (a) at (2.2,-11);
coordinate (c) at (1,-8.85);
draw [thick] [-] (a) |- (c);
path[near start,thick]
(tauglich) edge["JA"] (Gewissen)
(Gewissen) edge["JA"] (Armee)
(tauglich) edge["NEIN"] (IV)
(IV) edge["JA"] (EG)
(IV) edge["NEIN"] (Ersatzabgabe);
node [draw,fit=(Armee)(EG), inner sep=5mm] (frame) ;
matrix [
above left,
matrix of nodes,
nodes=anchor=west
] (m) at (frame.south east) & Sicherheitsdienstpflicht & ;
endtikzpicture
enddocument
As you can see the nodes cover the text. How can I enlarge the frame so it fits?
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric, % for diamond shape
chains, % for automatic placement nodes relative to the previous one, in "chains"
calc, % for ($...$) syntax of coordinate calculation
fit, % to create a node that fits around other specified nodes
arrows.meta, % for Triangle arrow tip
backgrounds, % for "on background layer", to place something behind already existing stuff
quotes, % for edge["label"] syntax, easy way of placing text along an edge
matrix % for matrix of nodes
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style= % base style for rectangles on top of the diagram
text width=3cm,
align=center,
draw
,
diam/.style= % style for the black diamonds
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white
,
basecirc/.style= % basic circle style, used in the next three styles
circle,
draw,
align=center,
text width=1.5cm
,
persohnlich/.style=
basecirc,
fill=black!60,
text=white
,
finanziell/.style=
basecirc,
fill=black!30
,
keine/.style=
basecirc,
fill=white
,
]
beginscope[
% in this scope, start a chain called groups. nodes in this chain are named groups-1, groups-2 etc.
start chain=groups,
% set distance between nodes in the chain
node distance=-pgflinewidth,
every node/.append style= % set style for all the nodes in the scope
baserect,
on chain, % adds all the nodes to the chain
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
% now add all the nodes, no additional styling or positioning needed
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
% this scope is basically the same as the previous one.
% one main difference is that the first node in the chain is
% placed on the lower edge of the first node in the previous chain
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node dienstpflichtig, (kein Zugang zur Armee);
node dienstpflichtig, (kein Zugang zur Armee);
endscope
% the nodes in the first row of the flow chart
node [diam, below=2cm of values-1] (tauglich) dienst-\tauglich?;
node [keine, right=7.9 of tauglich] (EG) keine\Ersatz-\abgabe;
% last node in flow chart
node [persohnlich, below=of tauglich] (Armee) Armee;
node [persohnlich, right=0.75cm of Armee] (Feuerwehr) Feuerwehr;
node [persohnlich, right=0.75cm of Feuerwehr] (Zivilschutz) Zivilschutz;
node [persohnlich, right=0.75cm of Zivilschutz] (SRK) Einsatz-\organisationen\SRK*;
node [persohnlich, right=0.75cm of SRK] (Gemeinschaftsdienste) Gemeinschaftsdienste;
% draw thick arrow from the dienstpflichtig node to the first node in the flow chart
% add a coordinate named "mid" halfway along the arrow, that is used to draw the dashed lines
draw [-Triangle, line width=2mm] (values-1) -- coordinate (mid) (tauglich);
% here (values-2) |- (mid) means draw a vertical, then horizontal,
% line from values-2 to mid
draw [line width=2mm] (values-2) |- (mid);
draw [line width=2mm] (values-3) |- (mid);
draw [line width=2mm] (values-4) |- (mid);
% here the -|/|- syntax is used both for coordinate specifications and path specifications
%draw [dashed, thick] (values-3) -- (values-3 |- mid) -| (schutzdienst);
%draw [dashed, thick] (values-4) |- (values-3 |- mid);
% draw the coloured background for the top right part of the flow chart, using a fit node
%beginscope[on background layer]
% node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] ;
%endscope
% draw the connections in the flow chart
% the ".." syntax comes from the quotes library
path[near start,thick]
(tauglich) edge["JA"] (Armee)
(tauglich) edge["NEIN"] (EG);
coordinate (a) at (2.5,-7.28);
coordinate (b) at (0,-6.8);
draw [-] (a) |- (b);
coordinate (c) at (5,-7.28);
coordinate (b) at (0,-6.8);
draw [-] (c) |- (b);
coordinate (d) at (7.7,-7.16);
coordinate (b) at (0,-6.8);
draw [-] (d) |- (b);
coordinate (e) at (10.5,-7.29);
coordinate (b) at (0,-6.8);
draw [-] (e) |- (b);
% use fit again, to draw the surrounding frame
node [draw,fit=(Armee)(EG), inner sep=5mm] (frame) ;
% use a matrix to make the legend
matrix [
above left,
matrix of nodes,
nodes=anchor=west
] (m) at (frame.south east) [draw,minimum size=8pt];
endtikzpicture
enddocument
Thank you for your help!
EDIT:
I tried to use marmot's solution regarding the second question. I worked fine with the other diagrams. However, with one it didn't work. What do I have to correct in the code so it works?
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric, % for diamond shape
chains, % for automatic placement nodes relative to the previous one, in "chains"
calc, % for ($...$) syntax of coordinate calculation
fit, % to create a node that fits around other specified nodes
arrows.meta, % for Triangle arrow tip
backgrounds, % for "on background layer", to place something behind already existing stuff
quotes, % for edge["label"] syntax, easy way of placing text along an edge
matrix % for matrix of nodes
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style= % base style for rectangles on top of the diagram
text width=3.55cm,
align=center,
draw
,
diam/.style= % style for the black diamonds
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white,
minimum size=2.5cm
,
basecirc/.style= % basic circle style, used in the next three styles
circle,
draw,
align=center,
text width=1.5cm,
,
persohnlich/.style=
basecirc,
fill=black!60,
text=white,
text width=1.7cm,
minimum size=2.2cm
,
finanziell/.style=
basecirc,
fill=black!30,
minimum size=2.2cm
% text=white
,
keine/.style=
basecirc,
fill=white,
minimum size=2.2cm
,
matrix1/.style=
basecirc,
fill=black!60,
text=white
,
matrix2/.style=
basecirc,
fill=black!30,
% text=white
,
matrix3/.style=
basecirc,
fill=white
,
]
beginscope[
% in this scope, start a chain called groups. nodes in this chain are named groups-1, groups-2 etc.
start chain=groups,
% set distance between nodes in the chain
node distance=-pgflinewidth,
every node/.append style= % set style for all the nodes in the scope
baserect,
on chain, % adds all the nodes to the chain
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
% now add all the nodes, no additional styling or positioning needed
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
% this scope is basically the same as the previous one.
% one main difference is that the first node in the chain is
% placed on the lower edge of the first node in the previous chain
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node dienstpflichtig, (kein Zugang zur Armee);
node dienstpflichtig, (kein Zugang zur Armee);
endscope
% the nodes in the first row of the flow chart
node [diam, below=2cm of values-1] (tauglich) dienst-\tauglich?;
node [keine, right=7.9 of tauglich] (EG) keine\Ersatz-\abgabe;
% last node in flow chart
node [persohnlich, below=3cm of tauglich] (Armee) Armee;
node [persohnlich, right=0.75cm of Armee] (Feuerwehr) Feuerwehr;
node [persohnlich, right=0.75cm of Feuerwehr] (Zivilschutz) Zivilschutz;
node [persohnlich, right=0.75cm of Zivilschutz] (SRK) Einsatz-\organisationen\SRK*;
node [persohnlich, right=0.75cm of SRK] (Gemeinschaftsdienste)
Gemein-\schafts-\dienste;
% draw thick arrow from the dienstpflichtig node to the first node in the flow chart
% add a coordinate named "mid" halfway along the arrow, that is used to draw the dashed lines
draw [-Triangle, line width=2mm] (values-1) -- coordinate (mid) (tauglich);
% here (values-2) |- (mid) means draw a vertical, then horizontal,
% line from values-2 to mid
draw [line width=2mm] (values-2) |- (mid);
draw [line width=2mm] (values-3) |- (mid);
draw [line width=2mm] (values-4) |- (mid);
% here the -|/|- syntax is used both for coordinate specifications and path specifications
%draw [dashed, thick] (values-3) -- (values-3 |- mid) -| (schutzdienst);
%draw [dashed, thick] (values-4) |- (values-3 |- mid);
% draw the coloured background for the top right part of the flow chart, using a fit node
%beginscope[on background layer]
% node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] ;
%endscope
% draw the connections in the flow chart
% the ".." syntax comes from the quotes library
path[near start,thick]
(tauglich) edge["JA",swap] (Armee)
(tauglich) edge["NEIN"] (EG);
node[text width=4cm] at (2.5,-7.8) Freie Wahl nach Massgabe der Tauglichkeit, der Eignung; Personalbedrüfnisse der Armee müsssen gesichert sein;
node[text width=4cm] at (1,-12) tiny *Organisationen des Schweiz. Roten Kreuzes, die in das Dispositiv eines Kantons zur Bewältigung von Katastrophen und Notlagen integriert sind;
coordinate (b) at (0,-8.8);
draw [-] (Armee.north) |- (b);
draw [-] (Feuerwehr.north) |- (b);
draw [-] (Zivilschutz.north) |- (b);
draw [-] (SRK.north) |- (b);
draw [-] (Gemeinschaftsdienste) |- (b);
% use a matrix to make the legend
matrix [
below=1.1cm of Gemeinschaftsdienste.east,
anchor=north east,
matrix of nodes,
nodes=anchor=west
] (m)
&&[1cm];
% use fit again, to draw the surrounding frame
node[fit=(groups-1) (groups-4) (values-1) (values-4),draw,inner
sep=-pgflinewidth/2](upper fit);
foreach X[count=Y] in 2,3,4
-upper fit.south);
coordinate (aux-L) at ([xshift=5mm+pgflinewidth]upper fit.west|-Armee.center);
coordinate (aux-R) at ([xshift=-5mm-pgflinewidth]upper fit.east|-Armee.center);
node [draw,fit=(Armee)(EG)(aux-L)(aux-R), inner sep=5mm] (frame) ;
endtikzpicture
enddocument
node [draw,fit=(Armee)(EG)(aux-L)(aux-R) (m), inner sep=5mm] (frame) ;
I spent about two hours searching for the error. Sometimes it is so easy:)
– danik
Sep 6 at 20:28
Please, ask only one question at a time. Here, you ask three questions: 1&2 (alignment), 3 (paragraph shape) and 4&5 (bubble nodes).
– Paul Gaborit
Sep 6 at 21:36
2 Answers
2
Gruezi from a marmot! ;-)
Here is how I would address the upper part of your questions:
fit
h
h'
edge["text",swap]
swap
cloudy
For some reason the umlaute do not show, which compiler do you use? They will of course show when you compile the code. (To compensate for that, I fixed the spelling of "persönlich". ;-)
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric,
chains,
calc,
fit,
arrows.meta,
backgrounds,
quotes,
matrix
% from https://tex.stackexchange.com/a/432326/121799
usetikzlibrarydecorations.pathreplacing,shadows.blur,shapes
tikzset
% styles to save the path in `savedpath`
add path/.style =
decoration=show path construction,
moveto code=
xdefsavedpathsavedpath (tikzinputsegmentfirst)
,
lineto code=
xdefsavedpathsavedpath -- (tikzinputsegmentlast)
,
curveto code=
xdefsavedpathsavedpath .. controls (tikzinputsegmentsupporta) and (tikzinputsegmentsupportb) ..(tikzinputsegmentlast)
,
closepath code=
xdefsavedpathsavedpath -- cycle
,
decorate
,
store path/.style = add path,
store path/.prefix code=xdefsavedpath,
% the style to create the path
callouts/.style=
store path,
append after command=
foreach target in #1
($(callout)!2pt!-90:target$)--target --($(callout)!2pt!90:target$)
savedpath
,
alias=callout
,
% the style to display the callout
custom style/.style=fill=blue!20,text=,blur shadow,
% some fun cloudy node
cloudy/.style=cloud,cloud puffs=10,cloud puff arc=120, aspect=2,
more serious/.style=ellipse
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style=
text width=3cm,
align=center,
draw
,
diam/.style=
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white
,
basecirc/.style=
circle,
draw,
align=center,
text width=1.5cm
,
persoenlich/.style=
basecirc,
fill=black!60,
text=white
,
finanziell/.style=
basecirc,
fill=black!30
,
keine/.style=
basecirc,
fill=white
,
]
beginscope[
start chain=groups,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
draw=none, %<- added
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node freiwillig, nur Katastrophen-\schutz;
node freiwillig, nur Katastrophen-\schutz;
endscope
% add a frame
node[fit=(groups-1) (groups-4) (values-1) (values-4),draw,inner
sep=-pgflinewidth/2](upper fit);
foreach X[count=Y] in 2,3,4
-upper fit.south);
node [diam, below=2cm of values-1] (tauglich) sicherheits-\dienst\-tauglich?;
node [diam, right=4.2 of tauglich, inner sep=-2pt] (IV) IV bzw.\Integritäts-\schädigung\>40%?;
node [keine, right=0.75cm of IV] (EG) keine\Ersatz-\abgabe;
node [diam, below=of tauglich] (Gewissen) mit\Gewissen\vereinbar?;
node [finanziell, at=(IV|-Gewissen)] (Ersatzabgabe) Ersatz-abgabe;
node [persoenlich, below=of Gewissen] (Armee) Armee;
node [finanziell, right=0.3 of Armee, , left color=black!60, right color=black!30,shading angle=90] (Schutz) Katastrophen-\schutz;
% modified the draw commands
draw [-Triangle, line width=2mm] (upper fit.south -| values-1.center) -- coordinate (mid) (tauglich);
draw [dashed, ultra thick] (upper fit.south -|values-2) |- (mid);
draw [dashed, thick] (upper fit.south -|values-3) -- (values-3 |- mid) ;
draw [dashed, thick] (upper fit.south -|values-4) |- (values-2 |- mid);
coordinate (a) at (2.2,-11);
coordinate (b) at (0,-7.2);
draw [thick] [-] (a) |- (b) coordinate[midway] (h); % added hilfscoordinate
coordinate (a) at (2.2,-11);
coordinate (c) at (1,-8.85);
draw [thick] [-] (a) |- (c) coordinate[midway] (h'); % added hilfscoordinate
path[near start,thick]
(tauglich) edge["JA"] (Gewissen)
(Gewissen) edge["JA"] (Armee)
(b) edge["text",swap] (h) %<-add text
(tauglich) edge["NEIN"] (IV)
(IV) edge["JA"] (EG)
(IV) edge["NEIN"] (Ersatzabgabe);
% 3rd edit
coordinate (aux-L) at ([xshift=5mm+pgflinewidth]upper fit.west|-Armee.center);
coordinate (aux-R) at ([xshift=-5mm-pgflinewidth]upper fit.east|-Armee.center);
node [draw,fit=(Armee)(EG)(aux-L)(aux-R), inner sep=5mm] (frame) ;
matrix [
above left,
matrix of nodes,
nodes=anchor=west
] (m) at (frame.south east) [finanziell,text width=0cm];
path[custom style] ($(Schutz)!0.5!(Ersatzabgabe)$) node[more serious,callouts=(Schutz),(Ersatzabgabe)]blah blah;
path[custom style] ($(h')+(1,1)$) node[more serious,callouts=(h')]blah blah;
endtikzpicture
enddocument
2nd EDIT: As for your second question, I would just include the matrix
in the fit.
matrix
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric, % for diamond shape
chains, % for automatic placement nodes relative to the previous one, in "chains"
calc, % for ($...$) syntax of coordinate calculation
fit, % to create a node that fits around other specified nodes
arrows.meta, % for Triangle arrow tip
backgrounds, % for "on background layer", to place something behind already existing stuff
quotes, % for edge["label"] syntax, easy way of placing text along an edge
matrix % for matrix of nodes
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style= % base style for rectangles on top of the diagram
text width=3cm,
align=center,
draw
,
diam/.style= % style for the black diamonds
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white
,
basecirc/.style= % basic circle style, used in the next three styles
circle,
draw,
align=center,
text width=1.5cm
,
persohnlich/.style=
basecirc,
fill=black!60,
text=white
,
finanziell/.style=
basecirc,
fill=black!30
,
keine/.style=
basecirc,
fill=white
,
]
beginscope[
% in this scope, start a chain called groups. nodes in this chain are named groups-1, groups-2 etc.
start chain=groups,
% set distance between nodes in the chain
node distance=-pgflinewidth,
every node/.append style= % set style for all the nodes in the scope
baserect,
on chain, % adds all the nodes to the chain
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
% now add all the nodes, no additional styling or positioning needed
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
% this scope is basically the same as the previous one.
% one main difference is that the first node in the chain is
% placed on the lower edge of the first node in the previous chain
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node dienstpflichtig, (kein Zugang zur Armee);
node dienstpflichtig, (kein Zugang zur Armee);
endscope
% the nodes in the first row of the flow chart
node [diam, below=2cm of values-1] (tauglich) dienst-\tauglich?;
node [keine, right=7.9 of tauglich] (EG) keine\Ersatz-\abgabe;
% last node in flow chart
node [persohnlich, below=of tauglich] (Armee) Armee;
node [persohnlich, right=0.75cm of Armee] (Feuerwehr) Feuerwehr;
node [persohnlich, right=0.75cm of Feuerwehr] (Zivilschutz) Zivilschutz;
node [persohnlich, right=0.75cm of Zivilschutz] (SRK) Einsatz-\organisationen\SRK*;
node [persohnlich, right=0.75cm of SRK] (Gemeinschaftsdienste)
Gemein-\schafts-\dienste;
% draw thick arrow from the dienstpflichtig node to the first node in the flow chart
% add a coordinate named "mid" halfway along the arrow, that is used to draw the dashed lines
draw [-Triangle, line width=2mm] (values-1) -- coordinate (mid) (tauglich);
% here (values-2) |- (mid) means draw a vertical, then horizontal,
% line from values-2 to mid
draw [line width=2mm] (values-2) |- (mid);
draw [line width=2mm] (values-3) |- (mid);
draw [line width=2mm] (values-4) |- (mid);
% here the -|/|- syntax is used both for coordinate specifications and path specifications
%draw [dashed, thick] (values-3) -- (values-3 |- mid) -| (schutzdienst);
%draw [dashed, thick] (values-4) |- (values-3 |- mid);
% draw the coloured background for the top right part of the flow chart, using a fit node
%beginscope[on background layer]
% node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] ;
%endscope
% draw the connections in the flow chart
% the ".." syntax comes from the quotes library
path[near start,thick]
(tauglich) edge["JA"] (Armee)
(tauglich) edge["NEIN"] (EG);
coordinate (a) at (2.5,-7.28);
coordinate (b) at (0,-6.8);
draw [-] (a) |- (b);
coordinate (c) at (5,-7.28);
coordinate (b) at (0,-6.8);
draw [-] (c) |- (b);
coordinate (d) at (7.7,-7.16);
coordinate (b) at (0,-6.8);
draw [-] (d) |- (b);
coordinate (e) at (10.5,-7.29);
coordinate (b) at (0,-6.8);
draw [-] (e) |- (b);
% use a matrix to make the legend
matrix [
below=1.1cm of Gemeinschaftsdienste.east,
anchor=north east,
matrix of nodes,
nodes=anchor=west
] (m) [draw,minimum size=8pt];
% use fit again, to draw the surrounding frame
node [draw,fit=(Armee)(EG)(m), inner sep=5mm] (frame) ;
endtikzpicture
enddocument
ADDENDUM: Callouts from this answer.
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric,
chains,
calc,
fit,
arrows.meta,
backgrounds,
quotes,
matrix
makeatletter % from https://tex.stackexchange.com/questions/187165/callout-with-multiple-pointers-how-to-design-it/361532#361532]
defoverlaynode<#1>#2;
gdefstacknodecommonpart#2
pgfkeys/typeset node/.list=#1
% we are lazy
% pgfkeys will translate
% pgfkeys/typeset node/.list=red,blue
% into
% pgfkeys/typeset node=red
% pgfkeys/typeset node=blue
pgfkeys
/typeset node/.code=
edefpgf@marshalnoexpandnode[#1]stacknodecommonpart;
pgf@marshal
defoverlaynodedrawfillpgfutil@ifnextchar[overlaynodedrawfill@optoverlaynodedrawfill@opt
defoverlaynodedrawfill@opt[#1]<#2>#3;
beginscope[transparency group,draw=black,fill=white,line cap=round,line join=round,#1]
pgfmathsetmacropgflinewidthdouble2pgflinewidth
overlaynode<#2>[draw=pgfstrokecolor,line width=pgflinewidthdouble]#3;
overlaynode<#2>[fill=pgffillcolor]#3;
endscope
makeatother
% from https://tex.stackexchange.com/a/432326/121799
usetikzlibrarydecorations.pathreplacing,shadows.blur,shapes
tikzset
% styles to save the path in `savedpath`
add path/.style =
decoration=show path construction,
moveto code=
xdefsavedpathsavedpath (tikzinputsegmentfirst)
,
lineto code=
xdefsavedpathsavedpath -- (tikzinputsegmentlast)
,
curveto code=
xdefsavedpathsavedpath .. controls (tikzinputsegmentsupporta) and (tikzinputsegmentsupportb) ..(tikzinputsegmentlast)
,
closepath code=
xdefsavedpathsavedpath -- cycle
,
decorate
,
store path/.style = add path,
store path/.prefix code=xdefsavedpath,
% the style to create the path
callouts/.style=
store path,
append after command=
foreach target in #1
($(callout)!2pt!-90:target$)--target --($(callout)!2pt!90:target$)
savedpath
,
alias=callout
,
% the style to display the callout
custom style/.style=fill=white,text=black,blur shadow,
% some fun cloudy node
cloudy/.style=cloud,cloud puffs=10,cloud puff arc=120, aspect=2,
more serious/.style=ellipse,draw=black
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style=
text width=3cm,
align=center,
draw
,
diam/.style=
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white
,
basecirc/.style=
circle,
draw,
align=center,
text width=1.5cm
,
persoenlich/.style=
basecirc,
fill=black!60,
text=white
,
finanziell/.style=
basecirc,
fill=black!30
,
keine/.style=
basecirc,
fill=white
,
]
beginscope[
start chain=groups,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
draw=none, %<- added
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node freiwillig, nur Katastrophen-\schutz;
node freiwillig, nur Katastrophen-\schutz;
endscope
% add a frame
node[fit=(groups-1) (groups-4) (values-1) (values-4),draw,inner
sep=-pgflinewidth/2](upper fit);
foreach X[count=Y] in 2,3,4
-upper fit.south);
node [diam, below=2cm of values-1] (tauglich) sicherheits-\dienst\-tauglich?;
node [diam, right=4.2 of tauglich, inner sep=-2pt] (IV) IV bzw.\Integritäts-\schädigung\>40%?;
node [keine, right=0.75cm of IV] (EG) keine\Ersatz-\abgabe;
node [diam, below=of tauglich] (Gewissen) mit\Gewissen\vereinbar?;
node [finanziell, at=(IV|-Gewissen)] (Ersatzabgabe) Ersatz-abgabe;
node [persoenlich, below=of Gewissen] (Armee) Armee;
node [finanziell, right=0.3 of Armee, , left color=black!60, right color=black!30,shading angle=90] (Schutz) Katastrophen-\schutz;
% modified the draw commands
draw [-Triangle, line width=2mm] (upper fit.south -| values-1.center) -- coordinate (mid) (tauglich);
draw [dashed, ultra thick] (upper fit.south -|values-2) |- (mid);
draw [dashed, thick] (upper fit.south -|values-3) -- (values-3 |- mid) ;
draw [dashed, thick] (upper fit.south -|values-4) |- (values-2 |- mid);
coordinate (a) at (2.2,-11);
coordinate (b) at (0,-7.2);
draw [thick] [-] (a) |- (b) coordinate[midway] (h); % added hilfscoordinate
coordinate (a) at (2.2,-11);
coordinate (c) at (1,-8.85);
draw [thick] [-] (a) |- (c) coordinate[midway] (h'); % added hilfscoordinate
path[near start,thick]
(tauglich) edge["JA"] (Gewissen)
(Gewissen) edge["JA"] (Armee)
(b) edge["text",swap] (h) %<-add text
(tauglich) edge["NEIN"] (IV)
(IV) edge["JA"] (EG)
(IV) edge["NEIN"] (Ersatzabgabe);
% 3rd edit
coordinate (aux-L) at ([xshift=5mm+pgflinewidth]upper fit.west|-Armee.center);
coordinate (aux-R) at ([xshift=-5mm-pgflinewidth]upper fit.east|-Armee.center);
node [draw,fit=(Armee)(EG)(aux-L)(aux-R), inner sep=5mm] (frame) ;
matrix [
above left,
matrix of nodes,
nodes=anchor=west
] (m) at (frame.south east) [finanziell,text width=0cm];
overlaynodedrawfill[draw,fill=white]<
callout absolute pointer=(Schutz.45),
callout absolute pointer=(Ersatzabgabe.-135)
>
[ellipse callout]
at ($(Schutz)!0.5!(Ersatzabgabe)$)hear me;
overlaynodedrawfill[draw,fill=white]<
callout absolute pointer=(h'.45)
>
[ellipse callout]
at ($(h')+(1,1)$)hear me;
% path[custom style] ($(Schutz)!0.5!(Ersatzabgabe)$) node[more serious,callouts=(Schutz),(Ersatzabgabe)]blah blah;
% path[custom style] ($(h')+(1,1)$) node[more serious,callouts=(h')]blah blah;
endtikzpicture
enddocument
Gruezi marmot, thank you for your answer and correcting persohnlich :) I use MiKTeX and TeXstudio, which works fine with Umlaute.
– danik
Sep 4 at 18:38
Hi marmot, I hope you're not yet in your hibernation and still awake enough to answer me some more questions :). Is there a possibility to enlarge the pointers? Is it true that it's impossible to have a white speech bubble with a black border with Kpym's callouts or am I just too stupid to do that? The third question is a bit longer so added it to my question.
– danik
Sep 6 at 18:20
@danik I am busy now. Would you mind asking a new question? I will look at it as soon as I have time. Questions are free and you will benefit from having your new question at the top of the list.
– marmot
Sep 6 at 18:33
@danik You could use
path[multiple absolute pointers= [fill=white,ellipse, at=($(Schutz)!0.5!(Ersatzabgabe)$),draw] [fill=white]Schutz.45,[fill=white]Ersatzabgabe.-135 ABCD]; path[multiple absolute pointers= [fill=white,ellipse, at=($(h')+(1,1)$),draw] [fill=white]h'.45 XYZ];
if you use the preamble of "Full code] in this answer. It is not too pretty. And then I do not understand what "enlarge the pointers" means.– marmot
Sep 6 at 19:27
path[multiple absolute pointers= [fill=white,ellipse, at=($(Schutz)!0.5!(Ersatzabgabe)$),draw] [fill=white]Schutz.45,[fill=white]Ersatzabgabe.-135 ABCD]; path[multiple absolute pointers= [fill=white,ellipse, at=($(h')+(1,1)$),draw] [fill=white]h'.45 XYZ];
Thank you for your reply. I've already looked at the link you sent before but I prefer the one from Kpym. I find it much easier. I was just wondering wether it's possible to draw a callout and fill it white. But apparently that's not possible with Kpym's solution. "Enlarge the pointer" means a similar command like "callout pointer width=.5cm" from [tex.stackexchange.com/questions/187165/… but with Kpym's solution. I hope it's clearer now.
– danik
Sep 6 at 20:03
Regarding the enlargment of the frame and minor .north
calls instead of new coordinate
definitions
.north
coordinate
documentclass[border=5mm]standalone
usepackagetikz
usepackage[utf8]inputenc
usepackage[T1]fontenc
usetikzlibrary
positioning,
shapes.geometric, % for diamond shape
chains, % for automatic placement nodes relative to the previous one, in "chains"
calc, % for ($...$) syntax of coordinate calculation
fit, % to create a node that fits around other specified nodes
arrows.meta, % for Triangle arrow tip
backgrounds, % for "on background layer", to place something behind already existing stuff
quotes, % for edge["label"] syntax, easy way of placing text along an edge
matrix % for matrix of nodes
begindocument
begintikzpicture[
font=footnotesizesffamily,
baserect/.style= % base style for rectangles on top of the diagram
text width=3cm,
align=center,
draw
,
diam/.style= % style for the black diamonds
diamond,
draw,
align=center,
text width=1.5cm,
inner sep=1pt,
fill=black,
text=white
,
basecirc/.style= % basic circle style, used in the next three styles
circle,
draw,
align=center,
text width=1.5cm
,
persohnlich/.style=
basecirc,
fill=black!60,
text=white,
text width=1.7cm,
,
finanziell/.style=
basecirc,
fill=black!30
,
keine/.style=
basecirc,
fill=white
,
]
beginscope[
% in this scope, start a chain called groups. nodes in this chain are named groups-1, groups-2 etc.
start chain=groups,
% set distance between nodes in the chain
node distance=-pgflinewidth,
every node/.append style= % set style for all the nodes in the scope
baserect,
on chain, % adds all the nodes to the chain
font=footnotesizesffamilybfseries,
minimum height=2cm,
fill=black!20,
]
% now add all the nodes, no additional styling or positioning needed
node Schweizer Männer;
node Schweizer Frauen;
node Ausländer \(niedergelassene Männer mit ausländischer Staatsangehörigkeit);
node Ausländerinnen (niedergelassene Frauen mit ausländischer Staatsangehörigkeit);
endscope
% this scope is basically the same as the previous one.
% one main difference is that the first node in the chain is
% placed on the lower edge of the first node in the previous chain
beginscope[
start chain=values,
node distance=-pgflinewidth,
every node/.append style=
baserect,
on chain,
minimum height=1cm
]
node [anchor=north] at (groups-1.south) dienstpflichtig;
node freiwillig;
node dienstpflichtig, (kein Zugang zur Armee);
node dienstpflichtig, (kein Zugang zur Armee);
endscope
% the nodes in the first row of the flow chart
node [diam, below=2cm of values-1] (tauglich) dienst-\tauglich?;
node [keine, right=7.9 of tauglich] (EG) keine\Ersatz-\abgabe;
% last node in flow chart
node [persohnlich, below=of tauglich] (Armee) Armee;
node [persohnlich, right=0.55cm of Armee] (Feuerwehr) Feuerwehr;
node [persohnlich, right=0.55cm of Feuerwehr] (Zivilschutz) Zivilschutz;
node [persohnlich, right=0.55cm of Zivilschutz] (SRK) Einsatz-\organisationen\SRK*;
node [persohnlich, right=0.55cm of SRK] (Gemeinschaftsdienste) Gemein-schaftsdienste;
% draw thick arrow from the dienstpflichtig node to the first node in the flow chart
% add a coordinate named "mid" halfway along the arrow, that is used to draw the dashed lines
draw [-Triangle, line width=2mm] (values-1) -- coordinate (mid) (tauglich);
% here (values-2) |- (mid) means draw a vertical, then horizontal,
% line from values-2 to mid
draw [line width=2mm] (values-2) |- (mid);
draw [line width=2mm] (values-3) |- (mid);
draw [line width=2mm] (values-4) |- (mid);
% here the -|/|- syntax is used both for coordinate specifications and path specifications
%draw [dashed, thick] (values-3) -- (values-3 |- mid) -| (schutzdienst);
%draw [dashed, thick] (values-4) |- (values-3 |- mid);
% draw the coloured background for the top right part of the flow chart, using a fit node
%beginscope[on background layer]
% node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] ;
%endscope
% draw the connections in the flow chart
% the ".." syntax comes from the quotes library
path[near start,thick]
(tauglich) edge["JA"] (Armee)
(tauglich) edge["NEIN"] (EG);
coordinate (b) at (0,-6.8);
draw [-] (Armee.north) |- (b);
draw [-] (Feuerwehr.north) |- (b);
draw [-] (Zivilschutz.north) |- (b);
draw [-] (SRK.north) |- (b);
draw [-] (Gemeinschaftsdienste) |- (b);
% use fit again, to draw the surrounding frame
node [draw,fit=(Armee)(EG), inner sep=5mm] (frame) ;
% use a matrix to make the legend
matrix [
above left,
matrix of nodes,
nodes=anchor=west
] (m) at (frame.south east) [draw,minimum size=8pt];
endtikzpicture
enddocument
Thank you for your answer. With north it's much better:) But I don't get your comment about enlarging the frame...
– danik
Sep 3 at 18:21
@danik I added
text width=1.7cm
to the persohnlich
style– BambOo
Sep 3 at 19:22
text width=1.7cm
persohnlich
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You only need to add the matrix to the fit:
node [draw,fit=(Armee)(EG)(aux-L)(aux-R) (m), inner sep=5mm] (frame) ;
.– marmot
Sep 6 at 19:15