As said in the comment, something like 5+15mm
will be interpreted as 5pt+15mm
(source: somewhere in the PGF manual). But you can change the coordinate system to use the unit mm
with x=1mm, y=1mm
, then you are able to use 5 + 15
which translate to 20mm
.
Toscho’s solution (with a path picture
instead of a separate node) would then look like Code A.
Though you didn’t asked for, I created a slightly more powerful holder
key that accepts a parameter in the form of <val1>:<val2>
or <val1>:<val2>:<val3>
(for the last node). You can also give no argument at all, then :
will be used (i.e. no contents but a box in the right-upper corner). The <vali>
can also be one of x
, X
or /
which will draw a black box or a black triangle (this may not be the best approach).
I haven’t realized that it is also possible to only have a black box, this will need to be input as :X
. The holder
stuff can be improved so that you can use holder=X
if needed.
The chains
library helps us to easily place the nodes.
Code A
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
use unit/.code={
\def\myUnit{#1}%
\pgfkeysalso{x=1#1,y=1#1}%
},
set sizes/.code args={#1and#2}{\def\bigside{#1}\def\smallside{#2}},
?/.style={
path picture={
\node[dereche,anchor=north east] at (path picture bounding box.north east) {#1};
}
}
}
\begin{document}
\begin{tikzpicture}[
node distance=0mm and 0mm,
use unit=mm,
set sizes=15 and 5,
box/.style={
shape=rectangle, % the default
draw,
fill=white
},
holder/.style={
box,
minimum size=\bigside\myUnit
},
dereche/.style={
box,
minimum size=\smallside\myUnit
}
]
\node[holder, ?=4] (n1) at (0,0) {5};
\node[holder, ?=5] (n2) at (\bigside*1,0) {14};
\node[holder] (n3) at (\bigside*2,0) {29};
\node[holder] (n4) at (\bigside*3,0) {49};
\node[holder] (n5) at (\bigside*4,0) {60};
\node[holder] (n6) at (\bigside*5,0) {61};
\node[holder] (n7) at (\bigside*6,0) {77};
\node[holder] (n8) at (\bigside*7,0) {97};
\node[holder] (n9) at (\bigside*8,0) {117};
\node[holder] (n10) at (\bigside*9,0) {133};
\end{tikzpicture}
\end{document}
Code B
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,
chains}
\makeatletter
\def\qrr@bowl@X{x}
\def\qrr@bowl@slash{/}
\tikzset{
use unit/.code={
\def\myUnit{#1}%
\pgfkeysalso{x=1#1,y=1#1}% we don't really need this anymore
},
set sizes/.code={\def\bigside{#1}\def\smallside{(#1/3)}},
box/.style={
shape=rectangle, % the default
draw,
outer sep=+0pt,
},
holder/.style={
box,
minimum size=\bigside\myUnit,
font=\bfseries\Large,
text height=+2em,
qrr@holder=#1,
},
holder/.default=:,
mini/.style={
box,
minimum width=\smallside*1\myUnit,
minimum height=\smallside*1\myUnit,
outer sep=+0pt,
% text height=,
% font=,
qrr@mini=#1
},
mini/.default=,
qrr@mini/.code=%
\lowercase{\def\pgf@tempa{#1}}%
\ifx\pgf@tempa\qrr@bowl@X
\pgfkeysalso{qrr@X}%
\else\ifx\pgf@tempa\qrr@bowl@slash
\pgfkeysalso{qrr@slash}%
\else
\pgfkeysalso{label={center:{#1}}}% the labels also needs [font=,text height=] if used with a path picture
\fi
\fi,
qrr@holder/.code args={#1:#2}{%
\pgfutil@in@:{#2}%
\ifpgfutil@in@
\pgfkeysalso{qrr@@holder={#1:#2}}%
\else
\pgfkeysalso{qrr@@holder={:#1:#2}}%
\fi
},
qrr@@holder/.style args={#1:#2:#3}{% we could have used simple rectangles instead of nodes ...
% path picture={
append after command={%
\pgfextra
\begingroup
% \node[mini=#3, anchor=north east] (@qrr@) at (path picture bounding box.north east) {};
\node[mini=#3, anchor=east] (@qrr@) at ([yshift=-\smallside*.5\myUnit]\tikzlastnode.north east) {};
\tikzset{mini/.append style={left=+0pt of @qrr@}}
\if\relax\detokenize{#1}\relax
\node[mini=#2, shape=rectangle, draw=none, minimum width={(\bigside-\smallside)*1\myUnit}] {};
\else
\node[mini=#2, minimum width={(\bigside-\smallside-\smallside)*1\myUnit}] (@qrr@) {};
\node[mini=#1, shape=rectangle, draw=none, minimum width={(\bigside-\smallside-\smallside)*1\myUnit}] {};
\fi
\endgroup
\endpgfextra
}
},
qrr@X/.style={fill=black},
qrr@slash/.style={path picture={\fill[black](path picture bounding box.south west)-|(path picture bounding box.north east)--cycle;}}
}
\makeatother
\begin{document}
\begin{tikzpicture}[
use unit=mm,
set sizes=15,
% just for fun a little bubblier:
mini/.append style={shape=circle},
holder/.append style={rounded corners=\smallside*.5\myUnit}
]
\begin{scope}[start chain=going right, holder/.append style={on chain}, node distance=+0pt]
\node[holder=1:4] {5};
\node[holder=4:5] {14};
\node[holder=6:/] {29};
\node[holder=5:/] {49};
\node[holder= :x] {60};
\node[holder=0:1] {61};
\node[holder=7:/] {77};
\node[holder=6:/] {97};
\node[holder= :X] {117};
\node[holder=2:/:6] {133};
\end{scope}
\end{tikzpicture}
\end{document}
Output
Output (bubbly)
5+15mm
will evaluated to5pt+15mm
by TikZ. But: instead of using\unit
simply set the x and y vectormm
:\begin{tikzpicture}[x=1mm,y=1mm,node distance=0mm and 0mm]