% !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 |ext_corner north east|, |ext_corner north west|, |ext_corner south west| and |ext_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{codeexample}[width=.45\linewidth,preamble=\usetikzlibrary{ext.positioning-plus}]
\Huge
\begin{tikzpicture}
\node[name=s,shape=circle,shape example,scale=.75,outer sep=auto]
  {Circle\vrule width 1pt height 2cm};
\foreach \anchor/\placement in {
  north west/below right, north/above, north east/below left,
  west/left, center/above, east/right,
  mid west/right, mid/above, mid east/left,
  base west/left, base/below, base east/right,
  south west/above right, south/below, south east/above left,
  text/left, 10/right, 130/above}
  \draw[node font=\scriptsize, shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
    node[\placement] {\texttt{(s.\anchor)}};
\draw (s.ext_corner north west) rectangle (s.ext_corner south east);
\foreach \anchor/\placement in {
  corner north west/above, corner north east/above,
  corner south west/below, corner south east/below}
  \draw[node font=\scriptsize, red, shift=(s.ext_\anchor)] plot[mark=x] coordinates{(0,0)}
    node[\placement] {\texttt{(s.ext\textunderscore\anchor)}};
\end{tikzpicture}
\end{codeexample}

\clearpage
\subsection{Useful placement keys for vertical and horizontal alignment}
\begin{multicols}{2}
\begin{keylist}[/\tikzext]{%
         left=\opt{\meta{specification}} (default 0pt),
        right=\opt{\meta{specification}} (default 0pt),
        above=\opt{\meta{specification}} (default 0pt),
        below=\opt{\meta{specification}} (default 0pt),
  above  left=\opt{\meta{specification}} (default 0pt),
  below  left=\opt{\meta{specification}} (default 0pt),
  above right=\opt{\meta{specification}} (default 0pt),
  below right=\opt{\meta{specification}} (default 0pt),
  mid    left=\opt{\meta{specification}} (default 0pt),
  mid   right=\opt{\meta{specification}} (default 0pt),
  base   left=\opt{\meta{specification}} (default 0pt),
  base  right=\opt{\meta{specification}} (default 0pt)%
}
  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}, width=.3\linewidth]
\begin{tikzpicture}[nodes=draw]
\node (A) {A} node[below=of A] (BCD) {BCD};
\node[ext/right=   of |(A)(BCD)] (c) {};
\node[ext/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}
  
  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.}
\end{keylist}

\newcolumn
The |fit|ting functionality is also available without the placement.
\begin{keylist}[/\tikzext]{%
  fit bounding box=\meta{list of coordinates},
  span vertical=\meta{list of coordinates},
  span horizontal=\meta{list of coordinates},
  span=\meta{list of coordinates}}
These all create a rectangular node with the name |ext_fit bounding box|
that encompasses the \meta{list of coordinates}.

The |span vertical| key will also set \referenceKeyandIndexO[/pgf/]{minimum height}
to the height of this bounding box

The |span horizontal| key will also set \referenceKeyandIndexO[/pgf/]{minimum width}
to the width of this bounding box

The last one combines |span vertical| and |span horizontal|.
\end{keylist}

\begin{keylist}[/\tikzext]{%
  north  left=\opt{\meta{specification}} (default 0pt),
  south  left=\opt{\meta{specification}} (default 0pt),
  north right=\opt{\meta{specification}} (default 0pt),
  south right=\opt{\meta{specification}} (default 0pt),
  west  above=\opt{\meta{specification}} (default 0pt),
  west  below=\opt{\meta{specification}} (default 0pt),
  east  above=\opt{\meta{specification}} (default 0pt),
  east  below=\opt{\meta{specification}} (default 0pt)%
}
  These work similarly to |left|, |right|, |above| and |below|
  but they are north- or south-aligned.

\begin{codeexample}[preamble=\usetikzlibrary{ext.positioning-plus}]
\begin{tikzpicture}[nodes=draw]
\node[minimum height=2cm] (a) {};
\node[minimum height=3cm, ext/north right=of a] {};
\end{tikzpicture}
\end{codeexample}
\end{keylist}

The same exist for the recently introduces corner anchors, too.
\begin{keylist}[/\tikzext]{%
  corner above left=\opt{\meta{specification}} (default 0pt),
  corner below left=\opt{\meta{specification}} (default 0pt),
  corner above right=\opt{\meta{specification}} (default 0pt),
  corner below right=\opt{\meta{specification}} (default 0pt),
  corner north  left=\opt{\meta{specification}} (default 0pt),
  corner south  left=\opt{\meta{specification}} (default 0pt),
  corner north right=\opt{\meta{specification}} (default 0pt),
  corner south right=\opt{\meta{specification}} (default 0pt),
  corner west  above=\opt{\meta{specification}} (default 0pt),
  corner west  below=\opt{\meta{specification}} (default 0pt),
  corner east  above=\opt{\meta{specification}} (default 0pt),
  corner east  below=\opt{\meta{specification}} (default 0pt)%
}
  These work the same as |above left|, |below left|, \dots\ 
  but they use the new generic corner anchors
\end{keylist}
\end{multicols}
\endinput






