下面是我的初始乳胶代码,但我无法正确更改形状、块的颜色和重定向箭头。有人请帮忙。谢谢
\documentclass{article}
\usepackage{geometry}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
%\pagestyle{empty}%
%\noindent
\begin{tikzpicture}[node distance =0.8cm, auto]
% Define block styles
\tikzset{block/.style={rectangle, draw, fill=blue!20,
text width=15em, text centered, rounded corners, minimum height=4em},
line/.style={draw, -latex'}}
% Place nodes
\node [block] (inputdata) {Read input data};
\node [block, below=of inputdata] (initialchecks) {Initial checks and calculation of means and standard deviations};
\node [block,below=of initialchecks] (stage1) {Stage 1:SNHT applied on stepped overlapping windows
};
\node [block,below=of stage1] (stage2) {Stage 2:SNHT applied on the whole series
};
\node [block,below=of stage2] (stage3) {Stage 3:In-filling of all missing data
};
\node [block, below =of stage3] (writehomo) {Write homogeneous files, graphics and other outputs};
\node [block, below right=of inputdata] (normalize) {Normalize series with their means and standard devaitions};
\node [block, below= of normalize] (estimate) {Estimate all series from their neighbours and normalize
};
\node [block,below= of estimate] (anomalies) {Compute anomalies(observed - estimated) and remove outliers};
\node [block, below=of anomalies] (infill) {In-fill missing data and compute new means and standard deviations};
\node [block, below=of infill] (yesno) {Did any means change? };
;
\node [block, right=of normalize] (ifstage3) {If stage 3 return };
\node [block, below=of ifstage3 ] (compute) {Compute SNHT of all series };
;
\node [block, below=of compute] (max) {If maximum SNHT or lower than threshold return};
;
\node [block, below=of max] (split) {Split series with higher SNHT break points};
;
% Draw edges
\path [line] (inputdata) -- (initialchecks);
\path [line] (initialchecks) -- (stage1);
\path [line] (stage1) -- (stage2);
\path [line] (stage2) -- (stage3);
\path [line] (stage3) -- (writehomo);
\path [line] (stage1) -- (normalize);
\path [line] (normalize) -- (estimate);
\path [line] (estimate) -- (anomalies);
\path [line] (anomalies) -- (infill);
\path [line] (infill) -- (yesno);
\path [line] (yesno) -- (ifstage3);
\path [line] (ifstage3) -- (compute);
\path [line] (compute) -- (max);
\path [line] (max) -- (split);
\path [line] (split) -- (normalize);
\path [line] (stage2) -- (normalize);
\path [line] (yesno) -- (normalize);
\end{tikzpicture}
\end{document}
答案1
像这样?
通过使用tikz
库chains
及其宏,join
我可以大大缩短您的代码:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
chains,
positioning,
shapes.geometric}
\makeatletter
\tikzset{suspend join/.code={\def\tikz@after@path{}}}
\makeatother
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 30mm,
start chain = A going below,
base/.style = {draw, text width=32mm, minimum height=8mm,
font=\small\sffamily, align=center, on chain=A, join=by -Stealth},
startstop/.style = {base, rounded corners, fill=red!30},
process/.style = {base, rectangle, fill=#1},
io/.style = {base, trapezium, trapezium stretches,
trapezium left angle=70, trapezium right angle=110,
fill=blue!30},
decision/.style = {base, text width=24mm, diamond, aspect=1.2,
fill=#1, inner xsep=0pt},
decision/.default = yellow!30,
every path/.style = {draw, -Stealth},
]
% Place nodes
\begin{scope}[process/.default = blue!20]
\node [io] {Read input data}; % A-1
\node [process] {Initial checks and calculation of means and standard deviations};
\node [process] {Stage 1: SNHT applied on stepped overlapping windows};
\node [process] {Stage 2: SNHT applied on the whole series};
\node [process] {Stage 3: In-filling of all missing data};
\node [process] {Write homogeneous files, graphics and other outputs}; % A-6
\end{scope}
\begin{scope}[process/.default = yellow!20]
\node [process, suspend join,
below right=of A-1] {Normalize series with their means and standard devaitions}; % A-7
\node [process] {Estimate all series from their neighbours and normalize};
\node [process] {Compute anomalies(observed - estimated) and remove outliers};
\node [process] {In-fill missing data and compute new means and standard deviations};
\node [decision] {Did any means change?};
\node [decision, suspend join,
right=22mm of A-8] {If stage 3 return }; % A-12
\node [process] {Compute SNHT of all series };
\node [decision] {If max. SNHT or lower than threshold return};
\node [process] {Split series with higher SNHT break points}; % A-15
\end{scope}
% Draw edges
\path (A-3.east) -- ++ (0.3,0) |- ([yshift= 3mm] A-7);
\path (A-4.east) -- ++ (0.4,0) |- ([yshift= 1mm] A-7);
\path (A-5.east) -- ++ (0.5,0) |- ([yshift=-1mm] A-7);
%
\path (A-11.west) -- ++ (-0.6,0) node[above right] {Yes} |- ([yshift=-3mm] A-7);
%
\path (A-11.east) -- ++ ( 0.6,0) node[above left] {No} |- (A-12);
%
\path (A-15.east) -- ++ (1,0) |- (A-7);
\end{tikzpicture}
\end{document}
节点之间的连接由宏绘制join
。它们在每个分支之间以样式分支中断,suspend join
并且分支之间的节点也单独绘制。它们使用正交坐标|-
(先垂直绘制,然后水平绘制),例如
\path (A-15.east) -- ++ (1,0) |- (A-7);
对于节点名称,使用从到chains
库定义的名称。A-1
A-15
答案2
虽然不是非常高效,但是是一个开始......
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,positioning}
\begin{document}
\begin{tikzpicture}[node distance =0.8cm, auto]
% Define block styles
\tikzset{
block/.style={draw, text width=15em, text centered, rounded corners, minimum height=4em},
bblock/.style={block, fill=blue!20},
yblock/.style={block, fill=yellow!20},
line/.style={draw, -latex'},
my trapezium/.style={trapezium, text width=12.5em, trapezium stretches, trapezium left angle=60, trapezium right angle=120},
my diamond/.style={diamond, aspect=1.5, text width=10em}
}
% Place nodes
\node [bblock, my trapezium] (inputdata) {Read input data};
\node [bblock, below=of inputdata] (initialchecks) {Initial checks and calculation of means and standard deviations};
\node [bblock,below=of initialchecks] (stage1) {Stage 1:SNHT applied on stepped overlapping windows
};
\node [bblock,below=of stage1] (stage2) {Stage 2:SNHT applied on the whole series
};
\node [bblock,below=of stage2] (stage3) {Stage 3:In-filling of all missing data
};
\node [bblock, below =of stage3, my trapezium] (writehomo) {Write homogeneous files, graphics and other outputs};
\node [yblock, right=of inputdata] (normalize) {Normalize series with their means and standard devaitions};
\node [yblock, below= of normalize] (estimate) {Estimate all series from their neighbours and normalize
};
\node [yblock,below= of estimate] (anomalies) {Compute anomalies(observed - estimated) and remove outliers};
\node [yblock, below=of anomalies] (infill) {In-fill missing data and compute new means and standard deviations};
\node [yblock, below=of infill, my diamond, text width=7.5em] (yesno) {Did any means change? };
;
\node [yblock, right=75pt of normalize.south east, my diamond, anchor=north west, text width=5em] (ifstage3) {If stage 3 return };
\node [yblock, below=of ifstage3 ] (compute) {Compute SNHT of all series };
;
\node [yblock, below=of compute, my diamond] (max) {If maximum SNHT or lower than threshold return};
;
\node [yblock, below=of max] (split) {Split series with higher SNHT break points};
;
% Draw edges
\path [line] (inputdata) -- (initialchecks);
\path [line] (initialchecks) -- (stage1);
\path [line] (stage1) -- (stage2);
\path [line] (stage2) -- (stage3);
\path [line] (stage3) -- (writehomo);
\path [line] (stage1.east) -- +(2.5pt,0) |- ([yshift=5pt]normalize);
\path [line] (normalize) -- (estimate);
\path [line] (estimate) -- (anomalies);
\path [line] (anomalies) -- (infill);
\path [line] (infill) -- (yesno);
\path [line] (yesno.east) -- +(22pt,0) node [midway,above] {No} |- (ifstage3);
\path [line] (ifstage3) -- (compute);
\path [line] (compute) -- (max);
\path [line] (max) -- (split);
\path [line] (split.east) -- +(5pt,0) |- (normalize);
\path [line] (stage2.east) -- +(5pt,0) |- (normalize);
\path [line] (stage3.east) -- +(7.5pt,0) |- ([yshift=-5pt]normalize);
\path [line] (yesno.west) -- +(-21pt,0) node [midway,above] {Yes} |- ([yshift=-7.5pt]normalize);
\end{tikzpicture}
\end{document}
你可以使用chains
库来简化这一过程,特别是当你有多个任务要做的时候。它似乎被那些graphs
东西弃用了,但实际上并没有被取代,而且通常可以完成这项工作。