선분의 끝점을 선분 "위에" 배치

선분의 끝점을 선분 "위에" 배치

다음 코드에 대한 표시는 TikZ끝점이 있는 선분입니다. 선분은 끝점 위에 그려집니다.

선분 위에 끝점을 어떻게 배치합니까?

\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$};
\filldraw (-1,-1) circle[radius=1.5pt];
\filldraw (2,1) circle[radius=1.5pt];

\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}

답변1

\coordinates를 사용하는 대신 다음과 같이 \nodes 자체를 사용하세요.label

%\filldraw (-1,-1) circle[radius=1.5pt];
%\filldraw (2,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);

귀하의 코드는 많이 단순화되었습니다.

전체 코드:

\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$};
%\filldraw (-1,-1) circle[radius=1.5pt];
%\filldraw (2,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);
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

관련 정보