1

Hi i took this code and made it sute my styles but i can not get the line end of net node end before the circle it ends inside the circle. how can i make it stop at the edge of the circle?

here is my code:

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

enter image description here

novski
  • 1,039

1 Answers1

5

You can try this:

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

Output:

enter image description here

Explanation: you have to connect with a named path so that the connection will respect it's shape.

Edit:

Also you can automate the procedure to use only one number (\i) and change whatever parameter you like much easier:

Code:

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

Same result:

koleygr
  • 20,105
  • thanks @koleygr. Had to find out how the first works and the second seams even trickier. I will go with the first... – novski Sep 22 '17 at 16:00
  • Welcome... In the first, I just created the circles as a path and named them as (C\i) [this means (C1) for first (C2) for second etc...] Then I connected the line with the path created and named as (C1) ... (C2)... And this respected it's dimensions. The rest of the code is yours (just added \i as a count)... In the second, I just wanted a simpler foreach loop (without giving the same or opposite y for each point)... I just gave the x coordinate as \i and I used an \ifodd conditional to give a possitive or a negative nalue to \y coordinate [Want odd nums above and even nums below.] – koleygr Sep 22 '17 at 16:16