This is my MWE:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[draw=red,very thin, align=left,every node/.style={draw,rectangle}]
\node (unaligned) {
\ttfamily
parameters: a\\
\phantom{parameters:} b};
\node[node font=\ttfamily, right=of unaligned] {
parameters: a\\
\phantom{parameters:} b};
\end{tikzpicture}
\end{document}
The difference is obvious, a and b are not aligned in the first node. Apparently, the \phantom{...}
is not typeset using the \ttfamily
, hence it's size is different. I could have used the incantation font=\ttfamily
, which would work just as fine as node font=\ttfamily
.
The PGF manual only mentions this a bit vaguely:
Naturally, you can just use a font command like \small or \rm at the beginning of a node. However, the following two options make it easier to set the font used in nodes on a general basis.
and
The keyword node is typically followed by some options and then some text between curly braces. This text is put inside a normal TEX box (if the node specification directly follows a coordinate, which is usually the case, TikZ is able to perform some magic so that it is even possible to use verbatim text inside the boxes)
Apparently I cannot "just use a font command". Why? Is this connected to the aforementioned "magic" in any way? Also, what is a "normal TeX box"? I am aware of \parbox
, \mbox
and \minipage
, and they all behave a little bit differently with respect to indentation and similar things.
font
ornode font
. (The first scenario can also be achieved with\node[execute at begin node=\ttfamily,...
.)