我正在尝试找到动态定位蓝色路径的最佳方法。 重要的是它相对于b
和 的位置c
。 我目前正在使用\path [line,blue] let \p1=(a.south), \p2=(c) in (h.south) |- +(2,-0.5) |- (\x2, \y1) -- (c.north);
蓝色路径,但它确实没有给我太多的动态控制。
我曾考虑尝试添加几个 let 点并取其 x 值的中间值,但我似乎不知道该怎么做。它看起来像:\path [line,blue] let \p1=(a.south), \p2=(c), \p3=(b.east), \p4=(c.west) in (h.south) -| +( AAA , -0.5) |- (\x2, \y1) -- (c.north);
其中AAA
会是类似($(\x3 !0.25! \x4)$)
或的东西,(\x3 + \x4)*0.75
但这确实看起来像是一种笨拙的方法。
那么,绘制此路径的最佳方法是什么,以便它可以动态缩放?
也欢迎任何关于改善红色路径的建议。
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\pagestyle{empty}
\begin{document}
%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning}
% Define block styles
\tikzstyle{state} = [ rounded rectangle,
draw,
text centered,
minimum height=3em
]
\tikzstyle{test} = [ diamond,
draw,
shape aspect=2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action} = [ rectangle, draw,
text width=8em,
inner sep = 5pt,
minimum height=5em
]
\tikzstyle{line} = [ draw, -triangle 45 ]
\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
% Place nodes
\matrix [column sep = 3em, row sep = 1.2em] (mtrx)
{
\node [state] (a) {a};\\
\node [action] (b) {b}; &
\node [test] (c) {c}; \\
\node [action] (d) {d}; &
&
\node [action] (e) {e}; \\
\node [action] (f) {f}; &
&
\node [action] (g) {g}; \\
\node [action] (h) {h}; \\
};
% Draw edges
\path [line, red] (c.west) -- ($(b.east)!0.75!(c.west)$) |- ($(e.south)!0.5!(g.north)$);
%\path [line, red] let \p1=(e), \p2=(f), \p3=(c.west), \p4=(b.east) in (c.west) -- ($(\x3, \y3)!0.25!(\x4, \y3)$) |- ($(\x1, \y1)!0.5!(\x1, \y2)$); %alt
\path [line,blue] let \p1=(a.south), \p2=(c) in (h.south) |- +(2,-0.5) |- (\x2, \y1) -- (c.north);
\end{tikzpicture}
\end{center}
\end{document}
答案1
尝试这个
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=0.5in]{geometry}
\pagestyle{empty}
\begin{document}
%\input{../tikz-setup.tex}
\usetikzlibrary{shapes, arrows, calc, positioning}
% Define block styles
\tikzstyle{state} = [ rounded rectangle,
draw,
text centered,
minimum height=3em
]
\tikzstyle{test} = [ diamond,
draw,
shape aspect=2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action} = [ rectangle, draw,
text width=8em,
inner sep = 5pt,
minimum height=5em
]
\tikzstyle{line} = [ draw, -triangle 45 ]
\begin{center}
\begin{tikzpicture}[align = flush center, font = \small]
% Place nodes
\matrix [column sep =5em, row sep = 2em] (mtrx)
{
\node [state] (a) {a};\\
\node [action] (b) {b}; &
\node [test] (c) {c}; \\
\node [action] (d) {d}; &
&
\node [action] (e) {e}; \\
\node [action] (f) {f}; &
&
\node [action] (g) {g}; \\
\node [action] (h) {h}; \\
};
% Draw edges
\path [line, red] (c.west) -- ($(b.east)!0.75!(c.west)$) |- ($(e.south)!0.5!(g.north)$);
\path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ;
\path[line,blue] (h.south) |- ($(h.south east) +(0,-0.5)$) -| (xx) -- (a.south-|xx) -|(c.north);
\end{tikzpicture}
\end{center}
\end{document}
拉利涅
\path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ;
允许在两个疑点(b)和(c)之间创建一个中间点。我不再依赖这些观点
线路
\path (b.east) -- (b.east-|c.west)coordinate[pos=0.25](xx) ;
在两个节点(b)
和之间创建一个中间点(c)
。剩下的步骤就是连接这些点。