5

I built two towers in Tikz. Because the document they will be included in takes a while to compile and because my Tikz skills are somewhat limited (so I need to compile often to check if I've done something crazy), I used standalone while working on the figure.

Here is a minimised version of the towers with colouring and labelling removed:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,positioning}

\pagestyle{empty}

\begin{document}

\begin{tikzpicture}
  [
    rounded corners=1pt,
    node distance=0pt,
    rock/.style={draw, thick, minimum width=5mm, minimum height=5mm, outer sep=0pt},
    rock1/.append style={rock, minimum width=10mm},
    rock2/.append style={rock, minimum width=15mm},
    rock3/.append style={rock, minimum width=2.5mm, minimum height=10mm, yshift=2.5mm},
    rock4/.append style={rock, minimum width=12.5mm},
    rock5/.append style={rock, minimum height=10mm, yshift=2.5mm},
    rock6/.append style={rock, minimum width=2.5mm},
    rock7/.append style={rock, minimum width=7.5mm, minimum height=10mm, yshift=2.5mm},
    rock8/.append style={rock, minimum width=2.5mm, minimum height=15mm, yshift=5mm},
    rock9/.append style={rock, minimum width=7.5mm},
    key/.style={draw, thick, minimum width=2.5mm, minimum height=2.5mm},
    keytxt/.style={font=\sffamily},
  ]

    \node (rbase1) [rock1] {};
    \node (rbase2) [rock2, base right=of rbase1] {};
    \node (rbase3) [rock3, base right=of rbase2] {};
    \node (rbase4) [rock4, base right=of rbase3, yshift=-2.5mm] {};
    \node (rbase5) [rock5, base right=of rbase4] {};
    \node (rbase6) [rock, base right=of rbase5, yshift=-2.5mm] {};
    \node (r1r4) [rock6, left=of rbase3, yshift=2.5mm] {};
    \node (r1r3) [rock5, left=of r1r4] {};
    \node (r1r2) [rock1, left=of r1r3, yshift=-2.5mm] {};
    \node (r1r1) [rock, left=of r1r2] {};
    \node (r1r5) [rock1, right=of rbase3, yshift=2.5mm] {};
    \node (r1r6) [rock3, right=of r1r5] {};
    \node (r2r1) [rock4, left=of r1r3, yshift=2.5mm] {};
    \node (r2r2) [rock, right=of r1r3, yshift=2.5mm] {};
    \node (r2r3) [rock5, right=of r2r2] {};
    \node (r2r2) [rock, right=of r2r3, yshift=-2.5mm] {};
    \node (r3r1) [rock1, above=of r2r1, xshift=1.25mm] {};
    \node (r3r2) [rock7, right=of r3r1] {};
    \node (r3r3) [rock8, right=of r3r2, yshift=-2.5mm] {};
    \node (r3r4) [rock, right=of r2r3, yshift=2.5mm] {};
    \node (r4r1) [rock, above=of r3r1] {};
    \node (r4r2) [rock, right=of r4r1, rock3] {};
    \node (r4r3) [rock9, right=of r3r3] {};
    \node (r5r1) [rock6, above=of r4r1, xshift=1.25mm] {};
    \node (r5r2) [rock3, right=of r4r2, yshift=2.5mm] {};
    \node (r5r3) [rock3, right=of r5r2, yshift=-2.5mm] {};
    \node (r5r4) [rock6, right=of r5r3, yshift=-2.5mm] {};
    \node (r5r5) [rock5, right=of r3r3, yshift=5mm] {};
    \node (r6r1) [rock3, left=of r5r2, yshift=2.5mm] {};
    \node (r6r2) [rock5, right=of r5r3, yshift=2.5mm] {};
    \node (r7r1) [rock5, right=of r6r1, yshift=2.5mm] {};
    \node (r7r2) [rock3, right=of r6r2, yshift=2.5mm] {};
    \node (r8r1) [rock3, right=of r7r1, yshift=2.5mm] {};
    \node (r8r2) [rock3, right=of r8r1, yshift=-2.5mm] {};
    \node (r9r1) [rock6, left=of r8r1, yshift=2.5mm] {};
    \node (r10r1) [rock, above=of r8r1] {};
    \node (r11r1) [rock6, above=of r10r1] {};

    \node (ebase1) [rock, right=of rbase6, xshift=30mm] {};
    \node (ebase2) [rock5, base right=of ebase1] {};
    \node (ebase3) [rock1, base right=of ebase2, yshift=-2.5mm] {};
    \node (ebase4) [rock6, base right=of ebase3] {};
    \node (ebase5) [rock3, base right=of ebase4] {};
    \node (ebase6) [rock1, base right=of ebase5, yshift=-2.5mm] {};
    \node (ebase7) [rock2, base right=of ebase6] {};
    \node (e1e1) [rock3, right=of ebase2, yshift=2.5mm] {};
    \node (e1e2) [rock1, right=of e1e1, yshift=-2.5mm] {};
    \node (e1e3) [rock6, right=of ebase5, yshift=2.5mm] {};
    \node (e1e4) [rock3, right=of e1e3] {};
    \node (e1e5) [rock3, right=of e1e4, yshift=-2.5mm] {};
    \node (e1e6) [rock, right=of e1e5, yshift=-2.5mm] {};
    \node (e1e7) [rock1, right=of e1e6] {};
    \node (e2e1) [rock5, right=of e1e1, yshift=2.5mm] {};
    \node (e2e2) [rock1, right=of e2e1, yshift=-2.5mm] {};
    \node (e2e3) [rock9, right=of e1e5, yshift=2.5mm] {};
    \node (e2e4) [rock, right=of e2e3] {};
    \node (e3e1) [rock, right=of e2e1, yshift=2.5mm] {};
    \node (e3e2) [rock8, right=of e3e1] {};
    \node (e3e3) [rock7, right=of e3e2, yshift=-5mm] {};
    \node (e3e4) [rock1, right=of e3e3, yshift=-2.5mm] {};
    \node (e4e1) [rock9, left=of e3e2] {};
    \node (e4e2) [rock6, right=of e3e3, yshift=2.5mm] {};
    \node (e4e3) [rock, right=of e4e2] {};
    \node (e5e2) [rock3, left=of e3e2, yshift=5mm] {};
    \node (e5e1) [rock3, left=of e5e2, yshift=-2.5mm] {};
    \node (e5e3) [rock6, right=of e3e2, yshift=5mm] {};
    \node (e5e4) [rock5, right=of e5e3] {};
    \node (e5e5) [rock, right=of e5e4, yshift=-2.5mm] {};
    \node (e6e1) [rock, right=of e5e2, yshift=2.5mm] {};
    \node (e6e2) [rock3, right=of e5e4, yshift=2.5mm] {};
    \node (e7e3) [rock3, left=of e6e2, yshift=2.5mm] {};
    \node (e7e2) [rock3, left=of e7e3, yshift=-2.5mm] {};
    \node (e7e1) [rock9, left=of e7e2, yshift=-2.5mm] {};
    \node (e8e2) [rock5, left=of e7e2, yshift=2.5mm] {};
    \node (e8e1) [rock6, left=of e8e2, yshift=-2.5mm] {};
    \node (e9e1) [rock6, right=of e8e2, yshift=2.5mm] {};
    \node (e10e1) [rock, above=of e8e2, xshift=1.25mm] {};
    \node (e11e1) [rock6, above=of e10e1] {};

\end{tikzpicture}

\end{document}

I finally got the output to look reasonable:

standalone towers

The next step was to include the figure in the document:

\documentclass[12pt]{article}
\usepackage{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\begin{document}

\begin{figure}
  \centering
    \input{standalone-tower}
\end{figure}

\end{document}

However, now the towers do not look quite right:

input towers

I can (and have) tweaked the left hand tower to make it look more-or-less OK but neither tower looks as good as it did standalone.

I have two questions:

  1. What causes the misalignment when the code is \input but not when compiled standalone?
  2. How could or should I have gone about constructing the original towers to ensure that they would give the same results when compiled in the main document as when compiled standalone?
7
  • 2
    You are using different font sizes: in standalone \normalfont has size 10pt, in your article you are using 12pt. Apr 28, 2014 at 15:23
  • 1
    You may add inner sep=0 as global option of your tikzpicture (its default value is .3333em that depends on current font size). Apr 28, 2014 at 15:32
  • If you have your figure done with standalone you can also include it as pdf with includegraphics.
    – Ignasi
    Apr 28, 2014 at 15:33
  • So the font size matters because it affects inner sep? I would have thought of font size had there been any text in the image or had I specified dimensions in terms which depend on font size. But that didn't occur to me in this case. I assume 0pt is the same regardless and the 1pt only affects the corners, not the overall size. Thanks. @PaulGaborit do you want to write an answer? Ulrike Fischer's comment wouldn't have meant anything to me even though I understand the point now I've got your comment. (I knew I had different font sizes but couldn't see why that would matter here.)
    – cfr
    Apr 28, 2014 at 21:10
  • @Ignasi I know but for complex reasons to do with difficulties printing in colour if I do that, I'd rather minimise the number of things I include as separate files. Included PDFs are unavoidable, unfortunately, but they are a great deal of trouble and I'd prefer to minimise the complications.
    – cfr
    Apr 28, 2014 at 21:12

1 Answer 1

7

Your picture depends implicitly on the size of the current font... via the default value of inner sep (.3333em). In your standalone figure, the current size is 10pt. In your document, the current size is 12pt.

You may add inner sep=0 to the global options of your tikzpicture for breaking this dependency.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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