0

I want to draw a graph similar to

enter image description here

in latex but I want edges to touch vertices.

My attempt:

\node (f) at (0,0) {$F$};
\node (g) at (1,0) {$G$};
\node (e) at (2,0) {$E$};
\node (d) at (2,1) {$D$};
\node (a) at (2,2) {$A$};
\node (b) at (3,2) {$B$};
\draw[black, thick] (a)--(b);
\draw[black, thick] (c)--(b);
\draw[black, thick] (d)--(c);
\draw[black, thick] (d)--(e);

but edges still don't touch vertices. Any help would be appreciated.

Edit: The code

\node (a) at (10,0) {$\circ$};
\node (b) at (11,-1) {$\circ$};
\node (c) at (11,-2) {$\circ$};
\node (d) at (12,-3) {$\circ$};
\node (e) at (11,-4) {$\circ$};


\draw[black, thick] (a.center)--(b.center)--(c.center)--(d.center)--(e.center);

produces this graph enter image description here

It would be nice if I were able to fill nodes with black color. If I put the code

\node [fill=black](a) at (10,0) {$\circ$};
\node [fill=black](b) at (11,-1) {$\circ$};
\node (c) at (11,-2) {$\circ$};
\node (d) at (12,-3) {$\circ$};
\node (e) at (11,-4) {$\circ$};


\draw[black, thick] (a.center)--(b.center)--(c.center)--(d.center)--(e.center);

It produces this graph enter image description here

However I want nodes to be circular and small and edges drawn from node border to node border.

2
  • 1
    outer sep=0pt would work (also play with nodes={draw}), but your code snippet uses non-empty node text, which is not the same in your image, is it? Dec 27, 2021 at 9:50
  • Does my answer doesn't solve your problem? See addendum to it.
    – Zarko
    Dec 28, 2021 at 8:31

2 Answers 2

3
  • Your code fragment has error (undefined node c)
  • Arrows touch nodes border. To see this, in MWE below nodes' borders are drawn at first two nodes
  • It is not entirely clear, what you after. Please always provide a MWE not just code fragment
\documentclass[margin=3.141592]{standalone} % ;-)
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[every node/.style = {circle, inner sep=2pt}]
\node[draw] (f) at (0,0) {$F$};
\node[draw] (g) at (1,0) {$G$};
\node[fill=cyan] (e) at (2,0) {$E$};
\node (d) at (2,1) {$D$};
\node (a) at (2,2) {$A$};
\node (b) at (3,2) {$B$};
\draw[black, thick] (a)--(b) -- (d) --(e) --(g) -- (f);    
    \end{tikzpicture}
\end{document}

enter image description here

Tiny whit space between node E and arrows are equal to outer sep distance which make space for (half of width) node's border. Hence it is absent at this node, it show up. If you set this distance to zero, for example by

every node/.style = {circle, inner sep=2pt, outer sep=0pt}

then they will disappear:

enter image description here

Addendum Already from above examples follows how you can solve your problem You need to define style of your nodes (as is done in examples). Because your question is still not entirely clear what is your problem, I defined nodes style so, that you can observe differences if you at nodes use border lines or not and if you just fill them.

Now I guess that you like to have the following:

\documentclass[margin=3.141592]{standalone} % ;-)
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {draw, circle, inner sep=2pt}
                        ]
circle, inner sep=2pt}]
\node (f) at (0,0) {};
\node (g) at (1,0) {};
\node (e) at (2,0) {};
\node (d) at (2,1) {};
\node (a) at (2,2) {};
\node (b) at (3,2) {};
\draw[black, thick] (a)--(b) -- (d) --(e) --(g) -- (f);
    \end{tikzpicture}
\end{document}

Please observe, that node styles is defined in the option of tikzpicture as

every node/.style = {draw, circle, inner sep=2pt}

The every node is instruction that this style had to be applied to all nodes in picture. If you have some other nodes in pictures, for example labels to nodes or arrows, which should have different style, then is better to give a name to nodes' style, for example V (as shortness for Vertices) and write above MWE as:

\documentclass[margin=3.141592]{standalone} % ;-)
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[
V/.style = {draw, circle, inner sep=2pt}
                        ]
\node[V] (f) at (0,0) {};
\node[V] (g) at (1,0) {};
\node[V] (e) at (2,0) {};
\node[V] (d) at (2,1) {};
\node[V] (a) at (2,2) {};
\node[V] (b) at (3,2) {};
\draw[black, thick] (a)--(b) -- (d) --(e) --(g) -- (f);
    \end{tikzpicture}
\end{document}

enter image description here

0

I had a similiar problem like yours in the past. Just try adding center to your points like:

\draw[black, thick] (a.center)--(b.center);
\draw[black, thick] (c.center)--(b.center);
\draw[black, thick] (d.center)--(c.center);
\draw[black, thick] (d.center)--(e.center);
1
  • 1
    This is not a correct answer to OP's issue, since it doesn't draw from node borders but from their centers.
    – SebGlav
    Dec 27, 2021 at 18:49

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.