summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/tikz-ext/tikz-ext-manual-en-pgf-shapes-uncentered.tex
blob: cb79e4ac7b2e41048b579af60cc19a12cd0f3b9d (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
% !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.
%

\section{Shape: Uncentered Rectangle}
\begin{pgflibrary}{ext.shapes.uncenteredrectangle}
  A rectangle that has a variable horizontal center with three node parts.
  \inspiration{UncRectCD-Q,UncRectForest-Q}{UncRectCD-A,UncRectForest-A}
\end{pgflibrary}
\begin{shape}{uncentered rectangle}

For some alignment problems, this shape could be useful.

It has three node parts: the standard |text| part,
the |left| part that is to the left of |text|
and the |right| part that is to the right of |text|.

When edges are to be connected with this shape, the
following key changes to which inner center this shape will
calculate the appropriate point on the border.
\begin{key}{/pgf/uncentered rectangle center=\meta{left}\textrm{ or }\meta{text}\textrm{ or }\meta{right}\textrm{ or }\meta{real} (initially text)}
  Sets the center that is to be used for connecting edges.
  
  This will also move the anchors |north|, |mid|, |base| and |south| along.
  In the picture below, this are marked red.
\end{key}

For support of the \referenceLibraryandIndexO{cd} library of the |tikz-cd| package,
this shape also supports a dynamic $y$ value for its anchors |center|, |west| and |east|.
\begin{key}{/pgf/uncentered rectangle center yshift=\meta{dimension} (initially \{\})}
  This determines the distance between the baseline and the |center| anchors.
  
  If \meta{dimension} is empty, the real center will be used which is the default.
  
  For use with |cd|, set this to |axis_height|.
  Due to a bug with \referenceKeyandIndexO{execute at end node}
  this needs a lot of fixing to be able to use in a commutative diagram, though.

\tikzexternaldisable
\catcode`\|=12
\begin{codeexample}[leave comments, preamble=\usetikzlibrary{cd, ext.shapes.uncenteredrectangle}]
\makeatletter
\tikzcdset{
  every diagram/.append style={
    /pgf/uncentered rectangle center=text,
    /tikz/math align/.style={
      shape=uncentered rectangle,
      /pgf/uncentered rectangle center yshift=axis_height,
      commutative diagrams/math mode=false},
    /tikz/math align left/.style={
      math align,
      /utils/exec={\def\mathalign####1=####2;{$####2$\nodepart{left}$####1={}$}}},
    /tikz/math align right/.style={
      math align,
      /utils/exec={\def\mathalign####1=####2;{$####1$\nodepart{right}${}=####2$}}},
    /tikz/matrix of math nodes/.style={
      matrix of nodes,
      nodes={
        execute at begin node=\iftikzcd@mathmode$\fi,
        execute at end node  =\iftikzcd@mathmode$\fi}}}}
\makeatother
\tikzcdset{install C shortcut/.code=\newcommand*\C[1]{C_{\%_{##1}}}}
\begin{tikzcd}[
  install C shortcut,
  sep=tiny,
  arrows={-, gray},
  cells={font=\strut, inner xsep=.2ex, inner ysep=.1ex}
]
\C{1} \drar &         & |[math align right]| \mathalign m_{r_1} = \C{2}-C_\%; \dlar\\
            & C_\% \\
\C{2} \urar &         & |[math align right]| \mathalign m_{r_2} = \C{1}-C_\%; \ular
\end{tikzcd}
\end{codeexample}
\end{key}
\pagebreak
\begin{codeexample}[preamble=\usepgflibrary{ext.shapes.uncenteredrectangle}]
\begin{tikzpicture}[style north/.style=red, style south/.style=red, style center/.style=red, style base/.style=red, style mid/.style=red]
\Huge
\node[shape example, name=n, uncentered rectangle]
  {centered \nodepart{left} Un \nodepart{right} \space Rectangle\vrule width 1pt height 2cm}
  foreach \anchor/\pos in {
   north west/above left, north/below, north east/above right, real north/above,  left north/above, right north/above, text north/above,
         west/left,      center/above,       east/right,       real center/above, left center/above,right center/above,text center/below,
     mid west/left,         mid/left,    mid east/right,       real mid/above,    left mid/above,   right mid/above,   text mid/above,
    base west/left,        base/right,  base east/right,       real base/below,   left base/below,  right base/below,  text base/below,
   south west/below left, south/above, south east/below right, real south/below,  left south/below, right south/below, text south/below,
                             10/right,        130/below,                          left/left,        right/right,       text/right}{
    plot[mark=x, only marks] coordinates {(n.\anchor)}
    node[inner sep=.1em, style \anchor/.try, style/.expand once=\pos] {\tiny\ttfamily\anchor}};
\end{tikzpicture}
\end{codeexample}
\end{shape}
\endinput