我想在流程图中连接“框”,箭头从框内开始。经过反复试验后,使用“硬编码”坐标这样做似乎非常繁琐。有没有一种有效的方法来生成:
目前我有:
由此产生:
%% PREAMBLE %%
\documentclass[11pt, twoside, openany]{memoir}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\tikzstyle{block} = [rectangle, draw, fill=blue!0, text width=12em, text centered, rounded corners, minimum height=2em]
\tikzstyle{smallblock} = [rectangle, draw, fill=blue!0, text width=9em, text centered, rounded corners, minimum height=2em]
\begin{tikzpicture}[node distance = 2cm, auto]
\node [block] at (0, 0) (init) {};
\node [block] at (-2, -1.5) (identify) {};
\node [smallblock] at (-1.5, -3.5) (excellence) {};
\node [block] at (3, -1.5) (pass) {};
\node [block] at (3, -3.5) (fail) {};
\draw[->] (-0.2, -1.5) -- +(0, 1.1) [above];
\draw[->] (-0.2, -1.5) -- +(1, 0) [above];
\draw[||||||->] (-2.2, -3.2) -- +(0, 1.2) [above];
\end{tikzpicture}
\end{document}
最后,我怎样才能将一个小的实心正方形作为箭尾?(也就是说,而不是\draw[||||||->]
)。
答案1
您可以获得所需图形的宽度:
\documentclass[11pt,tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\tikzstyle{smallblock} = [rectangle, draw, fill=blue!0, text width=9em, text centered, rounded corners, minimum height=2em]
\begin{tikzpicture}[
node distance = 2cm, auto,
block/.style = {draw, fill=blue!0,%rounded corners,
text width=12em, minimum height=2em, align=center},
smallblock/.style = {draw, fill=blue!0,%rounded corners,
text width=9em, minimum height=2em, align=center},
Line/.style = {{Square[length=4pt,width=4pt]}-%
{Straight Barb[length=4pt]},
shorten <=-2pt},
]
\node[block] at (0, 0) (init) {init};
\node[block] at (-2,-1.5) (identify) {identify};
\node[smallblock] at (-1.5,-3.5) (excellence) {excelence};
\node[block] at (3.5, -1.5) (pass) {pass};
\node[block] at (3.5, -3.0) (fail) {fail};
\draw[Line] (excellence.north -| identify) -- (identify);
\draw[Line] ([yshift=5pt] fail.west) -| (init);
\draw[Line] (init |- pass) -- (pass);
%
\draw[{Square[length=4pt,width=4pt]}-]%is square this necessary?
([xshift=-2pt,yshift=5pt] init |- fail) -- + (2pt,0);
\end{tikzpicture}
\end{document}
但如果您按照@Gonzalo Medina 在其回答中提出的建议放置块,效果会更好。在这种情况下,代码更简单、更合乎逻辑:
\documentclass[11pt,tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\tikzstyle{smallblock} = [rectangle, draw, fill=blue!0, text width=9em, text centered, rounded corners, minimum height=2em]
\begin{tikzpicture}[
block/.style = {draw, fill=blue!0,%rounded corners,
text width=12em, minimum height=2em, align=center},
smallblock/.style = {draw, fill=blue!0,%rounded corners,
text width=9em, minimum height=2em, align=center},
Line/.style = {{Square[length=4pt,width=4pt]}-%
{Straight Barb[length=4pt]},
shorten <=-2pt},
]
\node[block] at (0,0) (init) {init};
\node[block,below left=1cm and 0.5cm of init.south] (iden) {identify};
\node[smallblock,
below left=1cm and 0cm of iden.south east] (excel) {excelence};
\node[block,below right=1cm and 0.5cm of init.south] (pass) {pass};
\node[block,below=of pass] (fail) {fail};
\draw[Line] (excel.north -| iden) -- (iden);
\draw[Line] (fail.west) -| (init);
\draw[Line] (init |- pass) -- (pass);
\end{tikzpicture}
\end{document}
答案2
代码:
\documentclass[11pt, twoside, openany]{memoir}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows,arrows.meta}
\begin{document}
\tikzset{
block/.style={
rectangle,
draw,
fill=blue!0,
text width=12em,
text centered,
rounded corners,
minimum height=2em
},
smallblock/.style={
rectangle,
draw,
fill=blue!0,
text width=9em,
text centered,
rounded corners,
minimum height=2em
},
arro/.style={{Square[]->}}
}
\begin{tikzpicture}[node distance = 1.2cm]
\node [block] (init) {ini};
\node [block,below=of init,anchor=east,xshift=-20pt] (identify) {iden};
\node [smallblock,below=of identify.south east,anchor=east] (excellence) {exce};
\node [block,below=of init,anchor=west,xshift=20pt] (pass) {pass};
\node [block,below=of pass.south west,anchor=west] (fail) {fail};
\draw[arro] (excellence.north) -- (excellence.north|-identify.south);
\draw[arro] (fail.west) -| coordinate[near end] (aux) (init.south);
\draw[arro] (aux|-pass.west) -- (pass.west);
\end{tikzpicture}
\end{document}
评论,
要放置节点,请使用
positioning
库提供的功能。您可以访问节点的锚点来放置箭头。对于名为 A 的节点,您可以说
A.north
,或者A.south west
或使用角度锚点:A.130
,A.40
。使用该
arrows.meta
库,您可以生成您正在查看的箭头Square[]
。将旧
\tikzset
语法更改为更合适的\tikzset
语法。