0

I am currently using GeoGebra to generate Tikz code. So my directed edges are written as something like

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(0.36,0.28) rectangle (6.72,3.82);

\draw [->] (5.9,0.74) -- (2.26,2.76);

\fill [color=qqwwqq] (2.26,2.76) circle (2pt);
\draw[color=qqwwqq] (2.56,3.02) node {$y$};

\end{tikzpicture}

which gives me nearly exactly what I want aside from the fact that the arrow tip and the node slightly overlap (see picture).

enter image description here

One solution would be to shorten the line segment by a small amount manually. However, this might not be the smartest approach for larger graphs with lots of directed edges.

Is there any way I could resolve this issue easily? E.g. by automatically shortening each edge slightly such that the arrow tip ends at the beginning of the circle?

2 Answers 2

1

You can definitely shorten all arrowtips by the amount of a dot radius via

\tikzset{shorten >= 2pt}

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}
\colorlet{qqwwqq}{green!50!black}

\begin{document}

\usetikzlibrary{arrows}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\tikzset{shorten >= 2pt}

\clip(0.36,0.28) rectangle (6.72,3.82);

\draw [->] (5.9,0.74) -- (2.26,2.76);

\fill [color=qqwwqq] (2.26,2.76) circle (2pt);
\draw[color=qqwwqq] (2.56,3.02) node {$y$};

\end{tikzpicture}

\end{document}
1
  • Thank you. This is exactly what I was looking for!
    – mc.math
    May 13, 2022 at 14:54
3

Place the node at the desired coordinates with shape and label information, and give it a name (I used Y). Then draw the line to the node, not to the coordinates, using \draw [->] (5.9,0.74) -- (Y);. You increase the outer sep if you want a little space between the arrow and the circle.

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]

\node[circle, inner sep=1.5pt, outer sep=0, fill=green!30!black, label={[green!30!black]above right:$y$}] at (2.25,2.75) (Y){};
\draw [->] (6,0.75) -- (Y);

\end{tikzpicture}
\end{document}
3
  • But that is not what GeoGebra gives me, or am I missing something? And naming each node individually also seems a bit impractical.
    – mc.math
    May 13, 2022 at 14:21
  • 1
    @mc.math: GeoGebra translation to TikZ is not perfect. In virtually all cases you'll get better looking results if you just draw the image with TikZ and skip GeoGebra altogether. I know TikZ looks intimidating at first (especially the 1000-page manual) but it's worth it. You can always post questions to TeX.SX if you get stuck.
    – Sandy G
    May 13, 2022 at 14:36
  • Thank you for your answer. Also, I am already a bit familiar with TikZ. I decided you use GeoGebra for generating the code for some different reasons. That is why I was looking for a solution that works with the GeoGebra generated code specifically. Again, thank you very much for your answer!
    – mc.math
    May 13, 2022 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .