# How do I make a square and label each corner with a number?

I am trying to make a square to demonstrate how reflections and rotations work, so I would like a square with each interior vertex labeled with a number.

• I love the massive variety of answers! – Ryan Feb 23 '15 at 19:24
• ow, I returned here and found 7 answers! Nice! – Sigur Feb 23 '15 at 19:53
• By now it seems that only PStricks and Asymptote are missing! Only a matter of time, I hope, before they come ;-) – Franck Pastor Feb 23 '15 at 19:59
• @fpast Those aren't the only possibilities left... ;-) – Ryan Feb 23 '15 at 20:35
• @fpast I was also going to point out that it can be done using hyphens inside \resizeboxes, but I think I've done enough damage to this thread already. – Ryan Feb 23 '15 at 20:42

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (0,2) -- (2,2) -- (2,0) -- (0,0);
\node[above right] at (0,0) {1};
\node[below right] at (0,2) {2};
\node[below left] at (2,2) {3};
\node[above left] at (2,0) {4};
\end{tikzpicture}
\end{document}


An automatic and easy way to adapt (following idea of @Benjamin McKay)

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[blue,draw=red,thick,minimum width=2cm,minimum height=2cm] (rect) at (0,0) {$\times$};
\foreach \anc/\n in {south west/1,north west/2,north east/3,south east/4}{
\node[anchor=\anc] at (rect.\anc) {\n};
}
\end{tikzpicture}
\end{document}


The most standard LaTeX (not TeX ;-)) graphic solution: the picture environment. No packages loaded thus.

\documentclass[12pt]{scrartcl}
\begin{document}
\setlength{\unitlength}{4cm}
\begin{picture}(1,1)
\put(0,0){\framebox(1,1)[t]{}}
\put(0.01,0.01){1}
\put(0.99,0.01){\makebox(0,0)[br]{2}}
\put(0.99,0.99){\makebox(0,0)[tr]{3}}
\put(0.01,0.99){\makebox(0,0)[tl]{4}}
\end{picture}
\end{document}


• May be a tabular :P – Manuel Feb 23 '15 at 21:02

Quite an easy game for every TeXian drawing solution. By the way, did you try one of them?

Here with MetaPost via LuaLaTeX:

\documentclass[12pt]{scrartcl}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(1);
u = 4cm; draw unitsquare scaled u;
label.urt("1", origin); label.ulft("2", (u, 0));
label.llft("3", (u, u)); label.lrt("4", (0, u));
endfig;
\end{mplibcode}
\end{document}


Edit And now a mfpic solution. I've chosen to place it here and not as a separate answer because mfpic acts as an interface to MetaPost (it could have been to METAFONT by the way). It gives exactly the same result as above, is written only with (La)TeX macros but needs three compilations (by LaTeX, then by MetaPost, then by LaTeX again).

\documentclass[12pt]{scrartcl}
\usepackage[metapost]{mfpic}
\setlength{\mfpicunit}{4cm}
\opengraphsfile{\jobname}
\begin{document}
\begin{mfpic}{0}{1}{0}{1}
\rect{(0,0), (1, 1)}
\tlpointsep{3bp}
\tlabels{[bl](0,0){1} [br](1,0){2} [tr](1,1){3} [tl](0,1){4}}
\end{mfpic}
\end{document}


The solution based only on TeX primitives (without TikZ, Metapost, Lua etc.):

\def\hboxlab#1#2{\hbox to2cm{\vrule height4mm depth1mm \kern1mm #1\hfil #2\kern1mm\vrule}}
\vbox{\offinterlineskip\hrule
\hboxlab 43
\hbox to2cm{\vrule height1cm \hfil\vrule}
\hboxlab 12
\hrule
}


Here's quite possibly the strangest approach, using XeLaTeX and fontspec to type the unicode ballot box symbol, resizing it using a \resizebox, and then putting the numbers inside that by manipulating the kerning and alignment.

\documentclass{article}
\usepackage{fontspec}

\newfontfamily{\arial}{Arial Unicode MS}

\begin{document}
\resizebox{2in}{!}{\arial ☐}\textbf{
\kern-1.68in\raisebox{1.35in}{1}
\kern-1.8ex\raisebox{.22in}{3}
\kern1in\raisebox{1.35in}{2}
\kern-2ex\raisebox{.22in}{4}}
\end{document}


This is questionably functional and slightly ugly, and not actually intended as a serious answer.

Just to flood this post ;-)

\documentclass[12pt]{scrartcl}
\begin{document}
\fboxsep2pt
\fboxrule1pt
\fbox{%
\parbox[t][4cm]{4cm}{%
4 \hfill 3
\par\vfill
1 \hfill 2
}%
}

\begin{tabular*}{4cm}{|@{\,\extracolsep\fill}lr@{\,}|}
\hline
4 & 3\$3cm] 1 & 2\\\hline \end{tabular*} \end{document}  • Those are both really elegant solutions, especially the table! – Ryan Feb 24 '15 at 5:09 This is addicting. Here's a one line answer, using the boxed equation command in the amsmath package: \documentclass{article} \usepackage{amsmath} \begin{document} \[\boxed{1 \kern6ex 2\raisebox{-6.75ex}{\kern-8.25ex 3 \kern5ex 4}}$

\end{document}


This is fully functional and technically correct, but not actually intended as a serious answer.

Here, I stack inside a simple \framebox.

\documentclass{article}
\usepackage{stackengine}
\begin{document}
\stackinset{l}{2pt}{t}{2pt}{4}{%
\stackinset{r}{2pt}{t}{2pt}{3}{%
\stackinset{r}{2pt}{b}{2pt}{2}{%
\stackinset{l}{2pt}{b}{2pt}{1}{%
\framebox(50,50){}%
}}}}
\end{document}


If coloring and centermark are useful,

\documentclass{article}
\usepackage{stackengine,xcolor}
\begin{document}
\stackinset{l}{2pt}{t}{2pt}{4}{%
\stackinset{r}{2pt}{t}{2pt}{3}{%
\stackinset{r}{2pt}{b}{2pt}{2}{%
\stackinset{l}{2pt}{b}{2pt}{1}{%
\textcolor{red}{\framebox(50,50){\textcolor{blue}{$\times$}}}%
}}}}
\end{document}


Just because nobody has done it yet, here's a solution* using nothing but \vspace, \hspace, and \rule:

No packages loaded, and not too many lines of code!

\documentclass{article}

\begin{document}
\noindent\rule{25ex}{.4pt}\\
\hspace*{.25ex} 1 \hspace{19ex} 2 \vspace*{-1.1\baselineskip}\\
\rule{.4pt}{25ex} \hspace{23.265ex} \rule{.4pt}{25ex}\vspace*{-1.5\baselineskip}\\
\hspace*{.25ex} 3 \hspace{19ex} 4 \vspace*{-.5\baselineskip}\\
\rule{25ex}{.4pt}
\end{document}


This is fully functional and technically correct, but not actually intended as a serious answer.

Since nobody has volunteered for it yet, here is a solution with Asymptote, using the aptly named asymptote package.

\documentclass[12pt]{scrartcl}
\usepackage{asymptote}
\begin{document}
\begin{asy}
unitsize(4cm);
draw(unitsquare);
label("1", (0, 0), NE); label("2", (1, 0), NW);
label("3", (1, 1), SW); label("4", (0, 1), SE);
\end{asy}
\end{document}


To be compiled thrice, too: once with LaTeX, then once with Asymptote (asy myfile.asy in an Unix command line interface, for example) and then once again with LaTeX.