如何使线完美连接圆节点

如何使线完美连接圆节点

我将一条线连接到一个圆形节点,然后我注意到(在显微镜下)该线与圆形节点的半径并不完美。这通常不可见,但对于超粗的线和较小的节点半径,间隙变得明显。

\documentclass[preview]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,-3pt) -- (0,3pt);
\draw (0.3,-3pt) -- (0.3,3pt);
\node (leftEnd) at (0,0) [draw,circle,inner sep=0pt,minimum size=3pt] {};
\node (rightEnd) at (0.3,0) [draw,circle,inner sep=0pt,minimum size=3pt,fill=white] {};
\draw[ultra thick] (leftEnd) -- (rightEnd);
\end{tikzpicture}
\end{document}

TikZ 连接两个小圆圈节点的粗线

如何才能使线条无缝衔接?

编辑:理想情况下,圆圈节点应为空,以便允许其后面的线条可见或不可见。我已更新 MWE 和图片以反映这一点。

答案1

另一个选择是简单地连接这些center点,然后使用fill=white选项重新绘制,或者按照 marmot 的建议,你可以一次性完成绘制:

在此处输入图片描述

代码:

\documentclass[preview, border=0.5pt]{standalone}
\usepackage{tikz}

\tikzset{Node Style/.style={thick, draw,fill=white,circle,inner sep=0pt,minimum size=3pt}}

\begin{document}
\begin{tikzpicture}
\node (leftEnd)  at (0,0)   [Node Style] {};
\node (rightEnd) at (0.3,0) [Node Style] {};

\draw [ultra thick] (leftEnd.center) -- (rightEnd.center);

\node (leftEnd)  at (0,0)   [Node Style] {};
\node (rightEnd) at (0.3,0) [Node Style] {};
\end{tikzpicture}
%
\begin{tikzpicture}
\draw[ultra thick] 
       (0,0)   node[Node Style] {} 
    -- (0.3,0) node[Node Style] {};
\end{tikzpicture}%
\end{document}

答案2

您可以调整缩短值,shorten >=1.5pt,shorten <=1.5pt或者使用 arrows.meta 库来获得相同的结果。

结果:放大 1000%

在此处输入图片描述

梅威瑟:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
    >={Circle[fill=none,length=3.5pt,line width=0.5]}
]
\node (leftEnd) at (0,0) [draw,circle,inner sep=0pt,minimum size=3pt] {};
\node (rightEnd) at (0.3,0) [draw,circle,inner sep=0pt,minimum size=3pt] {};
\draw[ultra thick,shorten >=1.5pt,shorten <=1.5pt] (leftEnd.center) -- (rightEnd.center);
\draw[ultra thick,<->,shorten >=-1.75pt,shorten <=-1.75pt] (0,-10pt) -- ++(0.3,0);

\end{tikzpicture}
\end{document}

答案3

对于某些线宽,如果您在节点样式中设置它会有所帮助outer sep=0pt

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}[
circ/.style = {circle, draw, inner sep=0pt, minimum size=3pt, outer sep=0pt}
                    ]
\node (leftEnd)  [circ] {};
\node (rightEnd) [circ] at (0.5,0) {};
\draw[ultra thick] (leftEnd) -- (rightEnd);
\draw[line width=6pt, gray, semitransparent] (leftEnd) -- (rightEnd);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容