0
  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?

1 Answer 1

2

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}
5
  • We also prefer to use the \draw ... to node ...
    – Aria
    Oct 20, 2021 at 6:24
  • then use that! why not? ^^
    – Black Mild
    Oct 20, 2021 at 6:26
  • 1
    you may use layers (check pgfmanual), but the code will be more complicated im comparison with the figure itself
    – Black Mild
    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
  • 1
    [fill=white] is good also! I add an update \draw to node.
    – Black Mild
    Oct 20, 2021 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.