Debian Codegraph @

texmf-dist/doc/latex/tikz-ext/tikz-ext-manual-en-library-paths.ortho.tex

raw
1 % !TeX root = tikz-ext-manual.tex
2 % !TeX spellcheck = en_US
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
11 \section{More Horizontal and Vertical Lines}
12 \label{library:paths.ortho}
13
14 \begin{tikzlibrary}{ext.paths.ortho}
15 This library adds new path specifications \verb!|-|!, \verb!-|-!
16 as well as |r-ud|, |r-du|, |r-lr| and |r-rl|.
17 \end{tikzlibrary}
18
19 \begin{multicols*}{2}[\subsection{Timers}]
20 New timers are setup for both the Zig-Zag and the Zig-Zig connections
21 that will be introduced in this section.
22 These can be configured through the following keys.
23 \begin{key}{/\tikzext/ortho/spacing=\meta{number} (initially 4)}\keycompat{tikz/ortho}
24 For $\meta{number} \geq 2$
25 \begin{itemize}
26 \item |pos = 0| will be at the start,\indexKeyO{pos}
27 \item |pos = 1| will be at the end,
28 \item |pos = |$\frac{1}{\meta{number}}$ will be at the first kink,
29 \item |pos = |$\frac{\meta{number}-1}{\meta{number}}$ will be at the second kink and
30 \item |pos = .5| will be in the middle of the middle part of the connection.
31 \end{itemize}
32
33 If $\meta{number} \leq 1$ then
34 \begin{itemize}
35 \item |pos = -1| will be at the start,
36 \item |pos = 2| will be at the end,
37 \item |pos = 0| will be at the first kink,
38 \item |pos = 1| will be at the second kink and
39 \item |pos = .5| will still be in the middle of the middle part of the connection.
40 \end{itemize}
41 \end{key}
42
43 \newcolumn
44 \begin{key}{/\tikzext/ortho/middle 0 to 1}\keycompat{tikz/ortho}
45 This is an alias for |spacing = 0|.
46 \end{key}
47
48 \begin{codeexample}[width=4cm,preamble=\usetikzlibrary{ext.paths.ortho}]
49 \tikz \draw (0,0) -|- (2,3)
50 foreach \p in {0.0, 0.25, 0.5, 0.75, 1.0}{
51 node [pos=\p] {\p}};
52 \end{codeexample}
53 \end{multicols*}
54
55 \pagebreak
56 \begin{multicols*}{2}[\subsection{Zig-Zag}]
57 Similar to the path operations \verb!|-! and \verb!-|! this library adds\indexPathOperationO{\protect\pgfmanualbar-}\indexPathOperationO{-\protect\pgfmanualbar}
58 the path operations \verb!|-|! (\enquote{vhv}) and \verb!-|-! (\enquote{hvh}).
59 {\catcode`\|=12
60 \begin{pathoperation}[noindex]{|-|}{\opt{\oarg{options}}\meta{coordinate or cycle}}
61 \index{---1@\protect\texttt{\protect\pgfmanualbar-\protect\pgfmanualbar} path operation}%
62 \index{Path operations!---1@\protect\texttt{\protect\pgfmanualbar-\protect\pgfmanualbar}}%
63 \pgfmanualpdflabel[\catcode`\|=12 ]{|-|}{}%
64 This operation means ``first vertical, then horizontal and then vertical again''.
65 \end{pathoperation}
66 \begin{pathoperation}[noindex]{-|-}{\opt{\oarg{options}}\meta{coordinate or cycle}}
67 \index{--1@\protect\texttt{-\protect\pgfmanualbar-} path operation}%
68 \index{Path operations!--1@\protect\texttt{-\protect\pgfmanualbar-}}%
69 \pgfmanualpdflabel[\catcode`\|=12 ]{-|-}{}%
70 This operation means ``first horizontal, then vertical and then horizontal again''.
71 \end{pathoperation}
72 }
73
74 Where the middle part (horizontal for \verb!|-|! and vertical for \verb!-|-!)
75 of these path operation end up can be specified by a ratio, a distance or
76 a factor of one base vector of the $x\!y$ coordinate system.
77
78 If used with nodes, the key |from center| toggles from where these are measured.
79 \begin{key}{/\tikzext/ortho/from center=\opt{\meta{true or false}} (default true)}\keycompat{tikz/ortho}
80 When nodes get connected the placement of the middle part of the Zig-Zag
81 and the Zig-Zig (see below) connections will be calculated from the border
82 of these nodes.
83 The middle part of the connections will be calculated from the nodes' center
84 if this key is set to |true|.
85 \end{key}
86
87 \begin{keylist}[/\tikzext/ortho]{%
88 hvh ratio=\meta{ratio} (initially 0.5),
89 vhv ratio=\meta{ratio} (initially 0.5),
90 hvvh ratio=\meta{ratio},
91 ratio=\meta{ratio}}\keylistcompat{tikz/ortho}
92 This sets the ratio for the middle part of the \verb!-|-! and/or the \verb!|-|! operation.
93
94 For values of $\meta{ratio} < 0$ and $\meta{ratio} > 1$ the Zig-Zag lines will
95 look more like the Zig-Zig lines.
96
97 \begin{codeexample}[preamble=\usetikzlibrary{ext.paths.ortho}]
98 \begin{tikzpicture}[very thick, rounded corners]
99 \draw[help lines] (-.25, -1.25) grid (2.25, 1.25);
100 \draw (0, 0) -|- (2, 1) --
101 (2, 0) -|-[ratio=.25] (0,-1) -- cycle;
102 \end{tikzpicture}
103 \end{codeexample}
104 \end{keylist}
105
106 For specifying a distance or a factor in the $x\!y$ coordinate system the same option will be used.
107 \begin{keylist}[/\tikzext/ortho]{%
108 hvh distance=\meta{distance},
109 vhv distance=\meta{distance},
110 hvvh distance=\meta{distance},
111 distance=\meta{distance}}\keylistcompat{tikz/ortho}
112
113 If \meta{distance} contains a unit, this will be used as the absolute distance
114 for the middle part of the \verb!-|-! and/or the \verb!|-|! operation.
115 If \meta{distance} doesn't contain a unit it will be interpreted
116 as the factor for the base $y$ (\verb!|-|!) or $x$ vector (\verb!-|-!)
117 in the $x\!y$ coordinate system.
118
119 This distance is measured from the target coordinate if it's negative,
120 otherwise from the start coordinate.
121
122 The |distance| option also sets the distance of the Zig-Zig path operations below.
123
124 \begin{codeexample}[width=6cm,preamble=\usetikzlibrary{ext.paths.ortho}]
125 \begin{tikzpicture}[very thick,-latex]
126 \draw[help lines,-]
127 (-.25, -.25) grid (5.25, 3.25);
128 \draw (0, 0)
129 -|-[hvh distance=+ .5cm] ++(2, 1);
130 \draw (0, 2)
131 -|-[hvh distance=+-.5cm] ++(2, 1);
132
133 \tikzset{xshift=3cm}
134 \draw (2, 1)
135 -|-[hvh distance=+ .5cm]++(-2,-1);
136 \draw (2, 3)
137 -|-[hvh distance=+-.5cm]++(-2,-1);
138 \end{tikzpicture}
139 \end{codeexample}
140 \end{keylist}
141 \end{multicols*}
142
143 \begin{multicols*}{2}[\subsection{Zig-Zig}]
144 \begin{pathoperation}{r-ud}{\opt{\oarg{options}}\meta{coordinate or cycle}}
145 This operation means ``first up, then horizontal and then down''.
146 \end{pathoperation}
147 \begin{pathoperation}{r-du}{\opt{\oarg{options}}\meta{coordinate or cycle}}
148 This operation means ``first down, then horizontal and then up''.
149 \end{pathoperation}
150 \begin{pathoperation}{r-lr}{\opt{\oarg{options}}\meta{coordinate or cycle}}
151 This operation means ``left down, then vertical and then right''.
152 \end{pathoperation}
153 \begin{pathoperation}{r-rl}{\opt{\oarg{options}}\meta{coordinate or cycle}}
154 This operation means ``first right, then vertical and then down''.
155 \end{pathoperation}
156
157 \newcolumn
158 \begin{keylist}[/\tikzext/ortho]{%
159 ud distance=\meta{distance} (initially .5cm),
160 du distance=\meta{distance} (initially .5cm),
161 lr distance=\meta{distance} (initially .5cm),
162 rl distance=\meta{distance} (initially .5cm),
163 udlr distance=\meta{distance},
164 distance=\meta{distance}}%
165 \listcompat{These were all in the \texttt{/tikz/ortho} namespace.}
166 If \meta{distance} contains a unit, this will be used as the absolute distance
167 for the middle part of the previously introduced path operation.
168 If \meta{distance} doesn't contain a unit it will be interpreted
169 as the factor for the base $y$ (|ud|/|du|) or $x$ vector (|lr|/|rl|)
170 in the $x\!y$ coordinate system.
171
172 The distance is measured from the start, never from the target coordinate.
173
174 The |distance| option also sets the distance of the Zig-Zag path operations above.
175 \end{keylist}
176 \end{multicols*}
177
178 \begin{multicols*}{2}[\subsection{Even more Horizontal and Vertical Lines}]
179
180 The following keys can be used to access vertical and horizontal line path operations.
181 \begin{keylist}[/\tikzext]{%
182 horizontal vertical,
183 vertical horizontal}\keylistcompat{tikz/horizontal vertical, /tikz}
184 These install the path operations \verb!-|! or \verb!|-! respectively as to paths%
185 \indexKeyO{to path} that can be used with the path operations |to| or |edge|.
186 \end{keylist}
187 \begin{keylist}[/\tikzext]{%
188 horizontal vertical horizontal=\opt{\meta{options}},
189 vertical horizontal vertical=\opt{\meta{options}}}\keylistcompat{tikz/horizontal vertical horizontal, /tikz}
190 These installs the operations \verb!-|-! or \verb!|-|! respectively as to paths
191 that can be used with the path operations |to| or |edge|.
192 \end{keylist}
193 \begin{keylist}[/\tikzext]{%
194 up horizontal down=\opt{\meta{options}},
195 down horizontal up=\opt{\meta{options}},
196 left vertical right=\opt{\meta{options}},
197 right vertical left=\opt{\meta{options}}}\listcompat{These were all in the \texttt{/tikz} namespace.}
198 These install the Zig-Zig path operations as to paths
199 that can be used with the path operations |to| or |edge|.
200 \end{keylist}
201
202 When connecting rectangular nodes, these keys could be useful as well.
203 They all need to be given to a |to| or |edge| path operation.
204 \begin{stylekey}{/\tikzext/only vertical second=\opt{\meta{length}} (default 0pt)}\keycompat{tikz}
205 This draws a vertical line from the start point to the target point so that
206 it connects to the target point in the center (or at its border in case it is a node).
207
208 The optional \meta{length} can be used to shift the line orthogonally to its direction.
209 \end{stylekey}
210 \begin{stylekey}{/\tikzext/only horizontal second=\opt{\meta{length}} (default 0pt)}\keycompat{tikz}
211 This draws a horizontal line from the start point to the target point so that
212 it connects to the target point in the center (or at its border in case it is a node).
213
214 The optional \meta{length} can be used to shift the line orthogonally to its direction.
215 \end{stylekey}
216 \begin{stylekey}{/\tikzext/only vertical first=\opt{\meta{length}} (default 0pt)}\keycompat{tikz}
217 This draws a vertical line from the start point to the target point so that
218 it connects to the start point in the center (or at its border in case it is a node).
219
220 The optional \meta{length} can be used to shift the line orthogonally to its direction.
221 \end{stylekey}
222 \begin{stylekey}{/\tikzext/only horizontal first=\opt{\meta{length}} (default 0pt)}\keycompat{tikz}
223 This draws a horizontal line from the start point to the target point so that
224 it connects to the start point in the center (or at its border in case it is a node).
225
226 The optional \meta{length} can be used to shift the line orthogonally to its direction.
227 \end{stylekey}
228
229 %\newcolumn
230 Since all previous key are rather cumbersome, one can install shortcuts for these.
231 \begin{stylekey}{/\tikzext/ortho/install shortcuts}\keycompat{tikz/ortho}
232 Installs the following shortcuts:\\
233 {\ttfamily
234 \begin{tabular}{l@{\hspace{.5em}${}\to{}$\hspace{.5em}}l}
235 \pgfmanualbar- & vertical horizontal \\
236 -\pgfmanualbar & horizontal vertical \\
237 -\pgfmanualbar- & horizontal vertical horizontal \\
238 \pgfmanualbar-\pgfmanualbar & vertical horizontal vertical \\[.5em]
239 \pgfmanualbar* & only vertical first \\
240 *\pgfmanualbar & only vertical second \\
241 -* & only horizontal first \\
242 *- & only horizontal second \\[.5em]
243 r-ud & up horizontal down \\
244 r-du & down horizontal up \\
245 r-lr & left vertical right \\
246 r-rl & right vertical left
247 \end{tabular}
248 }
249 \end{stylekey}
250 \end{multicols*}