我尝试采用以下解决方案(来自上一个问题) 到五个不同但非常相似的图表,效果很好。但是,我仍然有一些问题。
我该如何更改代码才能使各行位于一行?
与其中一个相同。
我需要在那里写一些文字。我尝试使用 \node 命令,但效果不佳。我需要使用哪个命令?
4.&5. 我应该在图表中做一些注释。我尝试用节点形状制作对话气泡,但没有成功。
\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}
如您所见,节点覆盖了文本。我该如何放大框架以使其适合?
\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}
感谢您的帮助!
编辑: 对于第二个问题,我尝试使用 marmot 的解决方案。其他图表我都运行良好。但是,有一个图表不起作用。我需要在代码中更正哪些地方才能使其正常工作?
\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}
答案1
土拨鼠发出咕噜声!;-)
针对您提出的上述问题,我将这样回答:
- 用来
fit
绘制上部组的边界并定义箭头的起点; - 添加一些辅助坐标,使下框与上框一样宽(=第 4 次编辑);
- 添加辅助坐标
h
并h'
用 添加文本edge["text",swap]
,其中swap
将文本位置从上到下交换; - 5. 使用Kpym 的非常酷且未被投票的呼吁,带有多个指针。我
cloudy
用一些可能更合适的东西替换了。
由于某种原因,变音符号没有显示,您使用的是哪个编译器?当然,当您编译代码时,它们会显示出来。(为了弥补这一点,我修正了“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}
第二次编辑:至于您的第二个问题,我只会将其包含matrix
在适合范围内。
\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}
附录:来自的标注这个答案。
\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}
答案2
关于扩大框架和次要.north
呼吁而不是新\coordinate
定义
\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}