我目前正在使用 Tikz 绘制通量图。您知道如何在箭头下方放置字母“Sim”(是)和“Não”(否)吗?
谢谢。
我的MWE
\documentclass[11pt]{report}
% Fluxograma
\usepackage{tikz}
%\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{arrows, positioning, shapes.geometric}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}[node distance=1.5cm]
\centering
\node (start) [startstop] {Início do Processamento};
\node (pro2a) [process, below of=start] {Definir os Métodos de Solução};
\draw [arrow] (start) -- (pro2a);
\node (pro2b) [process, below of=pro2a] {Definir os Controlos da Solução};
\draw [arrow] (pro2a) -- (pro2b);
\node (pro2c) [process, below of=pro2b] {Definir os Monitores da Solução};
\draw [arrow] (pro2b) -- (pro2c);
\node (pro2d) [process, below of=pro2c] {Inicializar a Simulação};
\draw [arrow] (pro2c) -- (pro2d);
\node (pro2e) [process, below of=pro2d] {Efetuar o cálculo numérico};
\draw [arrow] (pro2d) -- (pro2e);
\node (dec1) [decision, below of=pro2e, yshift=-2cm] {Verificar convergência};
\node (pro2f) [process, right of=dec1, xshift=7cm] {Modificar paramêtros da malha ou da Solução};
\draw [arrow] (pro2e) -- (dec1);
\draw [arrow] (dec1) -- node[anchor=east] {Não} (pro2f);
\node (dec2) [decision, below of=dec1, yshift=-3.5cm] {Verificar Exactidão};
\draw [arrow] (dec1) -- node[anchor=south] {Sim} (dec2);
% \draw [arrow] (dec2) -- node[anchor=south] {yes} (stop);
\node (stop) [startstop, below of=dec2, yshift=-2cm] {Fim do Processamento};
\draw [arrow] (dec2) -- node[anchor=south] {Sim} (stop);
\draw [arrow] (dec2) -| node[anchor=east] (-1,0) {Não} (pro2f);
%\node (out1) [io, below of=pro2a] {Output};
\end{tikzpicture}
\caption[Propriedades Físicas de um escoamento]{Propriedades Físicas de um escoamento, retirado de \cite{Tu2013}.}
\label{flux:fluxograma}
\end{figure}
答案1
为了说明如何以更简洁的方式编写这个简单的流程图,以及如何使用正确的语法进行定位(不是... of= ...
而是...=of ...
使用positioning
库),而不是过时的\tikzstyle
使用,并且对于有更多预定义样式的情况,我建议给专用于绘制流程图的\tikzset
名称。\tikzset
在下面的 MWE 中,使用了另外两个库:chains
和quotes
分别用于定位节点和标记边。对于箭头,我建议使用arrows.meta
库而不是arrows
。对于简单的节点连接(不标记边),使用join
宏非常方便,我将其添加到base
节点定义中:
\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, chains, positioning, quotes, shapes.geometric}
\makeatletter % because join reset definition contain @
\tikzset{flowchart/.style={
base/.style = {draw, text width=42mm, minimum height=1cm,
align=flush center, on chain, join=by arrow},
startstop/.style = {base, rounded corners, fill=red!30},
io/.style = {trapezium,
trapezium left angle=70, trapezium right angle=110,
trapezium stretches=true,
base, fill=blue!30},
process/.style = {base, fill=orange!30},
decision/.style = {diamond, draw, minimum width=1cm, aspect=1.5,
align=center, fill=green!30, on chain, join=by arrow},
arrow/.style = {semithick,-Stealth},
join reset/.code = {\def\tikz@after@path{}} % for disconnecting of join arrows between nodes
},
}% end of tikzset
\makeatother
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[flowchart,
node distance = 6mm and 12mm,
start chain = going below
]
\node (start) [startstop] {Início do Processamento};
\node (pro2a) [process] {Definir os Métodos de Solução};
\node (pro2b) [process] {Definir os Controlos da Solução};
\node (pro2c) [process] {Definir os Monitores da Solução};
\node (pro2d) [process] {Inicializar a Simulação};
\node (pro2e) [process] {Efetuar o cálculo numérico};
\node (dec1) [decision] {Verificar convergência};
\node (dec2) [decision] {Verificar Exactidão};
\node (stop) [startstop] {Fim do Processamento};
%
\node (pro2f) [process, join reset,
right=of dec1] {Modificar paramêtros da malha ou da Solução};
%
\draw [arrow] (dec1) to ["Sim"] (dec2);
\draw [arrow] (dec2) to ["Sim"] (stop);
\draw [arrow] (pro2f) |- (pro2e);
\draw [arrow] (dec1) to ["Não"] (pro2f);
\draw [arrow] (dec2) -| node[right] {Não} (pro2f);
\end{tikzpicture}
\caption[]{my caption}
\label{flux:fluxograma_Fase_de_Processamento}
\end{figure}
\end{document}
如您所见,我略微改变了流程图样式。现在所有元素的宽度都相同,并且在某些情况下,当文本长度超过节点宽度时,它会被分成更多(两)行。如果您不喜欢这样,只需将base/.style
选项替换text width
为minimum width
并删除即可align=flush center
。
答案2
Torbjorn T.,是的。谢谢你的帮助!我使用东、南、西来解决问题
现在结果:
\documentclass[11pt]{report}
% Fluxograma
\usepackage{tikz}
%\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{arrows, positioning, shapes.geometric}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}[node distance=1.5cm]
\centering
\node (start) [startstop] {Início do Processamento};
\node (pro2a) [process, below of=start] {Definir os Métodos de Solução};
\draw [arrow] (start) -- (pro2a);
\node (pro2b) [process, below of=pro2a] {Definir os Controlos da Solução};
\draw [arrow] (pro2a) -- (pro2b);
\node (pro2c) [process, below of=pro2b] {Definir os Monitores da Solução};
\draw [arrow] (pro2b) -- (pro2c);
\node (pro2d) [process, below of=pro2c] {Inicializar a Simulação};
\draw [arrow] (pro2c) -- (pro2d);
\node (pro2e) [process, below of=pro2d] {Efetuar o cálculo numérico};
\draw [arrow] (pro2d) -- (pro2e);
\node (dec1) [decision, below of=pro2e, yshift=-2cm] {Verificar convergência};
\node (pro2f) [process, right of=dec1, xshift=7cm] {Modificar paramêtros da malha ou da Solução};
\draw [arrow] (pro2e) -- (dec1);
\draw [arrow] (pro2f) |- (pro2e);
\draw [arrow] (dec1) -- node[anchor=south] {Não} (pro2f);
\node (dec2) [decision, below of=dec1, yshift=-3.5cm] {Verificar Exactidão};
\draw [arrow] (dec1) -- node[anchor=east] {Sim} (dec2);
% \draw [arrow] (dec2) -- node[anchor=south] {yes} (stop);
\node (stop) [startstop, below of=dec2, yshift=-2cm] {Fim do Processamento};
\draw [arrow] (dec2) -- node[anchor=east] {Sim} (stop);
**\draw [arrow] (dec2) -| node[anchor=west] {Não} (pro2f);**
%\node (out1) [io, below of=pro2a] {Output};
\end{tikzpicture}
\caption[]
\label{flux:fluxograma_Fase_de_Processamento}
\end{figure}
答案3
您可以链接样式定义,从而轻松一致地更改流程图的格式。
梅威瑟:
\documentclass[11pt]{report}
% Fluxograma
\usepackage{tikz}
%\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{arrows, positioning, shapes.geometric}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\tikzstyle{nodestyle} = [near start] % <--- added
\tikzstyle{yesnode} = [nodestyle,xshift=1em] % <--- added
\tikzstyle{nonode} = [nodestyle,yshift=-1em] % <--- added
\begin{document}
\begin{figure}[h!]
\centering
\begin{tikzpicture}[node distance=1.5cm]
\centering
\node (start) [startstop] {Início do Processamento};
\node (pro2a) [process, below of=start] {Definir os Métodos de Solução};
\draw [arrow] (start) -- (pro2a);
\node (pro2b) [process, below of=pro2a] {Definir os Controlos da Solução};
\draw [arrow] (pro2a) -- (pro2b);
\node (pro2c) [process, below of=pro2b] {Definir os Monitores da Solução};
\draw [arrow] (pro2b) -- (pro2c);
\node (pro2d) [process, below of=pro2c] {Inicializar a Simulação};
\draw [arrow] (pro2c) -- (pro2d);
\node (pro2e) [process, below of=pro2d] {Efetuar o cálculo numérico};
\draw [arrow] (pro2d) -- (pro2e);
\node (dec1) [decision, below of=pro2e, yshift=-2cm] {Verificar convergência};
\node (pro2f) [process, right of=dec1, xshift=7cm] {Modificar paramêtros da malha ou da Solução};
\draw [arrow] (pro2e) -- (dec1);
\draw [arrow] (dec1) -- node[nonode] {Não} (pro2f); % <--- using nodestyle "nonode"
\node (dec2) [decision, below of=dec1, yshift=-3.5cm] {Verificar Exactidão};
\draw [arrow] (dec1) -- node[yesnode] {Sim} (dec2); % <--- using nodestyle "yesnode"
% \draw [arrow] (dec2) -- node[anchor=south] {yes} (stop);
\node (stop) [startstop, below of=dec2, yshift=-2cm] {Fim do Processamento};
\draw [arrow] (dec2) -- node[yesnode] {Sim} (stop);
\draw [arrow] (dec2) -| node[nonode] (-1,0) {Não} (pro2f);
%\node (out1) [io, below of=pro2a] {Output};
\end{tikzpicture}
\caption[Propriedades Físicas de um escoamento]{Propriedades Físicas de um escoamento, retirado de \cite{Tu2013}.}
\label{flux:fluxograma}
\end{figure}
\end{document}