如果可能的话,我需要您的帮助来将此图像转换为 TikZ/PGF:
仅供参考,我想在beamerslide
标准article
类型文档(A4 纸)上使用该图像。
我使用了 Inkscape ( .svg > .png
),它能很好地完成工作。但它没有提供任何TikZ
代码 - 而是提供PSTricks
类型代码,这让我更加困惑。 有 GUI 吗TikZ/PGF
?
答案1
这相当简单,请参阅下面的代码。loop
我没有将字母逐个写在下方,而是旋转了节点。
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{scopes}
\begin{document}
\begin{tikzpicture}
% putting the nodes
\node[red,right] (1) at (0,0) {first guess};
\node[black,right] (2) at (2,-2) {second guess};
\node[blue,right] (3) at (4,-4) {third guess};
% drawing arrows; the scopes library is used for putting the arrow tip option [-latex} only once; the |- notation means: from first point go straight down and then right to the second point, try -| to see the difference
{[-latex]
\draw[red] (1.south) |- (2.west);
\draw[black] (2.south) |- (3.west);
\draw[red] (1.220) -- node[rotate=-90, below] {loop} ++(0,-12) -- ++(6,0) node[right] {End};
\draw[black] (2.220) -- node[rotate=-90, below] {loop} ++(0,-8) -- ++(4,0) node[right] {End};
\draw[blue] (3.220) -- node[rotate=-90, below] {loop} node[right] {Max} ++(0,-4) -- ++(2,0) node[right] {End};
}
\end{tikzpicture}
\end{document}
编辑1:如果我理解正确的话,你想要
\draw[red] (1.south) -- (0,-2) -- (2.west);
\draw[black] (2.south) -- (2,-4) -- (3.west);
产生与之前相同的结果。
编辑2:如果使用 来text width=3cm
拆分节点内的文本,则会改变节点的高度,因此也会改变220
度节点的坐标。因此,我使用 calc 库来计算相对于节点中心的坐标。这样,箭头保持等距并终止于相同的坐标。下图说明了这个问题:
清理后的代码解决了 calc 库的问题:
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{scopes,calc}
\begin{document}
\begin{tikzpicture}
% putting the nodes
\node[red] (1) at (0,0) {first guess};
\node[black] (2) at (2,-2) {second guess};
\node[blue,text width=3cm] (3) at (4,-4) {Take a guess on $l(n)$ while Shanananana};
% drawing arrows; the scopes library is used for putting the arrow tip option [-latex} only once;
% the |- notation means: from first point go straight down and then right to the second point,
% try -| to see the difference
{[-latex,very thick]
\draw[red] (1.south) -- (0,-2) -- (2.west);
\draw[black] (2.south) -- (2,-4) -- (3.west);
\draw[red] ($(1.south) + (-0.4,0)$) -- node[rotate=-90, below] {loop} ($(1.center) + (-0.4,-12)$) -- ++(6,0) node[right] {End};
\draw[black] ($(2.south) + (-0.4,0)$) -- node[rotate=-90, below] {loop} ($(2.center) + (-0.4,-8)$) -- ++(4,0) node[right] {End};
\draw[blue] ($(3.south) + (-0.4,0)$) -- node[rotate=-90, below] {loop} node[right] {Max} ($(3.center) + (-0.4,-4)$) -- +(2,0) node[right] {End};
}
\end{tikzpicture}
\end{document}
最后的结果。请注意,您text width
也可以向其他节点添加,箭头仍然正确: