Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What is the easiest way to label the sides of rectangles and triangles in TikZ?

share|improve this question
2  
Does tex.stackexchange.com/questions/13401/… what you want? –  Martin Scharrer Mar 15 '11 at 18:06
add comment

1 Answer

up vote 7 down vote accepted

I usually use nodes placed along the path that draws the polygon.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
% Rectangle with labeled edges
\draw (0,0)  -| (5,3) 
    node[pos=0.25,below] {$\ell$} 
    node[pos=0.75,right] {$w$}
    -| (0,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[rotate=30] (0,0)  -| (5,3) 
    node[pos=0.25,below] {$\ell$} 
    node[pos=0.75,right] {$w$}
    -| (0,0);   
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) -- (4,0) node[midway,below] {$a$}
   -- (2,4) node[midway,right] {$b$}
   -- (0,0) node[midway,left] {$c$};
\end{tikzpicture}

\end{document}

sample code output

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.