On using circular nodes on the path using \draw ... to node ..." without crossing the circles

1. Let us assume that we have a line segment starting at (0,0) and stopping at (-2,-2).
2. Suppose we want to add two circular nodes on the line segment, one near to start one near to end.
3. In addition the circular nodes have some texts in them: for example the starting node has "x" in it and the stopping node has "+ -" in it.
4. Also we desire that the line does not cross the inside of the circles.
5. We also prefer to use the  \draw ... to node ...

Below is the first trial code:

\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node [anchor=south west]at (0,0) (start){Start};
\node [anchor=north east]at (-2,-2) (stop){Stop};
\draw (start) to node [circle, draw,near start] {x}  node [circle, draw,near end] {+ -}(stop);
\end{tikzpicture}
\end{document}


The result is:

In order to prevent the line crossing the circles I add fill=white in the node properties as below:

\draw (start) to node [circle, draw,near start, fill=white] {x} node [circle, draw,near end, fill=white] {+ -}(stop); And we nicely get:

My question is: Is there other simple way instead of fill=white to create the desired output?

1 Answer

Is this? two dashes -- looks better!

\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path
(3,3) node (start) {Start}
(0,0) node (stop)  {Stop};
\path (start) to
node[circle,draw,near start] (x) {x}
node[circle,draw,near end]   (pm) {+ --}
(stop);
\draw (stop)--(pm)--(x)--(start);
\end{tikzpicture}
\end{document}


Update:

\documentclass[tikz,border=0.5cm]{standalone}
\begin{document}
\begin{tikzpicture}
\path
(3,3) node (start) {Start}
(0,0) node (stop)  {Stop};
\draw[nodes={circle,draw,fill=white}]
(start) to
node[near start] (x) {x}
node[near end]   (pm) {+ --}
(stop);
\end{tikzpicture}
\end{document}

• We also prefer to use the \draw ... to node ...
– Aria
Oct 20, 2021 at 6:24
• then use that! why not? ^^ Oct 20, 2021 at 6:26
• you may use layers (check pgfmanual), but the code will be more complicated im comparison with the figure itself Oct 20, 2021 at 6:28
• fill=white came to my mind but thought maybe other ways exist
– Aria
Oct 20, 2021 at 6:28
• [fill=white] is good also! I add an update \draw to node. Oct 20, 2021 at 6:32