我想将一个黑色圆圈对齐到另一个更大的白色圆圈的中心(它必须看起来像Activity Final Node
)UML
。
最直接的方法就是简单地将较大的圆形节点明确地放置在某个坐标处,然后手动计算黑色节点的坐标;但是如果不浪费时间,就不可能用这种方法来处理困难的图形。
我可以做这样的事:
\begin{tikzpicture}
\node (close){Close};
%defining "end process" node:
\node [circle, below =of close, text width=2em, fill=none, draw=black] (stop-outer){};
\node [circle, below =1.2 of close, text width=1em, fill=black] (stop-inner){};
%end of defining "end process" node
\draw [->] (close) -- (stop-outer);
\end{tikzpicture}
但它也有缺点,例如我必须关心text width
更大的圈子并改变数值部分below =1.2 of close
才能获得最佳结果。
有没有办法做到这一点而不需要手工计算?
答案1
你还有更多的可能性:
- 为圆定义公共锚点并使用不同的圆半径(如果理解正确,你不喜欢这个解决方案)
- 首先画出内圆并围绕它画出外圆:
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{fit, positioning}
\begin{document}
\begin{tikzpicture}
\node (close){Close};
%defining "end process" node:
\node [circle, draw,
fill=black, text width=1em,
below = of close] (stop) {};
\node [circle, draw, inner sep =0.2em,
fit = (stop) ] (stop-outer) {};
%end of defining "end process" node
\draw [->] (close) -- (stop-outer);
\end{tikzpicture}
\end{document}
- 使用选项
double
绘制一个圆圈:
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{fit, positioning}
\begin{document}
\begin{tikzpicture}
\node (close){Close};
\node [circle, draw, double, double distance=0.2em,
fill=black, text width=1em, outer sep=0.1em,
below = of close] (stop) {};
\draw [->] (close) -- (stop);
\end{tikzpicture}
\end{document}
在后两种情况下,结果都是相同的:
答案2
使用positionning
中心和anchor
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (close){Close};
% defining "end process" node:
\node [circle, below =of close, text width=2em, fill=none, draw=black] (stop-outer){};
\node [circle, below=0mm of stop-outer.center, anchor=center, text width=1em, fill=black] (stop-inner){};
% end of defining "end process" node
\draw [->] (close) -- (stop-outer);
\end{tikzpicture}
\end{document}