2

Suppose I have a polygon $ABCD$ and I want to put numbers $1$ through $4$ at the vertices $A$ through $D$. How to do that? Thanks.

\documentclass[tikz]{standalone} 

\usepackage{tkz-euclide}
\begin{document} 
\begin{tikzpicture}
\tkzDefPoints{2/0/A,1/3/B,2/3/C,4/1/D}
\tkzDrawPolygon(A,B,C,D)
% mark 1,2,3,4 at points A,B,C,D
\end{tikzpicture}
\end{document}

2 Answers 2

1

If you want a label different from the node name :

\tkzLabelPoint(Ref){Label}

You can use the macro \foreach but it's not necessary

\documentclass[tikz]{standalone} 

\usepackage{tkz-euclide}
\begin{document} 
\begin{tikzpicture}
\tkzDefPoints{2/0/A,1/3/B,2/3/C,4/1/D}
\tkzDrawPolygon(A,...,D)
\foreach \x/\t in {A/t1,B/t2,C/t3,D/t4} {
   \tkzLabelPoint[anchor=center,fill=white](\x){\t}
}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you! Works very well! Commented Jul 12 at 7:21
1

Adaptations

  • added a \foreach loop with counter \xi over A to D
  • draw nodes with fill=white at the vertices
  • (If you want to place the nodes outside the polygon, you might need to define the position (with left, below, etc.).)

Code

\documentclass[tikz]{standalone} 

\usepackage{tkz-euclide}
\begin{document} 
\begin{tikzpicture}
\tkzDefPoints{2/0/A,1/3/B,2/3/C,4/1/D}
\tkzDrawPolygon(A,...,D)
\foreach \x [count=\xi] in {A,...,D} {
    \node[fill=white, circle, inner sep=1pt] at (\x) {\xi};
}
\end{tikzpicture}
\end{document}

Result

enter image description here

3
  • Sorry my question was a little too specific. What if the numbers (or texts) to add are arbitrary, like 2,5,6,0.2? Thanks. Commented Jul 9 at 15:56
  • 1
    @HaoranChen In that case you can use \foreach \x/\xi in {A/2,B/5,C/6,D/0} { ... }.
    – dexteritas
    Commented Jul 9 at 16:34
  • Thank you very much. It works perfectly! Commented Jul 12 at 7:21

You must log in to answer this question.

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