| 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 |
\clearpage |
| 11 |
\section{Scaling Pictures to a Specific Size} |
| 12 |
\label{library:scalepicture} |
| 13 |
|
| 14 |
\begin{tikzlibrary}{ext.scalepicture} |
| 15 |
This library scales \tikzname\ pictures to a specific width or height |
| 16 |
by scaling the whole picture. |
| 17 |
\end{tikzlibrary} |
| 18 |
|
| 19 |
\begin{multicols}{2} |
| 20 |
If one of the keys below are used on a \tikzname\ picture, meaning |
| 21 |
as an option to |\tikzpicture| or \texttt{\textbackslash begin\{tikzpicture\}}, |
| 22 |
the size of the picture% |
| 23 |
\footnote{This is the size of the pseudo-node \texttt{current bounding box}.} |
| 24 |
will be measured and written to the \filetype{aux} file |
| 25 |
so that it will be available at the next compilation run |
| 26 |
and an appropriate scaling for the picture can be installed. |
| 27 |
|
| 28 |
\begin{command}{\tikzextpicturewidth} |
| 29 |
Returns the last measured width of the picture. |
| 30 |
|
| 31 |
This will expand to |0pt| if the picture hasn't been measured before. |
| 32 |
\end{command} |
| 33 |
\begin{command}{\tikzextpictureheight} |
| 34 |
Returns the last measured height of the picture. |
| 35 |
|
| 36 |
This will expand to |0pt| if the picture hasn't been measured before. |
| 37 |
\end{command} |
| 38 |
|
| 39 |
\begin{stylekey}{/\tikzext/save picture size}\keycompat{tikz} |
| 40 |
This key is usually used by the keys provided by this library. |
| 41 |
Normally, this is not needed to be explicitly given. |
| 42 |
\end{stylekey} |
| 43 |
|
| 44 |
\subsection{Externalization} |
| 45 |
As this library usually needs multiple compilations |
| 46 |
to produce stable pictures it is incompatible |
| 47 |
with the \referenceLibraryandIndexO{external} library. |
| 48 |
|
| 49 |
However, the library provides support for the |
| 50 |
\referencePackageandIndexO{memoize} \cite{memoize} package. |
| 51 |
When it is used the arguments to the keys below |
| 52 |
will be saved as the context of the memo. |
| 53 |
This means that the arguments need to be a valid |
| 54 |
\referenceCommandandIndexExt{\dimexpr} expression. |
| 55 |
|
| 56 |
\subsection{Keeping the aspect ratio} |
| 57 |
The following \emph{unstarred} keys do not change the aspect ratio of the picture. |
| 58 |
|
| 59 |
\begin{key}{/\tikzext/picture width=\meta{dimension}}\keycompat{tikz} |
| 60 |
Scales the picture so that the width of the picture will be \meta{dimension}. |
| 61 |
This will keep the aspect ratio the same. |
| 62 |
\end{key} |
| 63 |
|
| 64 |
\begin{key}{/\tikzext/minimum picture width=\meta{dimension}}\keycompat{tikz} |
| 65 |
As above but will not change the size of the picture |
| 66 |
if its width is greater than \meta{dimension}. |
| 67 |
\end{key} |
| 68 |
|
| 69 |
\begin{key}{/\tikzext/maximum picture width=\meta{dimension}}\keycompat{tikz} |
| 70 |
As above but will not change the size of the picture |
| 71 |
if its width is less than \meta{dimension}. |
| 72 |
\end{key} |
| 73 |
|
| 74 |
\begin{key}{/\tikzext/picture height=\meta{dimension}}\keycompat{tikz} |
| 75 |
Scales the picture so that the height of the picture will be \meta{dimension}. |
| 76 |
This will keep the aspect ratio the same. |
| 77 |
\end{key} |
| 78 |
|
| 79 |
\begin{key}{/\tikzext/minimum picture height=\meta{dimension}}\keycompat{tikz} |
| 80 |
As above but will not change the size of the picture |
| 81 |
if its height is greater than \meta{dimension}. |
| 82 |
\end{key} |
| 83 |
|
| 84 |
\begin{key}{/\tikzext/maximum picture height=\meta{dimension}}\keycompat{tikz} |
| 85 |
As above but will not change the size of the picture |
| 86 |
if its height is less than \meta{dimension}. |
| 87 |
\end{key} |
| 88 |
|
| 89 |
\begin{key}{/\tikzext/minimum picture size=\marg{width}\marg{height}}\keycompat{tikz} |
| 90 |
Scales the picture so that its height will be at least \meta{width} |
| 91 |
and its height will be at least \meta{height}. |
| 92 |
\end{key} |
| 93 |
|
| 94 |
\begin{key}{/\tikzext/maximum picture size=\marg{width}\marg{height}}\keycompat{tikz} |
| 95 |
Scales the picture so that its height will be at most \meta{width} |
| 96 |
and its height will be at most \meta{height}. |
| 97 |
\end{key} |
| 98 |
|
| 99 |
\subsection{Changing the aspect ratio} |
| 100 |
The following \emph{starred} keys do change the aspect ratio. |
| 101 |
\begin{key}{/\tikzext/picture width*=\meta{dimension}}\keycompat{tikz} |
| 102 |
Scales the picture so that the width of the picture will be \meta{dimension}. |
| 103 |
This will only scale the $x$ axis. |
| 104 |
\end{key} |
| 105 |
|
| 106 |
\begin{key}{/\tikzext/minimum picture width*=\meta{dimension}}\keycompat{tikz} |
| 107 |
As above but will not change the size of the picture |
| 108 |
if its width is greater than \meta{dimension}. |
| 109 |
\end{key} |
| 110 |
|
| 111 |
\begin{key}{/\tikzext/maximum picture width*=\meta{dimension}}\keycompat{tikz} |
| 112 |
As above but will not change the size of the picture |
| 113 |
if its width is less than \meta{dimension}. |
| 114 |
\end{key} |
| 115 |
|
| 116 |
\begin{key}{/\tikzext/picture height*=\meta{dimension}}\keycompat{tikz} |
| 117 |
Scales the picture so that the height of the picture will be \meta{dimension}. |
| 118 |
This will only scale the $y$ axis. |
| 119 |
\end{key} |
| 120 |
|
| 121 |
\begin{key}{/\tikzext/minimum picture height*=\meta{dimension}}\keycompat{tikz} |
| 122 |
As above but will not change the size of the picture |
| 123 |
if its height is greater than \meta{dimension}. |
| 124 |
\end{key} |
| 125 |
|
| 126 |
\begin{key}{/\tikzext/maximum picture height*=\meta{dimension}}\keycompat{tikz} |
| 127 |
As above but will not change the size of the picture |
| 128 |
if its height is less than \meta{dimension}. |
| 129 |
\end{key} |
| 130 |
|
| 131 |
\begin{key}{/\tikzext/picture size*=\marg{width}\marg{height}}\keycompat{tikz} |
| 132 |
Scales the picture so that its width will be \meta{width} |
| 133 |
and its height will be \meta{height}. |
| 134 |
|
| 135 |
This will scale both axes but independent from each other. |
| 136 |
\end{key} |
| 137 |
\end{multicols} |