我在 Tikz 中建造了两座塔。由于包含这些塔的文档需要一段时间才能编译完成,而且我的 Tikz 技能有限(所以我需要经常编译以检查我是否做了一些疯狂的事情),所以我在standalone
绘制图形时使用了它们。
以下是已去除颜色和标签的塔的最小化版本:
\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}
我最终得到了看起来合理的输出:
下一步是将该图纳入文档中:
\documentclass[12pt]{article}
\usepackage{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\begin{document}
\begin{figure}
\centering
\input{standalone-tower}
\end{figure}
\end{document}
然而,现在这些塔看起来不太对劲:
我可以(并且已经)调整了左侧的塔,使其看起来或多或少还可以,但两座塔看起来都不如独立时好看。
我有两个问题:
- 是什么原因导致代码在编译时出现错位
\input
,但在独立编译时却不会出现错位? - 我怎样才能或应该怎样构建原始塔以确保它们在主文档中编译时与独立编译时产生相同的结果?
答案1
您的图片隐含地取决于当前字体的大小...通过默认值inner sep
( .3333em
)。在您的独立图形中,当前大小为 10pt。在您的文档中,当前大小为 12pt。
您可以添加inner sep=0
到全局选项中tikzpicture
以打破这种依赖关系。