summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-ext/doc/tikz-ext-manual-en-library-positioning-plus.tex
blob: 56c81376aaf14add3365add862ddb8950b25673e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
% !TeX spellcheck = en_US
% !TeX root = tikz-ext-manual.tex
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
\clearpage
\section{Positioning Plus}
\label{library:positioning-plus}
\tikzsetnextfilename{posplus}
\begin{tikzlibrary}{ext.positioning-plus}
  With the help of the \referenceLibraryandIndexO{positioning} and the \referenceLibraryandIndexO{fit} library this extends the placement of nodes.
\end{tikzlibrary}

\subsection{Useful corner anchors}
The anchors |corner north east|, |corner north west|, |corner south west| and |corner south east|
are defined as ``generic anchors'', i.\,e. they are defined for all shapes.
This is mostly useful for the placement of circular shapes.
\begin{stylekey}{/tikz/corner above left=\opt{\meta{specification}} (default 0pt)}
  Similar as \referenceKeyandIndexO{above left} of the \tikzname\space library |positioning|
  but uses the |corner north west| anchor.
\end{stylekey}
\begin{stylekey}{/tikz/corner below left=\opt{\meta{specification}} (default 0pt)}
  Similar as \referenceKeyandIndexO{below left} of the \tikzname\space library |positioning|
  but uses the |corner south west| anchor.
\end{stylekey}
\begin{stylekey}{/tikz/corner above right=\opt{\meta{specification}} (default 0pt)}
  Similar as \referenceKeyandIndexO{above right} of the \tikzname\space library |positioning|
  but uses the |corner north east| anchor.
\end{stylekey}
\begin{stylekey}{/tikz/corner below right=\opt{\meta{specification}} (default 0pt)}
  Similar as \referenceKeyandIndexO{below right} of the \tikzname\space library |positioning|
  but uses the |corner south east| anchor.
\end{stylekey}

\begin{codeexample}[width=.6\linewidth,preamble=\usetikzlibrary{ext.positioning-plus}]
\Huge
\begin{tikzpicture}
\node[name=s,shape=circle,shape example]
  {Circle\vrule width 1pt height 2cm};
\foreach \anchor/\placement in {
  north west/above left, north/above, north east/above right,
  west/left, center/above, east/right,
  mid west/right, mid/above, mid east/left,
  base west/left, base/below, base east/right,
  south west/below left, south/below, south east/below right,
  text/left, 10/right, 130/above}
  \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
    node[\placement] {\scriptsize\texttt{(s.\anchor)}};
\draw (s.corner north west) rectangle (s.corner south east);
\foreach \anchor/\placement in {
  corner north west/above left, corner north east/above right,
  corner south west/below left, corner south east/below right}
  \draw[red,shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
    node[\placement] {\scriptsize\texttt{(s.\anchor)}};
\end{tikzpicture}
\end{codeexample}

\subsection{Useful placement keys for vertical and horizontal alignment}
\begin{stylekey}{/tikz/north left=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{left} but aligns the nodes at their |north| border.
  
  This is basically the same as |left=of reference.north west, anchor=north east|.
  %
\begin{codeexample}[preamble=\usetikzlibrary{ext.positioning-plus}]
\begin{tikzpicture}[nodes=draw]
\node[minimum height=2cm] (a) {};
\node[minimum height=3cm, north right=of a] {};
\end{tikzpicture}
\end{codeexample}
\end{stylekey}
\begin{stylekey}{/tikz/north right=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{right} but aligns the nodes at their |north| border.
  
  This is basically the same as |left=of reference.north east, anchor=north west|.
\end{stylekey}
\begin{stylekey}{/tikz/south left=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{left} but aligns the nodes at their |south| border.
  
  This is basically the same as |left=of reference.south west, anchor=south east|.
\end{stylekey}
\begin{stylekey}{/tikz/south right=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{right} but aligns the nodes at their |south| border.
  
  This is basically the same as |left=of reference.south east, anchor=south west|.
\end{stylekey}
\begin{stylekey}{/tikz/west above=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{above} but aligns the nodes at their |west| border.
  
  This is basically the same as |left=of reference.north west, anchor=south west|.
\end{stylekey}
\begin{stylekey}{/tikz/west below=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{below} but aligns the nodes at their |west| border.
  
  This is basically the same as |left=of reference.south west, anchor=north west|.
\end{stylekey}
\begin{stylekey}{/tikz/east above=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{above} but aligns the nodes at their |east| border.
  
  This is basically the same as |left=of reference.north east, anchor=south east|.
\end{stylekey}
\begin{stylekey}{/tikz/east below=\opt{\meta{specification}} (default 0pt)}
  Like \referenceKeyandIndexO{below} but aligns the nodes at their |east| border.
  
  This is basically the same as |left=of reference.south east, anchor=north east|.
\end{stylekey}

The same exist for the recently introduces corner anchors, too.
\begin{stylekey}{/tikz/corner north left=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/north left| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner north right=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/north right| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner south left=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/south left| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner south right=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/south right| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner west above=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/west above| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner west below=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/west below| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner east above=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/east above| but uses the new corner anchors.
\end{stylekey}
\begin{stylekey}{/tikz/corner east below=\opt{\meta{specification}} (default 0pt)}
  The same as |/tikz/east below| but uses the new corner anchors.
\end{stylekey}

While the \meta{specification} of all these keys still accept the same form as with \tikzname,
the |ext.positioning-plus| library extends this even more.

The specification after |of| can contain a list of coordinates
(like the |fit| key of the |fit| library).
This means that the new node will be placed in relation to a rectangular bounding box
that fits around all this nodes in the list.

If this list is prefixed with \verb!|!, |-| or |+|,
the new node will also have the same height (\verb!|!),
the same width (|-|) or both as this bounding box.

\begin{codeexample}[preamble=\usetikzlibrary{ext.positioning-plus}]
\begin{tikzpicture}[nodes=draw]
\node                     (A) {A};
\node[below=of A]         (BCD) {BCD};
\node[right=of |(A)(BCD)] (c) {};
\node[below=.5:of -(A)(BCD)] (d) {};
\draw[help lines] (BCD.south west) -- (c.south east)
                  (BCD.north east) -- (d.south east);
\end{tikzpicture}
\end{codeexample}

This functionality is also available without the placement:
\begin{stylekey}{/tikz/fit bounding box=\meta{list of coordinates}}
  Creates a rectangular node with the name |fit bounding box| that encompasses
  the \meta{list of coordinates}.
\end{stylekey}
\begin{stylekey}{/tikz/span vertical=\meta{list of coordinates}}
  Creates a rectangular node with the name |fit bounding box| that encompasses
  the \meta{list of coordinates} \emph{and} sets the \referenceKeyandIndexO[/pgf]{minimum height} to
  the height of this bounding box.
\end{stylekey}
\begin{stylekey}{/tikz/span horizontal=\meta{list of coordinates}}
  Creates a rectangular node with the name |fit bounding box| that encompasses
  the \meta{list of coordinates} \emph{and} sets the \referenceKeyandIndexO[/pgf]{minimum width} to
  the width of this bounding box.
\end{stylekey}
\begin{stylekey}{/tikz/span=\meta{list of coordinates}}
  Is a combination of |/tikz/span vertical| and |/tikz/span horizontal|.
\end{stylekey}

As you maybe noticed in the example above, the \meta{specification} also allows a prefix
delimited by |:| which the |node distance| will be multiplied to with for the placement.%
\footnote{This is probably more useful when \referenceKeyandIndexO{on grid} is used.}

\endinput