| 1 |
% !TeX spellcheck = en_US |
| 2 |
% !TeX root = tikz-ext-manual.tex |
| 3 |
% Copyright 2022 by Qrrbrbirlbel |
| 4 |
% |
| 5 |
% This file may be distributed and/or modified |
| 6 |
% |
| 7 |
% 1. under the LaTeX Project Public License and/or |
| 8 |
% 2. under the GNU Free Documentation License. |
| 9 |
% |
| 10 |
\section{Node Families} |
| 11 |
\begin{tikzlibrary}{ext.node-families} |
| 12 |
With this library the user can instruct multiple nodes to have the same |
| 13 |
width, height, text width, text height or text width. |
| 14 |
This uses the hook \referenceKeyandIndexO{execute at end picture} to write the nodes' |
| 15 |
measurements to the \filetype{aux} file. |
| 16 |
|
| 17 |
\inspiration{NodeFam-Q}{NodeFam-A} |
| 18 |
\end{tikzlibrary} |
| 19 |
|
| 20 |
Before we get to the interesting keys, a common prefix can be set for the families' names. |
| 21 |
Initially this is |\pgfpictureid-| so that families of different pictures don't interact. |
| 22 |
\begin{key}{/\tikzext/node family/prefix=\meta{prefix}(initially \string\pgfpictureid-)} |
| 23 |
\keycompat{tikz/node family} |
| 24 |
The family names are prefixed with the value of |/tikz/ext/node family/prefix|. |
| 25 |
\end{key} |
| 26 |
|
| 27 |
\subsection{Externalization} |
| 28 |
As this library usually needs multiple compilations |
| 29 |
to produce stable pictures it is incompatible |
| 30 |
with the \referenceLibraryandIndexO{external} library. |
| 31 |
|
| 32 |
However, the library provides support for the |
| 33 |
\referencePackageandIndexO{memoize} \cite{memoize} package. |
| 34 |
\subsection{Text Box} |
| 35 |
\label{ssec:nf-text} |
| 36 |
The following keys~-- when setup, see below~-- work with every shape with one single node part.% |
| 37 |
\footnote{Technically, it will also work with shapes with multiple node parts but it will only affect the main node part.} |
| 38 |
Initially though, only \referenceShapeandIndexO{circle} and \referenceShapeandIndexO{rectangle} are set up that way. |
| 39 |
\begin{key}{/\tikzext/node family/text height=\meta{name} (initially \{\})} |
| 40 |
\keycompat{tikz/node family} |
| 41 |
Nodes with the same \meta{name} will have the same text height. |
| 42 |
An empty \meta{name} disables the evaluation by the library. |
| 43 |
\end{key} |
| 44 |
|
| 45 |
\begin{key}{/\tikzext/node family/text depth=\meta{name} (initially \{\})} |
| 46 |
\keycompat{tikz/node family} |
| 47 |
Nodes with the same \meta{name} will have the same text depth. |
| 48 |
An empty \meta{name} disables the evaluation by the library. |
| 49 |
\end{key} |
| 50 |
|
| 51 |
\begin{key}{/\tikzext/node family/text width=\meta{name} (initially \{\})} |
| 52 |
\keycompat{tikz/node family} |
| 53 |
Nodes with the same \meta{name} will have the same text width. |
| 54 |
An empty \meta{name} disables the evaluation by the library. |
| 55 |
\end{key} |
| 56 |
|
| 57 |
\begin{key}{/\tikzext/node family/text=\meta{name}} |
| 58 |
\keycompat{tikz/node family} |
| 59 |
Sets |text height|, |text depth| and |text width|. |
| 60 |
\end{key} |
| 61 |
|
| 62 |
Since the width of the node's content's box is setup much earlier, |
| 63 |
the previous key only extends the width of that box which would make the text |
| 64 |
seem as if it where aligned to the left. |
| 65 |
With |text width family align| this can changed. |
| 66 |
\begin{key}{/\tikzext/node family/text width align=\meta{alignment}(initially center)} |
| 67 |
\meta{alignment} is one of |left|, |center| or |right|. |
| 68 |
|
| 69 |
\begin{codeexample}[preamble=\usetikzlibrary{positioning,ext.node-families},/tikz/node distance=.5cm] |
| 70 |
\tikzexternaldisable % ext.node-families does not work with active externalization |
| 71 |
\begin{tikzpicture}[nodes={rectangle, draw, ext/node family={text width=manual, text width align=right}}] |
| 72 |
\node (a) {Foo}; |
| 73 |
\node[below=of a] (b) {Foobar}; |
| 74 |
\end{tikzpicture} |
| 75 |
\end{codeexample} |
| 76 |
\end{key} |
| 77 |
|
| 78 |
\begin{key}{/\tikzext/node family/setup shape=\meta{shape}} |
| 79 |
\keycompat{tikz/node family} |
| 80 |
This adds instructions to the \meta{shape}'s definition which |
| 81 |
adjust the text box's dimensions according to the family. |
| 82 |
|
| 83 |
This should be only used once per shape. |
| 84 |
\end{key} |
| 85 |
|
| 86 |
\subsection{Minimum Width/Height} |
| 87 |
While the keys of the previous subsection work well enough for nodes of the same shape |
| 88 |
(and the same |inner sep|s), for different node shapes the text box dimensions will be used |
| 89 |
differently for the node's total dimension. |
| 90 |
|
| 91 |
For this, the following keys are necessary. |
| 92 |
When one of the keys are used the values of |minimum width| and/or |minimum height| are set to |ext_nf_width| or |nf_height| respectively. |
| 93 |
\begin{key}{/\tikzext/node family/width=\meta{name} (initially \{\})} |
| 94 |
\keycompat{tikz/node family} |
| 95 |
Nodes with the same \meta{name} will have the same \referenceKeyandIndexO[/pgf/]{minimum width}. |
| 96 |
An empty \meta{name} disables the evaluation by the library. |
| 97 |
\begin{codeexample}[preamble=\usetikzlibrary{positioning,ext.node-families},/tikz/node distance=.5cm] |
| 98 |
\tikzexternaldisable % ext.node-families does not work with active externalization |
| 99 |
\begin{tikzpicture}[nodes={rectangle, draw, ext/node family/width=manual}] |
| 100 |
\node (a) {Foo}; |
| 101 |
\node[below=of a] (b) {Foobar}; |
| 102 |
\end{tikzpicture} |
| 103 |
\end{codeexample} |
| 104 |
\end{key} |
| 105 |
\begin{key}{/\tikzext/node family/height=\meta{name} (initially \{\})} |
| 106 |
\keycompat{tikz/node family} |
| 107 |
Nodes with the same \meta{name} will have the same \referenceKeyandIndexO[/pgf/]{minimum height}. |
| 108 |
An empty \meta{name} disables the evaluation by the library. |
| 109 |
\end{key} |
| 110 |
\begin{key}{/\tikzext/node family/size=\meta{name}} |
| 111 |
\keycompat{tikz/node family} |
| 112 |
Sets both |height| and |width|. |
| 113 |
\end{key} |
| 114 |
|
| 115 |
\clearpage |
| 116 |
\subsection{More shapes that support the keys \texttt{width} and \texttt{height}} |
| 117 |
\begin{tikzlibrary}{ext.node-families.shapes.geometric} |
| 118 |
This library adds support for the keys \referenceKeyandIndex[/\tikzext/node family/]{width} and |
| 119 |
\referenceKeyandIndex[/\tikzext/node family/]{height} for the shapes of |
| 120 |
the \pgfname\space library \referenceLibraryandIndexO{shapes.geometric}. |
| 121 |
|
| 122 |
\inspirationQ{NodeFam-Ellipse} |
| 123 |
\end{tikzlibrary} |
| 124 |
The shapes are also setup for the keys from subsection~\ref{ssec:nf-text}. |
| 125 |
|
| 126 |
\begin{codeexample}[width=9cm,preamble=\usetikzlibrary{ext.node-families.shapes.geometric}] |
| 127 |
\tikzexternaldisable % ext.node-families does not work with active externalization |
| 128 |
\begin{tikzpicture} |
| 129 |
\foreach \cnt[count=\Cnt] in {a,...,h} |
| 130 |
\node[draw, diamond, ext/node family/text=aTOh] (\cnt) |
| 131 |
at (right:\Cnt) {\cnt}; |
| 132 |
\draw[help lines] (a.south) -- (h.south) (a.north) -- (h.north) (a.base-|a.west) -- (h.base-|h.east); |
| 133 |
\end{tikzpicture} |
| 134 |
\end{codeexample} |
| 135 |
\endinput |