# How to make a label in a square in TikZ?

I have a code like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\draw (0,0)--(12,0)--(0,5)--cycle;
\draw (60/17,0)-- ++(0,60/17) -- (0,60/17);
\end{tikzpicture}
\end{document}


Well, I want to label the word $S_1$ inside the square(in the center). Is there an easy way to do this? I don't want to calculate the coordinate of the middle of the square.. On the other hand, how can I fill the square with many slashes?

I don't know exactly what you mean with slashes but here is my attempt.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}[scale=0.5]
\draw (0,0) -- (12,0) -- (0,5) -- cycle;
\filldraw[pattern=north east lines] (0,0) rectangle (60/17,60/17) node[pos=0.5] {$S_1$};
\end{tikzpicture}
\end{document}


• Thanks! By the way, what does the number 0.5 in [pos=0.5] refer to? I was studying the pgf-manual, but so far I just have learnt to set the nodes for not "closed" path. – Eric Jun 9 '17 at 14:15
• See The Tik Z and PGF Packages Manual for version 3.0.0 Sec. 17.8 Placing Nodes on a Line or Curve Explicitly. You can also place the node with the separate commend \path (0,0) -- (60/17,60/17) node[pos=0.5] {$S_1$}; – hzhr Jun 9 '17 at 19:49

One of the major strengths of TikZ is that one can create any number of nodes half way on a path. We can exploit that feature and create the square on the same triangular path. Also, a white background makes the label clearer.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\tikzset{sq/.style={draw,anchor=south west,minimum size=30cm/17,pattern=north east lines,outer sep=0pt}}

\begin{tikzpicture}[scale=0.5]
\draw (0,0) node[sq]{\colorbox{white}{$S_1$}} -- (12,0) -- (0,5) -- cycle;
\end{tikzpicture}

\end{document}