1

This might be a very simple question and may have been asked here. I just don't know what the keywords are if it does. Let me start with an example:

\documentclass[border=10pt,varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, shapes, backgrounds}

\begin{document}

\begin{tikzpicture}
\coordinate (P) at (0,0);
\fill (P) circle[radius=0.05] node[below]{P};
\node (Q) at (2,0) {};
\fill (Q) circle[radius=0.05] node[below]{Q};
\draw (P) -- (Q) node[pos=0.4] (A) {};
\fill (A) circle[radius=0.05] node[below]{A};
\draw (1,1) -- (A);
\end{tikzpicture}

\end{document}

So I specify the two points P and Q differently: I use coordinate for P and node for Q. Here is the outcome: Outcome

When drawing a segment between these two points P and Q, the segment fell short of reaching the actual point Q.

I could use coordinate to specify Q. Just there are cases that I have to use node to specify a point in the middle of somewhere (like the point A).

How do I draw lines that actually reach the points Q and A, respectively?

Thanks!

2
  • 1
    You can use a coordinate in the middle of a path just like a node, so all your nodes could be coordinates. Jul 19, 2021 at 15:00
  • Thanks! It works.
    – Pengfei
    Jul 19, 2021 at 15:10

1 Answer 1

2

As @AndrewStacey wrote, you can very well define nodes with the coordinate shape in the middle of a path. Otherwise, just make sure the nodes have minimum size=0pt, inner sep=0pt, outer sep=0pt if you want “connecting lines” to reach their center.

The code below illustrates this for nodes A and Q of your example. I changed the two corresponding \fill commands into \draw so that we can see that the “connecting lines” do reach the centers of these nodes.

\documentclass[border=1mm]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[foo/.style={minimum size=0pt, inner sep=0pt, outer sep=0pt}]
  \coordinate (P) at (0,0);
  \fill (P) circle[radius=0.05] node[below] {P};
  \node[foo] (Q) at (2,0) {};
  \draw (Q) circle[radius=0.05] node[below] {Q};
  \draw (P) -- (Q) node[pos=0.4, foo] (A) {};
  \draw (A) circle[radius=0.05] node[below]{A};
  \draw (1,1) -- (A);
\end{tikzpicture}

\end{document}

enter image description here

2
  • Thanks! This is very interesting.
    – Pengfei
    Jul 19, 2021 at 17:22
  • You're welcome, glad to help :-)
    – frougon
    Jul 19, 2021 at 18:13

You must log in to answer this question.

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