嗨,我拿了此代码并使其符合我的风格,但我无法让网络节点端的线端在圆之前结束,它在圆内结束。我怎样才能让它停在圆的边缘?
这是我的代码:
\tikzset{
net node/.style = {circle, draw, minimum width=0.8cm, inner sep=0pt, outer sep=0pt},
net connect/.style = {line width=1pt, draw=black},
net thick connect/.style = {net connect, line width=1.7pt},
}
\begin{tikzpicture}
\path [net thick connect] (0.8,0) -- (5.2,0);
\foreach \i/\j in {2/-1,4/-1,1/1,3/1,5/1} \path [net connect] (\i,0) -- (\i,\j) node [net node] {\i};
\end{tikzpicture}
答案1
您可以尝试以下操作:
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
%opening
\title{}
\begin{document}
\tikzset{
net node/.style = {circle, draw=black,line width=1.2pt,minimum width=0.8cm, inner sep=0pt, outer sep=0pt},
net connect/.style = {line width=1pt, draw=black},
net thick connect/.style = {net connect, line width=1.7pt},
}
\begin{tikzpicture}
\path [net thick connect] (0.8,0) -- (5.2,0);
\foreach \i/\j [count=\k]in {2/-1,4/-1,1/1,3/1,5/1} {
\path (\i,\j) node [net node] (C\k) {\i};
\path [net connect] (\i,0) -- (C\k);}
\end{tikzpicture}
\end{document}
输出:
说明:您必须使用命名路径进行连接,以便连接能够遵循其形状。
编辑:
您还可以自动化该过程以仅使用一个数字(\i)并更轻松地更改您喜欢的任何参数:
代码:
\xdef\Ydist{1.4}
\begin{tikzpicture}
\path [net thick connect] (0.8,0) -- (5.2,0);
\foreach \i in {1,...,5} {
\ifodd\i \xdef\y{\Ydist} \else \xdef\y{-\Ydist}\fi
\path (\i,\y) node [net node] (C\i) {\i};
\path [net connect] (\i,0) -- (C\i);}
\end{tikzpicture}
相同的结果: