On using circular nodes on the path using“ \draw … to node …” without crossing the circles

drawtikz-nodetikz-pathtikz-pgf

  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:
enter image description here

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:
enter image description here

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

Best Answer

Is this? two dashes -- looks better!

enter image description here

\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}