# Putting the endpoints of a line segment “over” the line segment

The display that TikZ gives for the following code is a line segment with endpoints. The line segment is drawn over the endpoints.

How do I put the endpoints over the line segment?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,intersections,quotes}

\begin{document}

\begin{tikzpicture}
\draw[yellow, line width=0.1pt] (-1.75,-1.75) grid[xstep=0.5, ystep=0.5]  (2.75,1.75);
\draw[draw=gray!30,latex-latex] (0,1.75) +(0,0.25cm) node[above right] {$y$} -- (0,-1.75) -- +(0,-0.25cm);
\draw[draw=gray!30,latex-latex] (-1.75,0) +(-0.25cm,0) -- (2.75,0) -- +(0.25cm,0) node[below right] {$x$};

\node[left, outer sep=2pt, fill=white] at (-1,-1) {P};
\node[right, outer sep=2pt, fill=white] at (2,1) {Q};
\coordinate (P) at (-1,-1);
\coordinate (Q) at (2,1);

\draw[green!20!white] (P) -- (Q);
\end{tikzpicture}

\end{document}


Instead of using \coordinates, use the \nodes themselves with label like

%\filldraw (-1,-1) circle[radius=1.5pt];

\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]left:$P$}] (P) at (-1,-1) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt, label={[fill=white]right:$Q$}] (Q) at (2,1) {};
%\coordinate (P) at (-1,-1);
%\coordinate (Q) at (2,1);

\draw[green!20!white] (P) -- (Q);


Full code:

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,intersections,quotes}

\begin{document}

\begin{tikzpicture}
\draw[yellow, line width=0.1pt] (-1.75,-1.75) grid[xstep=0.5, ystep=0.5]  (2.75,1.75);
\draw[draw=gray!30,latex-latex] (0,1.75) +(0,0.25cm) node[above right] {$y$} -- (0,-1.75) -- +(0,-0.25cm);
\draw[draw=gray!30,latex-latex] (-1.75,0) +(-0.25cm,0) -- (2.75,0) -- +(0.25cm,0) node[below right] {$x$};

\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]left:$P$}] (P) at (-1,-1) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt, label={[fill=white]right:$Q$}] (Q) at (2,1) {};
%\coordinate (P) at (-1,-1);
%\coordinate (Q) at (2,1);

\draw[green!20!white] (P) -- (Q);
\end{tikzpicture}

\end{document}


• I would like two edits. The letters "P" and "Q" should be in script. Why doesn't label=left:$P$ put "P" in script? I also want to put the letters in a circular node (filled with white) so that the "P" and "Q" are over the grid ... but I don't want this white, circular node to interfere with the endpoints. – user74973 Apr 20 '15 at 0:11
• @user74973 What do you mean by script? – user11232 Apr 20 '15 at 0:25
• Italics. _______ – user74973 Apr 20 '15 at 0:27
• @user74973 OK, please see the edit. You have to use label={[fill=white]right:$Q$}. – user11232 Apr 20 '15 at 0:29
• Thanks! I will look at the manual later for label={[fill=white]right:$Q$}. – user74973 Apr 20 '15 at 0:32