我的问题很简单,但我找不到答案。上一个:
\usepackage{tikz}
\usetikzlibrary{matrix, shapes, arrows, positioning, fit, calc}
样式:
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=6em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=9em, text centered, rounded corners, minimum height=2.5em]
\tikzstyle{label} = [draw=white!0, minimum size=2ems]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\tikzstyle{box}=[rectangle,
thick,
minimum size=1cm,
draw=black!80,
fill=gray!01]
\tikzstyle{connector} = [->,thick]
\tikzstyle{pusty}=[draw=white, minimum size=2em]
我使用 myncbar 宏来创建类似 C 的形状:
\def\myarm{1cm}
\def\myangle{0}
\tikzset{
arm/.default=1cm,
arm/.code={\def\myarm{#1}}, % store value in \myarm
angle/.default=0,
angle/.code={\def\myangle{#1}} % store value in \myangle
}
\tikzset{
myncbar/.style = {to path={
% We need to calculate a couple of coordinates to help us draw
% the path.
let
% Same as (\tikztotarget)++(\myangle:\myarm)
\p1=($(\tikztotarget)+(\myangle:\myarm)$)
in
-- ++(\myangle:\myarm) coordinate (tmp)
% Find the projection of the (tmp) coordinate
% on the line from the target to p1
-- ($(\tikztotarget)!(tmp)!(\p1)$)
-- (\tikztotarget)\tikztonodes
}}
}
我的代码是:
\begin{figure}[H]
\begin{center}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [decision] (init) {Minął określony czas?};
\node [block, below of=init, node distance = 3cm] (oblicz) {Oblicz różnicę temperatur};
\node [decision, below of=oblicz, node distance=3.5cm] (roznica) {Róznica powyżej zadanego poziomu?};
\node [decision, below of=roznica, node distance=5.5cm] (otwarte) {Przepustnice otwarte maksymalnie i temperatura spada?};
\node [block, right of=otwarte, node distance=5.5cm] (ostrzezenie) {Wyświetl ostrzeżenie o kończącym się paliwie};
\node [block, below of=otwarte, node distance=4cm] (kat) {Oblicz kąt otwarcia przepustnic};
\node [block, below of=kat, node distance=2cm] (servo) {Ustaw serwomechanizmy};
\node [block, below of=servo, node distance=2cm] (koniec) {Koniec};
% Draw edges
\path [line] (init) -- node [near start] {Tak} (oblicz);
\path [line] (init.west) to[myncbar,angle=0,arm=-2cm] node [near start] {Nie} (koniec.west);
\path [line] (oblicz) -- (roznica);
\path [line] (roznica) -- node [near start] {Tak} (otwarte);
\path [line] (roznica.east) to[myncbar,angle=0,arm=6cm] node [near start] {Nie} (koniec.east);
\path [line] (otwarte) -- node [near start] {Tak} (ostrzezenie);
\path [line] (otwarte) -- node [near start] {Nie} (kat);
\path [line] (kat) -- (servo);
\path [line] (servo) -- (koniec);
\path [line] (ostrzezenie) -- (koniec);
\end{tikzpicture}
\caption{Algorytm obsługi kotła}
\end{center}
\end{figure}
我的问题就在这一行:
\path [line] (init.west) to[myncbar,angle=0,arm=-2cm] node [near start] {Nie} (koniec.west);
...
\path [line] (roznica.east) to[myncbar,angle=0,arm=6cm] node [near start] {Nie} (koniec.east);
文本标签不在开始处。它们位于最后的行。是否可以将它们放在靠近开始的位置第一的线?
答案1
我猜想很难轻易引用这种复合路径的第一部分。不过,您可以使用near start
第一部分的不可见副本。
你可以更换
\path [line] (roznica.east) to[myncbar,angle=0,arm=6cm]
node [near start] {Nie} (koniec.east);
经过
\path [line] (roznica.east) to[myncbar,angle=0,arm=6cm] (koniec.east);
\path (roznica.east) -- node [near start] {Nie} ++(6cm,0);