我正在尝试在决策节点旁边放置一个锚点,但是使用我当前的代码,它会将其放置在箭头的末尾。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{comment}
\usetikzlibrary{shapes.geometric,arrows}
\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=4cm ,minimum height=1cm, text centered, trapezium stretches=true, draw=black, fill = blue!30]
\tikzstyle{process}=[rectangle,minimum width=3cm,minimum height=1cm, text centered,text width = 4cm, draw=black, fill = orange!30]
\tikzstyle{decision} = [diamond,minimum width=3cm,minimum height=1cm, text centered, draw=black, fill = green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node(start)[startstop]{Start};
\node(mesh)[process,below of=start]{Form the Mesh};
\node(initialize_pot)[process,below of=mesh]{Initialize \\ potential using charge neutrality};
\node(initial_poisson_coeff)[process,below of=initialize_pot,yshift=-0.7cm]{Calculate the poisson coefficients and the forcing function using the initialized potential};
\node(solve_poisson_firsttime)[process,below of=initial_poisson_coeff,yshift=-0.5cm]{Solve the \\ poisson equation};
\node(first_potential)[io,below of=solve_poisson_firsttime,yshift=0.1cm]{Potential Profiles};
\node(schrodinger_solver)[process,right of=start,xshift=8cm]{Solve the schr\"{o}dinger equation using potential profile};
\node(wavefunctions)[io,below of=schrodinger_solver]{Wavefunctions and Energies};
\node(electron_density)[process,below of=wavefunctions] {Calculate \\ electron density in the schrodinger domain};
\node(update_poisson_coefficients)[process,below of = electron_density,yshift=-1.7cm]{Use wavefunctions and eigen energies to update the central coefficients and forcing function of the grid points in the schrodinger domain. For the other points, use potential from previous iteration};
\node(solve_poisson)[process,below of=update_poisson_coefficients,yshift=-1.5cm]{solve poisson equation};
\node(converged_check)[decision, below of=solve_poisson, yshift=-0.5cm] {Converged?};
\node(stop)[startstop,below of=converged_check,yshift=-0.5cm]{Stop};
\draw[arrow](start)--(mesh);
\draw[arrow](mesh)--(initialize_pot);
\draw[arrow](initialize_pot)--(initial_poisson_coeff);
\draw[arrow](initial_poisson_coeff)-- (solve_poisson_firsttime);
\draw[arrow](solve_poisson_firsttime)--(first_potential);
\draw[arrow] (first_potential) - ++(5,0) -- ++(5,11) -- (schrodinger_solver);
\draw[arrow](schrodinger_solver)--(wavefunctions);
\draw[arrow](wavefunctions)--(electron_density);
\draw[arrow](electron_density) -- (update_poisson_coefficients);
\draw[arrow](update_poisson_coefficients) -- (solve_poisson);
\draw[arrow](solve_poisson) -- (converged_check);
\draw[arrow](converged_check)- ++(4,0) -- ++(4,13.75) --node[anchor=north] {no} (schrodinger_solver);
\draw[arrow](converged_check) --node[anchor = east] {yes} (stop);
\begin{comment}
\draw[arrow](proc2b)|-(proc1);
\draw[arrow](out1)--(stop);
\end{comment}
\end{tikzpicture}
\end{document}
我怎样才能做到这一点?
答案1
我想你想要
\draw[arrow](converged_check) -- node[above] {no} ++(4,0) |- schrodinger_solver);
这会将该节点放置在路径第一段的中间,即离开收敛节点的水平部分。
如果您希望它位于路径垂直部分的中间,请使用
\draw[arrow](converged_check) -- ++(4,0) |- node[pos=0.25,left] {no} (schrodinger_solver);
关键pos
在于将节点定位在路径上的相对位置。使用垂直路径规范(如我在此处所做的那样)(即(a) |- (b)
,参见TikZ:箭头的 |- 符号到底起什么作用?) 是一个特例,那么它pos=0.5
总是对应于路径的拐角,所以pos=0.25
位于第一条线段的中间。
附带说明一下,你使用了一些过时的语法,尤其是right of=
etc. 和\tikzstyle
。对于前者,建议加载positioning
库并使用right=of
,但请注意,行为略有不同。请参阅PGF/TikZ 中“right of=”和“right=of”之间的区别 对于后者,建议使用\tikzset{foo/.style={...}, bar/.style={...}}
。(也许今天晚上晚些时候可以举一个例子,现在没有时间。)
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{comment}
\usetikzlibrary{shapes.geometric,arrows}
\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=4cm ,minimum height=1cm, text centered, trapezium stretches=true, draw=black, fill = blue!30]
\tikzstyle{process}=[rectangle,minimum width=3cm,minimum height=1cm, text centered,text width = 4cm, draw=black, fill = orange!30]
\tikzstyle{decision} = [diamond,minimum width=3cm,minimum height=1cm, text centered, draw=black, fill = green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node(start)[startstop]{Start};
\node(mesh)[process,below of=start]{Form the Mesh};
\node(initialize_pot)[process,below of=mesh]{Initialize \\ potential using charge neutrality};
\node(initial_poisson_coeff)[process,below of=initialize_pot,yshift=-0.7cm]{Calculate the poisson coefficients and the forcing function using the initialized potential};
\node(solve_poisson_firsttime)[process,below of=initial_poisson_coeff,yshift=-0.5cm]{Solve the \\ poisson equation};
\node(first_potential)[io,below of=solve_poisson_firsttime,yshift=0.1cm]{Potential Profiles};
\node(schrodinger_solver)[process,right of=start,xshift=6cm]{Solve the schr\"{o}dinger equation using potential profile};
\node(wavefunctions)[io,below of=schrodinger_solver]{Wavefunctions and Energies};
\node(electron_density)[process,below of=wavefunctions] {Calculate \\ electron density in the schrodinger domain};
\node(update_poisson_coefficients)[process,below of = electron_density,yshift=-1.7cm]{Use wavefunctions and eigen energies to update the central coefficients and forcing function of the grid points in the schrodinger domain. For the other points, use potential from previous iteration};
\node(solve_poisson)[process,below of=update_poisson_coefficients,yshift=-1.5cm]{solve poisson equation};
\node(converged_check)[decision, below of=solve_poisson, yshift=-0.5cm] {Converged?};
\node(stop)[startstop,below of=converged_check,yshift=-0.5cm]{Stop};
\draw[arrow](start)--(mesh);
\draw[arrow](mesh)--(initialize_pot);
\draw[arrow](initialize_pot)--(initial_poisson_coeff);
\draw[arrow](initial_poisson_coeff)-- (solve_poisson_firsttime);
\draw[arrow](solve_poisson_firsttime)--(first_potential);
\draw[arrow] (first_potential) -- ++(4,0) |- (schrodinger_solver);
\draw[arrow](schrodinger_solver)--(wavefunctions);
\draw[arrow](wavefunctions)--(electron_density);
\draw[arrow](electron_density) -- (update_poisson_coefficients);
\draw[arrow](update_poisson_coefficients) -- (solve_poisson);
\draw[arrow](solve_poisson) -- (converged_check);
\draw[arrow](converged_check) -- node[above] {no} ++(4,0) |- (schrodinger_solver);
% or this:
%\draw[arrow](converged_check) -- ++(4,0) |- node[pos=0.25,left] {no} (schrodinger_solver);
\draw[arrow](converged_check) --node[anchor = east] {yes} (stop);
\begin{comment}
\draw[arrow](proc2b)|-(proc1);
\draw[arrow](out1)--(stop);
\end{comment}
\end{tikzpicture}
\end{document}
编辑:
yshift
如上所述,以下是更现代化的代码版本。请注意,使用时无需使用或类似方法调整节点间距below=of ..
,因为间距是在节点边缘之间计算的,而不是中心点之间计算的。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{
shapes.geometric,
arrows.meta, % not actually used, but supersedes the old arrows library
positioning,
}
\tikzset{
startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill = red!30},
io/.style={trapezium, trapezium left angle = 70, trapezium right angle = 110, minimum width=4cm ,minimum height=1cm, text centered, trapezium stretches=true, draw=black, fill = blue!30},
process/.style={rectangle,minimum width=3cm,minimum height=1cm, text centered,text width = 4cm, draw=black, fill = orange!30},
decision/.style={diamond,minimum width=3cm,minimum height=1cm, text centered, draw=black, fill = green!30},
arrow/.style={thick,->,>=stealth}
}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node (start) [startstop] {Start};
\node (mesh) [process,below=of start]{Form the Mesh};
\node (initialize_pot) [process,below=of mesh] {Initialize \\ potential using charge neutrality};
\node (initial_poisson_coeff) [process,below=of initialize_pot] {Calculate the poisson coefficients and the forcing function using the initialized potential};
\node (solve_poisson_firsttime) [process,below=of initial_poisson_coeff] {Solve the \\ poisson equation};
\node (first_potential) [io,below=of solve_poisson_firsttime] {Potential Profiles};
\node (schrodinger_solver) [process,right=3cm of start] {Solve the schr\"{o}dinger equation using potential profile};
\node (wavefunctions) [io,below=of schrodinger_solver] {Wavefunctions and Energies};
\node (electron_density) [process,below=of wavefunctions] {Calculate \\ electron density in the schrodinger domain};
\node (update_poisson_coefficients) [process,below=of electron_density] {Use wavefunctions and eigen energies to update the central coefficients and forcing function of the grid points in the schrodinger domain. For the other points, use potential from previous iteration};
\node (solve_poisson)[process,below=of update_poisson_coefficients] {solve poisson equation};
\node (converged_check) [decision, below=of solve_poisson] {Converged?};
\node (stop) [startstop,below=of converged_check] {Stop};
\draw[arrow] (start) -- (mesh);
\draw[arrow] (mesh) -- (initialize_pot);
\draw[arrow] (initialize_pot) -- (initial_poisson_coeff);
\draw[arrow] (initial_poisson_coeff) -- (solve_poisson_firsttime);
\draw[arrow] (solve_poisson_firsttime) -- (first_potential);
\draw[arrow] (first_potential) -- ++(3,0) |- (schrodinger_solver);
\draw[arrow] (schrodinger_solver) -- (wavefunctions);
\draw[arrow] (wavefunctions) -- (electron_density);
\draw[arrow] (electron_density) -- (update_poisson_coefficients);
\draw[arrow] (update_poisson_coefficients) -- (solve_poisson);
\draw[arrow] (solve_poisson) -- (converged_check);
\draw[arrow] (converged_check) -- node[above] {no} ++(3,0) |- (schrodinger_solver);
% or this:
%\draw[arrow](converged_check) -- ++(4,0) |- node[pos=0.25,left] {no} (schrodinger_solver);
\draw[arrow](converged_check) --node[anchor = east] {yes} (stop);
\end{tikzpicture}
\end{document}