# Simple (rectangular) diagrams labelled with mathematical expressions

I am looking to typeset a diagram vaguely similar to this one:

(source: papersizes.org)

The differences, for my diagram, are that I don't need an "A0" overlay - and... rather than sizes in mm, and A-numbers, I want math expressions, in latex, neatly typeset and centred.

I've considered using Xfig - but positioning the maths expressions is tedious/tricky/manual. I've considered using Inkscape - but that makes it hard to include the mathematical expressions at all. I've considered using TikZ - but I can't find any example diagrams of this (approximate) style.

I have a preference to implement this using only Latex (i.e. not use a GUI graphics tool to draw it) but I'm not sure where to start. By any chance, can anyone point me at a suitable example?

• What do you mean by "rather than sizes in mm, and A-numbers, I want math expressions, in latex, neatly typeset and centred"? Commented Jan 16, 2014 at 1:34
• Hmmm... I mean that, in place of "1189 mm"; "297 mm"; "A5"; "A2" - etc, I have a diagram that has math-mode expressions like $E=mC^2$ - etc. I want the labels for rectangles centred in the rectangles - and the measurements of edges centred between arrows - just like in the sample graphic... Similarly, rather than a number of mm, I want a math expression (like $E=mC^2$) to denote the size of edges. Commented Jan 17, 2014 at 0:24

# Update

To mark the dimension of a node, one can manually "draw" it, as in the following example (requires arrows library):

\begin{tikzpicture}
\node(n)[draw,minimum size=3cm]{$e=me^2$};
\draw[|<->|,>=latex]([yshift=5pt]n.north west)--([yshift=5pt]n.north east)
node[above,midway]{3cm};
\draw[|<->|,>=latex]([xshift=-5pt]n.south west)--([xshift=-5pt]n.north west)
node[above,midway,rotate=90]{3cm};
\end{tikzpicture}


This can be simplified by defining two keys, markwd and markht:

markwd/.style={
append after command={
\pgfextra{%
\begin{pgfinterruptpath}
\draw[|<->|,>=latex]
([yshift=5pt]\tikzlastnode.north west)--([yshift=5pt]\tikzlastnode.north east)
node[draw=none,midway,above]{#1};
\end{pgfinterruptpath}}}
},
markht/.style={
append after command={
\pgfextra{%
\begin{pgfinterruptpath}
\draw[|<->|,>=latex]
([xshift=-5pt]\tikzlastnode.south west)--([xshift=-5pt]\tikzlastnode.north west)
node[draw=none,midway,rotate=90,above]{#1};
\end{pgfinterruptpath}}}
},


Thus, the following code will reproduce the picture above:

\begin{tikzpicture}
\node(n)[draw,minimum size=3cm,markwd={3cm},markht={3cm}]{$e=me^2$};
\end{tikzpicture}


To further simplify, one can define a dim={<wd>}{<ht>} key, whose first argument sets the width of the node, and second argument sets the height:

dim/.style 2 args={minimum width=#1,minimum height=#2},


The following example illustrates how dimensions can be marked in @StevenBSegletes's example (note that some minor adjustment using yshift is needed):

## Full example

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{
every node/.style={draw},
dim/.style 2 args={minimum width=#1,minimum height=#2},
markwd/.style={
append after command={
\pgfextra{%
\begin{pgfinterruptpath}
\draw[|<->|,>=latex]
([yshift=5pt]\tikzlastnode.north west)--([yshift=5pt]\tikzlastnode.north east)
node[draw=none,midway,above]{#1};
\end{pgfinterruptpath}}}
},
markht/.style={
append after command={
\pgfextra{%
\begin{pgfinterruptpath}
\draw[|<->|,>=latex]
([xshift=-5pt]\tikzlastnode.south west)--([xshift=-5pt]\tikzlastnode.north west)
node[draw=none,midway,rotate=90,above]{#1};
\end{pgfinterruptpath}}}
},
}

\begin{document}
\begin{tikzpicture}
\node(n1)[dim={4in}{4in},markht={4in}]{$\int e^x dx = e^x$};
\node(n2)[dim={2in}{.5in},markht={.5in},anchor=south west]at(n1.north west){$0=0$};
\node(n3)[dim={1in}{1.5in},anchor=south west]at(n2.south east){$A=\pi r^2$};
\node(n4)[dim={1in}{2in},markwd={1in},anchor=south east]at(n1.north east){$F=kx$};
\node(n5)[dim={1in}{.5in},markwd={1in},anchor=south east,yshift=-\pgflinewidth]at(n3.north east){$e=mc^2$};
\node(n6)[dim={2in}{1.5in},markwd={2in},markht={1.5in},anchor=south west,yshift=-\pgflinewidth]at(n2.north west){$y=mx+b$};
\end{tikzpicture}
\end{document}


## Output

Assuming @StevenBSegletes's interpretation of your intent is correct, here's the TikZ way :)

# Code

\documentclass[]{article}
\usepackage{tikz}
\tikzset{
a1dim/.style={minimum width=841,minimum height=594,draw,fill=white!100!purple},
a2dim/.style={minimum width=420,minimum height=595,draw,fill=white!90!purple},
a3dim/.style={minimum width=421,minimum height=297,draw,fill=white!80!purple},
a4dim/.style={minimum width=210,minimum height=298,draw,fill=white!70!purple},
a5dim/.style={minimum width=211,minimum height=148,draw,fill=white!60!purple},
a6dim/.style={minimum width=105,minimum height=150,draw,fill=white!50!purple},
a7dim/.style={minimum width=106,minimum height= 74,draw,fill=white!40!purple},
a8dim/.style={minimum width= 52,minimum height= 76,draw,fill=white!30!purple},
nn/.style={minimum width=54, minimum height=76,draw,fill=gray},
}

\begin{document}
\begin{tikzpicture}
\begin{scope}[transform shape,scale=.3]
\node(A1)[a1dim]{};
\node(A2)[a2dim,anchor=south east,at=(A1.north east)]{};
\node(A3)[a3dim,anchor=south west,at=(A1.north west)]{};
\node(A4)[a4dim,anchor=south east,at=(A3.north east)]{};
\node(A5)[a5dim,anchor=south west,at=(A3.north west)]{};
\node(A6)[a6dim,anchor=south east,at=(A5.north east)]{};
\node(A7)[a7dim,anchor=south west,at=(A5.north west)]{};
\node(A8)[a8dim,anchor=south east,at=(A7.north east)]{};
\node(nn)[nn,anchor=south west,at=(A7.north west)]{};
\end{scope}

\node at(A1){$e=mc^2$};
\node at(A2){$e=mc^2$};
\node at(A3){$e=mc^2$};
\node at(A4){$e=mc^2$};
\node at(A5){$e=mc^2$};
\node[rotate=90] at(A6){$e=mc^2$};
\node[font=\tiny] at(A7){$e=mc^2$};
\node[font=\tiny,rotate=-90] at(A8){$e=mc^2$};
\end{tikzpicture}
\end{document}


# Output

• I think you don't need to specify all the paper sizes because the larger one can be derived from the smaller one consecutively. Use geometric sequence. Commented Jan 16, 2014 at 3:57
• @CodeMocker: You're right! But I'll leave this for the OP to work out :) Commented Jan 16, 2014 at 4:34
• My diagram is "similar" - but not identical - to the one I posted. :) This latex diagram looks very pretty - but doesn't show the size of edges (denoted in mm in the example graphic...) I need to show the size of edges - as well as label the rectangles... I don't mind if the edges are labelled internally - or, as in the graphic I posted, outside the enclosing rectangle. Commented Jan 17, 2014 at 0:31
• @aSteve: Please see my updated answer. Commented Jan 17, 2014 at 2:34

This introduces \cbox with 4 arguments for creating the elements. The arguments are width, height, scale factor, and mathematical expression. Then the various \cboxes are then inset into a background field (also created with a \cbox).

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\usepackage{graphicx}
\newcommand\cbox[4]{%
\fboxrule=1pt\fboxsep=-.5\fboxrule%
\fbox{\stackinset{c}{}{c}{}{\scalebox{#3}{$#4$}}{\rule{#1}{0pt}\rule{0pt}{#2}}}%
}
\begin{document}
\def\field{\cbox{4in}{6in}{1}{}}
\def\boxA{\cbox{2in}{1.5in}{1.7}{y=mx+b}}
\def\boxB{\cbox{1in}{0.5in}{1.1}{e=mc^2}}
\def\boxC{\cbox{1in}{2in}{1.4}{F=kx}}
\def\boxD{\cbox{1in}{1.5in}{1.2}{A=\pi r^2}}
\def\boxE{\cbox{2in}{0.5in}{2}{0 = 0}}
\def\boxF{\cbox{4in}{4in}{4}{\int e^x dx = e^x}}
\stackinset{l}{}{t}{}{\boxA}{%
\stackinset{l}{2in}{t}{}{\boxB}{%
\stackinset{r}{}{t}{}{\boxC}{%
\stackinset{r}{1in}{t}{0.5in}{\boxD}{%
\stackinset{l}{}{t}{1.5in}{\boxE}{%
\stackinset{l}{}{b}{}{\boxF}{%
\field%
}}}}}}
\end{document}


• Neat... but... how do I label the dimension of the edges (done using arrows and distances in mm in the example I posted...) Commented Jan 17, 2014 at 0:32
• @aSteve Hmmm, I didn't pick that up in my original read of your question. While I could perhaps handle text/math expressions on the side, I do not have a convenient way to have extensible arrows. Commented Jan 17, 2014 at 1:48

This is looking like a repetitive thing, hence some (over) simplified code can be thought of.

\documentclass[tikz,margin=10pt]{standalone}

\newcommand{\mynode}[5][none]{%
\node[draw,fill=#1,minimum width=2cm,minimum height=3cm,outer sep=0pt,anchor=north west] at
(0,0) (a) {};
\node[draw,fill=#2,minimum width=2cm,minimum height=3cm,outer sep=0pt,anchor=north west] at
(a.north east) {#4};
\node[draw,fill=#3,minimum width=4cm,minimum height=3cm,outer sep=0pt,anchor=north west] at
(a.south west) {#5};
}
%% syntax
%% \mynode[<color1>]{<color2>}{<color3>}{<text1}{<text2}

\begin{document}
\begin{tikzpicture}
\begin{scope}[scale=4,anchor=north west,transform shape]
\mynode{red!20}{white}{$e=mc^2$}{$e=mc^2$}
\end{scope}
\begin{scope}[scale=2,anchor=north west,transform shape]
\mynode{green!20}{blue!20}{$e=mc^2$}{$e=mc^2$}
\end{scope}
\begin{scope}[scale=1,anchor=north west,transform shape]
\mynode{green!20}{blue!20}{$e=mc^2$}{$e=mc^2$}
\end{scope}
\begin{scope}[scale=0.5,anchor=north west,transform shape]
\mynode{green!20}{blue!20}{$e=mc^2$}{$e=mc^2$}
\end{scope}

\end{tikzpicture}
\end{document}


Peace be upon PSTricks users. Here is a template in PSTricks.

\documentclass[pstricks,border=1.61803398875cc,12pt]{standalone}
\usepackage{pst-eucl,siunitx}
\begin{document}
\begin{pspicture}[showgrid=false](9,7)
\pstGeonode[CurveType=polygon,PosAngle={-135,-90,135,-45,45,-45}]
(0,0){A}
(4,0){B}
(4,4){C}
(8,4){D}
(8,6){E}
(0,6){F}
\pcline[offset=12pt]{|*-|*}(F)(E)\naput[labelsep=5pt]{\SI{12}{\centi\meter}}
\pcline[offset=12pt]{|*-|*}(E)(D)\naput[labelsep=5pt,nrot=:U]{\SI{2}{\centi\meter}}
\end{pspicture}
\end{document}