1

I have an issue with the \draw command in Tikz, where I attempt to draw a line between two nodes and there is an offset between the start/end of the line and the actual coordinates of the nodes defined. As an example of the issue, here I'm trying to draw a triangle between the three points (0,0), (1,0), and (1,1):

\begin{tikzpicture}
\node (a) at (0,0) {};
\node (b) at (1,0) {};
\node (c) at (1,1) {};
\draw (a) -- (b);
\draw (b) -- (c);
\draw (a) -- (c);
\end{tikzpicture}

but it returns this. Does anyone know why it works like this, and an alternative to \draw that would (in this case) draw the full triangle?

1 Answer 1

3

Most of the gaps come from inner sep, which is >0 per default.

However I think for your use case, a \coordinate would be better suited. And if you draw all three lines in one go, they will be nicely connected at the corners.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[inner sep=0pt]
\node (a) at (0,0) {};
\node (b) at (1,0) {};
\node (c) at (1,1) {};
\draw (a) -- (b);
\draw (b) -- (c);
\draw (a) -- (c);
\end{tikzpicture}


\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,0);
\coordinate (c) at (1,1);
\draw (a) -- (b) -- (c) -- cycle;
\end{tikzpicture}
\end{document}
1
  • 1
    Thank you so much! 🙏
    – igunnarsson
    Jun 14, 2020 at 11:25

You must log in to answer this question.

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