8

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. enter image description here

  1. How do I have to change the code so the lines are in one line?

  2. Same as in one.

  3. 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}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetikzlibrary{
  positioning,
  shapes.geometric, 
  chains, 
  calc,
  fit,
  arrows.meta, 
  backgrounds, 
  quotes,
  matrix 
}
\begin{document}
\begin{tikzpicture}[
    font=\footnotesize\sffamily,
    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
    },
]


\begin{scope}[
   start chain=groups,
   node distance=-\pgflinewidth,
   every node/.append style={
     baserect,
     on chain, 
     font=\footnotesize\sffamily\bfseries,
     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)};
\end{scope}




\begin{scope}[
   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};
\end{scope}


\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) {
&&[0.5cm] |[persohnlich,text width=0cm]| & persöhnliche Dienstleistung \\
&& |[finanziell,text width=0cm]| &finanzielle Ersatzgabe \\
|[draw,minimum size=8pt]| & Sicherheitsdienstpflicht & |[keine,text width=0cm]| & keine Leistung \\
};
\end{tikzpicture} 
\end{document}

enter image description here

  1. As you can see the nodes cover the text. How can I enlarge the frame so it fits?

        \documentclass[border=5mm]{standalone}
        \usepackage{tikz}
        \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
        }
        \begin{document}
        \begin{tikzpicture}[
            font=\footnotesize\sffamily,
            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
            },
        ]
    
    
        \begin{scope}[
           % 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=\footnotesize\sffamily\bfseries,
             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)};
        \end{scope}
    
        % 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
        \begin{scope}[
           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)};
        \end{scope}
    
        % 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
        %\begin{scope}[on background layer]
         % \node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] {};
        %\end{scope}
    
    
        % 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) {
        &&[1cm]|[keine,text width=0cm]| & keine Leistung \\
        |[draw,minimum size=8pt]| & Allgemeine Diensptpflicht & |[finanziell,text width=0cm]| &finanzielle Ersatzgabe \\
        };
        \end{tikzpicture} 
        \end{document}
    

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}
\usepackage{tikz}
\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
}
\begin{document}
\begin{tikzpicture}[
font=\footnotesize\sffamily,
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
},
]   


\begin{scope}[
% 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=\footnotesize\sffamily\bfseries,
    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)};
\end{scope}

% 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
\begin{scope}[
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)};
\end{scope}

% 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
%\begin{scope}[on background layer]
% \node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] {};
%\end{scope}


% 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]|[matrix3,text width=0cm]| & keine Leistung \\
    |[draw,minimum size=8pt]| & Allgemeine Diensptpflicht & |[matrix2,text width=0cm]| &finanzielle Ersatzgabe \\
};
% 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}
{\draw ($(groups-\Y.south east)!0.5!(groups-\X.south west)$) coordinate(aux)
    -- (aux|-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) {};
\end{tikzpicture} 
\end{document}
  • You only need to add the matrix to the fit: \node [draw,fit=(Armee)(EG)(aux-L)(aux-R) (m), inner sep=5mm] (frame) {};. – user121799 Sep 6 '18 at 19:15
  • I spent about two hours searching for the error. Sometimes it is so easy:) – danik Sep 6 '18 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 '18 at 21:36
7

Gruezi from a marmot! ;-)

Here is how I would address the upper part of your questions:

  1. use fit to draw the boundary of the upper group and to define the starting points of the arrows;
  2. add some auxiliary coordinates to make the lower frame as wide as the upper one (=4th edit);
  3. add auxiliary coordinates h and h' to add the text with edge["text",swap], where swap swaps the text position from above to below;
  4. and 5. use Kpym's extremely cool and undervoted callouts with multiple pointers. I replaced cloudy by something that might be more appropriate.

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}
\usepackage{tikz}
\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
\usetikzlibrary{decorations.pathreplacing,shadows.blur,shapes}
\tikzset{
  % styles to save the path in `\savedpath`
  add path/.style = {
    decoration={show path construction,
      moveto code={
        \xdef\savedpath{\savedpath (\tikzinputsegmentfirst)}
      },
      lineto code={
        \xdef\savedpath{\savedpath -- (\tikzinputsegmentlast)}
      },
      curveto code={
        \xdef\savedpath{\savedpath .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast)}
      },
      closepath code={
        \xdef\savedpath{\savedpath -- cycle}
      }
    },
    decorate
  },
  store path/.style = {add path},
  store path/.prefix code={\xdef\savedpath{}},
  % 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}
}
\begin{document}
\begin{tikzpicture}[
    font=\footnotesize\sffamily,
    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
    },
]


\begin{scope}[
   start chain=groups,
   node distance=-\pgflinewidth,
   every node/.append style={
     baserect,
     on chain, 
     font=\footnotesize\sffamily\bfseries,
     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)};
\end{scope}


\begin{scope}[
   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};
\end{scope}

% 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}
{\draw ($(groups-\Y.south east)!0.5!(groups-\X.south west)$) coordinate(aux)
-- (aux|-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) {
&&[0.5cm] |[persoenlich,text width=0cm]| & persönliche Dienstleistung \\
&& |[finanziell,text width=0cm]| &finanzielle Ersatzgabe \\
|[draw,minimum size=8pt]| & Sicherheitsdienstpflicht & |[keine,text width=0cm]| & keine Leistung \\
};

\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};
\end{tikzpicture} 
\end{document}

enter image description here

2nd EDIT: As for your second question, I would just include the matrix in the fit.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\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
}
\begin{document}
\begin{tikzpicture}[
    font=\footnotesize\sffamily,
    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
    },
]


\begin{scope}[
   % 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=\footnotesize\sffamily\bfseries,
     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)};
\end{scope}

% 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
\begin{scope}[
   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)};
\end{scope}

% 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
%\begin{scope}[on background layer]
 % \node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] {};
%\end{scope}


% 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) {
&&[1cm]|[keine,text width=0cm]| & keine Leistung \\
|[draw,minimum size=8pt]| & Allgemeine Diensptpflicht & |[finanziell,text width=0cm]| &finanzielle Ersatzgabe \\
};
% use fit again, to draw the surrounding frame
\node [draw,fit=(Armee)(EG)(m), inner sep=5mm] (frame) {};
\end{tikzpicture} 
\end{document}

enter image description here

ADDENDUM: Callouts from this answer.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\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]
\def\overlaynode<#1>#2;{
        \gdef\stacknodecommonpart{#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={
        \edef\pgf@marshal{\noexpand\node[#1]\stacknodecommonpart;}
        \pgf@marshal
    }
}
\def\overlaynodedrawfill{\pgfutil@ifnextchar[{\overlaynodedrawfill@opt}{\overlaynodedrawfill@opt[]}}
\def\overlaynodedrawfill@opt[#1]<#2>#3;{
    \begin{scope}[transparency group,draw=black,fill=white,line cap=round,line join=round,#1]
        \pgfmathsetmacro\pgflinewidthdouble{2\pgflinewidth}
        \overlaynode<#2>[draw=pgfstrokecolor,line width=\pgflinewidthdouble]#3;
        \overlaynode<#2>[fill=pgffillcolor]#3;
    \end{scope}
}
\makeatother


% from https://tex.stackexchange.com/a/432326/121799
\usetikzlibrary{decorations.pathreplacing,shadows.blur,shapes}
\tikzset{
  % styles to save the path in `\savedpath`
  add path/.style = {
    decoration={show path construction,
      moveto code={
        \xdef\savedpath{\savedpath (\tikzinputsegmentfirst)}
      },
      lineto code={
        \xdef\savedpath{\savedpath -- (\tikzinputsegmentlast)}
      },
      curveto code={
        \xdef\savedpath{\savedpath .. controls (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb) ..(\tikzinputsegmentlast)}
      },
      closepath code={
        \xdef\savedpath{\savedpath -- cycle}
      }
    },
    decorate
  },
  store path/.style = {add path},
  store path/.prefix code={\xdef\savedpath{}},
  % 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}
}
\begin{document}
\begin{tikzpicture}[
    font=\footnotesize\sffamily,
    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
    },
]


\begin{scope}[
   start chain=groups,
   node distance=-\pgflinewidth,
   every node/.append style={
     baserect,
     on chain, 
     font=\footnotesize\sffamily\bfseries,
     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)};
\end{scope}


\begin{scope}[
   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};
\end{scope}

% 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}
{\draw ($(groups-\Y.south east)!0.5!(groups-\X.south west)$) coordinate(aux)
-- (aux|-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) {
&&[0.5cm] |[persoenlich,text width=0cm]| & persönliche Dienstleistung \\
&& |[finanziell,text width=0cm]| &finanzielle Ersatzgabe \\
|[draw,minimum size=8pt]| & Sicherheitsdienstpflicht & |[keine,text width=0cm]| & keine Leistung \\
};


 \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};
\end{tikzpicture} 
\end{document}

enter image description here

  • 1
    Gruezi marmot, thank you for your answer and correcting persohnlich :) I use MiKTeX and TeXstudio, which works fine with Umlaute. – danik Sep 4 '18 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 '18 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. – user121799 Sep 6 '18 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. – user121799 Sep 6 '18 at 19:27
  • 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 '18 at 20:03
6

Regarding the enlargment of the frame and minor .north calls instead of new \coordinate definitions

\documentclass[border=5mm]{standalone}
    \usepackage{tikz}
    \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
    }
    \begin{document}
    \begin{tikzpicture}[
        font=\footnotesize\sffamily,
        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
        },
    ]


\begin{scope}[
   % 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=\footnotesize\sffamily\bfseries,
     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)};
\end{scope}

% 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
\begin{scope}[
   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)};
\end{scope}

% 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
%\begin{scope}[on background layer]
 % \node [fill=black!10, fit=(Zivilschutz)(EG), inner sep=3mm] {};
%\end{scope}


% 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) {
&&[1cm]|[keine,text width=0cm]| & keine Leistung \\
|[draw,minimum size=8pt]| & Allgemeine Diensptpflicht & |[finanziell,text width=0cm]| &finanzielle Ersatzgabe \\
};
\end{tikzpicture} 
\end{document}

enter image description here

  • 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 '18 at 18:21
  • @danik I added text width=1.7cm to the persohnlich style – BambOo Sep 3 '18 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.