| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2019 by Tobias Plüss <[email protected]> |
| 4 |
% |
| 5 |
% This file may be distributed and/or modified under the |
| 6 |
% conditions of the LaTeX Project Public License, either |
| 7 |
% version 1.3 of this license or (at your option) any later |
| 8 |
% version. The latest version of this license is in: |
| 9 |
% |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% and version 1.3 or later is part of all distributions of |
| 13 |
% LaTeX version 2005/12/01 or later. |
| 14 |
% |
| 15 |
% \fi |
| 16 |
% |
| 17 |
% \iffalse |
| 18 |
%<package>\NeedsTeXFormat{LaTeX2e}[2011/06/27] |
| 19 |
%<package>\ProvidesPackage{tikz-imagelabels} |
| 20 |
%<package> [2019/06/27 v0.2 put labels on images using TikZ] |
| 21 |
% |
| 22 |
%<*driver> |
| 23 |
\documentclass[a4paper]{ltxdoc} |
| 24 |
\RecordChanges |
| 25 |
|
| 26 |
\usepackage[T1]{fontenc} |
| 27 |
\usepackage{lmodern} |
| 28 |
\usepackage{hyperref} |
| 29 |
\usepackage{url} |
| 30 |
\usepackage{amsmath} |
| 31 |
\usepackage{amssymb} |
| 32 |
\usepackage{tikz-imagelabels} |
| 33 |
\usepackage{float} |
| 34 |
\usepackage{parskip} |
| 35 |
|
| 36 |
% default position for floats: H |
| 37 |
\makeatletter |
| 38 |
\renewcommand{\fps@figure}{H} |
| 39 |
\renewcommand{\fps@table}{H} |
| 40 |
\makeatother |
| 41 |
|
| 42 |
\setlength{\parindent}{0pt} |
| 43 |
|
| 44 |
\def\pkg{\texttt{tikz-imagelabels}} |
| 45 |
\def\tkz{Ti\emph{k}Z} |
| 46 |
|
| 47 |
\begin{document} |
| 48 |
\DocInput{tikz-imagelabels.dtx} |
| 49 |
\end{document} |
| 50 |
%</driver> |
| 51 |
% \fi |
| 52 |
% |
| 53 |
% \CheckSum{0} |
| 54 |
% |
| 55 |
% \CharacterTable |
| 56 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 57 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 58 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 59 |
% Exclamation \! Double quote \" Hash (number) \# |
| 60 |
% Dollar \$ Percent \% Ampersand \& |
| 61 |
% Acute accent \' Left paren \( Right paren \) |
| 62 |
% Asterisk \* Plus \+ Comma \, |
| 63 |
% Minus \- Point \. Solidus \/ |
| 64 |
% Colon \: Semicolon \; Less than \< |
| 65 |
% Equals \= Greater than \> Question mark \? |
| 66 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 67 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 68 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 69 |
% Right brace \} Tilde \~} |
| 70 |
% |
| 71 |
% \changes{v0.1}{2019/01/04}{Submission to CTAN} |
| 72 |
% |
| 73 |
% \GetFileInfo{tikz-imagelabels.sty} |
| 74 |
% |
| 75 |
% \title{The \texttt{tikz-imagelabels} package\thanks{This document corresponds |
| 76 |
% to \texttt{tikz-imagelabels}~\fileversion, dated~\filedate.}} |
| 77 |
% \author{Tobias Plüss} |
| 78 |
% \date{\filedate} |
| 79 |
% \thispagestyle{empty} |
| 80 |
% \maketitle |
| 81 |
% |
| 82 |
% \begin{abstract} |
| 83 |
% This package allows to put annotations (arrows, labels) on top of |
| 84 |
% images using Ti\emph{k}Z. |
| 85 |
% \end{abstract} |
| 86 |
% |
| 87 |
% \tableofcontents |
| 88 |
% |
| 89 |
% \PrintChanges |
| 90 |
% |
| 91 |
% \StopEventually{} |
| 92 |
% |
| 93 |
% \section{Introduction} |
| 94 |
% |
| 95 |
% For manuals, scientific reports and the like, one often needs to add |
| 96 |
% annotations to an image (mostly a photograph) to label different items. |
| 97 |
% An example of this is shown in \autoref{fig:pleiades}, which shows the names |
| 98 |
% of the different stars in a star constellation. The package \pkg{} allows to |
| 99 |
% produce this kind of illustration. |
| 100 |
% |
| 101 |
% \begin{figure} |
| 102 |
% \centering |
| 103 |
% \begin{annotationimage}{width=6cm}{pleiades.jpg} |
| 104 |
% \draw[annotation left = {Atlas at 0.3}] to (0.11,0.4); |
| 105 |
% \draw[annotation left = {Pleione at 0.55}] to (0.11,0.49); |
| 106 |
% \draw[annotation left = {Alcyone at 0.8}] to (0.39,0.45); |
| 107 |
% \draw[annotation below = {Merope at 0.5}] to (0.58,0.28); |
| 108 |
% \draw[annotation right = {Electra at 0.3}] to (0.84,0.45); |
| 109 |
% \draw[annotation right = {Caleano at 0.75}] to (0.85,0.64); |
| 110 |
% \draw[annotation above = {Maia at 0.4}] to (0.67,0.72); |
| 111 |
% \draw[annotation above = {Taygeta at 0.9}] to (0.78,0.82); |
| 112 |
% \draw[image label = {M45 at south east}]; |
| 113 |
% \end{annotationimage} |
| 114 |
% \caption{The Pleiades, also known as M45. Image source: \url{http://hubblesite.org/newscenter/archive/releases/2004/20/image/a/}} |
| 115 |
% \label{fig:pleiades} |
| 116 |
% \end{figure} |
| 117 |
% |
| 118 |
% But why does this task deserve its own \LaTeX{} package? there are several |
| 119 |
% reasons: |
| 120 |
% \begin{itemize} |
| 121 |
% \item One does not need to edit the image in an external graphics |
| 122 |
% program. They can be input directly into your \LaTeX{} document. |
| 123 |
% |
| 124 |
% \item Since the labels and annotations are processed by \LaTeX{}, all the |
| 125 |
% font settings and the like remain consistent through the whole the document. |
| 126 |
% However, of course the \pkg{} package allows to configure the style. |
| 127 |
% |
| 128 |
% \item The annotations stay rock-solid if the image needs to be rescaled |
| 129 |
% later. |
| 130 |
% |
| 131 |
% \item Since the arrows are processed by \tkz{}, they are vector |
| 132 |
% graphics and thus, issues with scaling or unsharp/blurry labels, which would |
| 133 |
% result if one labels the image in a graphics software, are avoided. |
| 134 |
% \end{itemize} |
| 135 |
% |
| 136 |
% \clearpage |
| 137 |
% \autoref{fig:pleiades} was created with the following code: |
| 138 |
% \begin{verbatim} |
| 139 |
% \begin{annotationimage}{width=6cm}{pleiades.jpg} |
| 140 |
% \draw[annotation left = {Atlas at 0.3}] to (0.11,0.4); |
| 141 |
% \draw[annotation left = {Pleione at 0.55}] to (0.11,0.49); |
| 142 |
% \draw[annotation left = {Alcyone at 0.8}] to (0.39,0.45); |
| 143 |
% \draw[annotation below = {Merope at 0.5}] to (0.58,0.28); |
| 144 |
% \draw[annotation right = {Electra at 0.3}] to (0.84,0.45); |
| 145 |
% \draw[annotation right = {Caleano at 0.75}] to (0.85,0.64); |
| 146 |
% \draw[annotation above = {Maia at 0.4}] to (0.67,0.72); |
| 147 |
% \draw[annotation above = {Taygeta at 0.9}] to (0.78,0.82); |
| 148 |
% \draw[image label = {M45 at south east}]; |
| 149 |
% \end{annotationimage} |
| 150 |
% \end{verbatim} |
| 151 |
% |
| 152 |
% \section{Usage} |
| 153 |
% |
| 154 |
% \subsection{Inclusion of the image} |
| 155 |
% |
| 156 |
% \DescribeEnv{annotationimage} |
| 157 |
% To include an image, the |annotationimage| environment is used. It |
| 158 |
% has the following syntax: |
| 159 |
% |
| 160 |
% |annotationimage|\oarg{grid}\marg{options}\marg{file name} |
| 161 |
% |
| 162 |
% The \meta{grid} is an optional parameter. If this parameter is present, i.e. |
| 163 |
% if it has the value |[grid]|, then a coordinate grid is visible. The |
| 164 |
% coordinate grid is used to find the coordinates of the points to be labelled. |
| 165 |
% If the parameter \meta{grid} is omitted, no coordinate grid is drawn. The code |
| 166 |
% |
| 167 |
% \begin{verbatim} |
| 168 |
% \begin{annotationimage}[grid]{width=6cm}{pleiades.jpg} |
| 169 |
% \end{annotationimage} |
| 170 |
% \end{verbatim} |
| 171 |
% |
| 172 |
% produces the image shown in \autoref{fig:grid-example}. |
| 173 |
% |
| 174 |
% \begin{figure} |
| 175 |
% \centering |
| 176 |
% \begin{annotationimage}[grid]{width=6cm}{pleiades.jpg} |
| 177 |
% \end{annotationimage} |
| 178 |
% \caption{Example of an image with coordinate grid} |
| 179 |
% \label{fig:grid-example} |
| 180 |
% \end{figure} |
| 181 |
% |
| 182 |
% \meta{options} is any set of options understood by the |
| 183 |
% |\includegraphics| command, e.g. |width=|, |height=| and so on. It may also be |
| 184 |
% left empty, but in this case, the curly braces need to be there, though. |
| 185 |
% |
| 186 |
% The \meta{file name} is, obviously, the file name of the image. Like for the |
| 187 |
% \meta{options}, any image format supported by |\includegraphics| may be used. |
| 188 |
% |
| 189 |
% \subsection{Adding a label} |
| 190 |
% |
| 191 |
% A label (like the ``M45'' in \autoref{fig:pleiades}) can be added to the image |
| 192 |
% using following |\draw| macro: |
| 193 |
% |
| 194 |
% |\draw[image label = {|\meta{text}| at |\meta{placement}|}];| |
| 195 |
% |
| 196 |
% The \meta{text} parameter is obvious. It contains the text to be put into the |
| 197 |
% label. |
| 198 |
% |
| 199 |
% The \meta{placement} dictates the placement of the label. It may be one of |
| 200 |
% |north west|, |north|, |north east|, |east|, |south east|, |south|, |
| 201 |
% |south west| or |west|. Also |center| is possible, even though it possibly |
| 202 |
% doesn't make a lot of sense. \autoref{fig:label_example} shows an example |
| 203 |
% with several labels. |
| 204 |
% |
| 205 |
% \begin{figure} |
| 206 |
% \centering |
| 207 |
% \begin{annotationimage}{width=6cm}{example-image} |
| 208 |
% \draw[image label = {north at north}]; |
| 209 |
% \draw[image label = {north east at north east}]; |
| 210 |
% \draw[image label = {east at east}]; |
| 211 |
% \draw[image label = {south east at south east}]; |
| 212 |
% \draw[image label = {south at south}]; |
| 213 |
% \draw[image label = {south west at south west}]; |
| 214 |
% \draw[image label = {west at west}]; |
| 215 |
% \draw[image label = {north west at north west}]; |
| 216 |
% \draw[image label = {center at center}]; |
| 217 |
% \end{annotationimage} |
| 218 |
% \caption{Example for the placement labels} |
| 219 |
% \label{fig:label_example} |
| 220 |
% \end{figure} |
| 221 |
% |
| 222 |
% The label in \autoref{fig:pleiades} was drawn using the following code: |
| 223 |
% |
| 224 |
% |\draw[image label = {M45 at south east}];| |
| 225 |
% |
| 226 |
% \changes{v0.2}{2019/06/27}{add coordinate labels} |
| 227 |
% Another kind of label is the so-called ``coordinate label''. In contrast to |
| 228 |
% the image label, it may be positioned at arbitrary coordinates. The syntax is |
| 229 |
% similar to the |image label|: |
| 230 |
% |
| 231 |
% |\draw[coordinate label = {|\meta{text}| at (|\meta{coordinate}|)}];| |
| 232 |
% |
| 233 |
% An example of some coordinate labels is shown in \autoref{fig:coord-labels}. |
| 234 |
% |
| 235 |
% \begin{figure} |
| 236 |
% \centering |
| 237 |
% \begin{annotationimage}{width=6cm}{pleiades.jpg} |
| 238 |
% \draw[coordinate label = {1 at (0.1,0.3)}]; |
| 239 |
% \draw[coordinate label = {2 at (0.4,0.6)}]; |
| 240 |
% \draw[coordinate label = {3 at (0.65,0.25)}]; |
| 241 |
% \draw[coordinate label = {4 at (0.9,0.4)}]; |
| 242 |
% \draw[coordinate label = {5 at (0.62,0.62)}]; |
| 243 |
% \draw[coordinate label = {6 at (0.83,0.8)}]; |
| 244 |
% \draw[image label = {M45 at south east}]; |
| 245 |
% \end{annotationimage} |
| 246 |
% \caption{Example of using coordinate labels} |
| 247 |
% \label{fig:coord-labels} |
| 248 |
% \end{figure} |
| 249 |
% |
| 250 |
% \autoref{fig:coord-labels} was created using the following code: |
| 251 |
% \begin{verbatim} |
| 252 |
% \draw[coordinate label = {1 at (0.1,0.3)}]; |
| 253 |
% \draw[coordinate label = {2 at (0.4,0.6)}]; |
| 254 |
% \draw[coordinate label = {3 at (0.65,0.25)}]; |
| 255 |
% \draw[coordinate label = {4 at (0.9,0.4)}]; |
| 256 |
% \draw[coordinate label = {5 at (0.62,0.62)}]; |
| 257 |
% \draw[coordinate label = {6 at (0.83,0.8)}]; |
| 258 |
% \draw[image label = {M45 at south east}]; |
| 259 |
% \end{verbatim} |
| 260 |
% |
| 261 |
% \subsection{Adding annotations} |
| 262 |
% |
| 263 |
% An annotation is added with the aid of the \tkz{} macro |\draw|. The syntax is |
| 264 |
% as follows: |
| 265 |
% |
| 266 |
% |\draw[annotation |\meta{placement}| = {|\meta{text}| at |\meta{position}|}] to (|\meta{x}|, |\meta{y}|);| |
| 267 |
% |
| 268 |
% The \meta{placement} is one of: |above|, |right|, |below| or |left|. It tells |
| 269 |
% on which side of the image the annotation will appear. \meta{above} and |
| 270 |
% \meta{below} basically determine the $y$ coordinate of the text, while |
| 271 |
% \meta{left} and \meta{right} determine the $x$ coordinate of the text. The |
| 272 |
% remaining coordinate is determined using the \meta{position}. |
| 273 |
% |
| 274 |
% The \meta{text} is the actual text of the annotation. |
| 275 |
% |
| 276 |
% The \meta{x} and \meta{y} parameters are the actual coordinates where the |
| 277 |
% arrow should point to. Note that \pkg{} will automatically insert a small |
| 278 |
% distance between the arrow's tip and the coordinate given, such that the |
| 279 |
% arrow is close to the coordinate but does not cover it. |
| 280 |
% |
| 281 |
% For example, the code |
| 282 |
% |
| 283 |
% |\draw[annotation left = {Atlas at 0.3}] to (0.11,0.4);| |
| 284 |
% |
| 285 |
% draws the text ``Atlas'' on the left-hand side of the image, at $y=0.3$. The |
| 286 |
% arrow will point towards coordinate $(0.11, 0.4)$ but ends shortly before this |
| 287 |
% coordinate such that the interesting feature to be labelled is not covered by |
| 288 |
% the arrow's tip. |
| 289 |
% |
| 290 |
% \section{Configuring styles} |
| 291 |
% |
| 292 |
% \DescribeMacro{\imagelabelset} |
| 293 |
% Various options, like font size and so on, can be configured with the |
| 294 |
% |\imagelabelset| macro. It uses the key-value syntax from \tkz{}, e.g.: |
| 295 |
% |
| 296 |
% |\imagelabelset{|\meta{key}| = |\meta{value}|, ...}| |
| 297 |
% |
| 298 |
% Multiple \meta{key} and \meta{value} pairs may be combined. The following |
| 299 |
% sections list all possible configurations. |
| 300 |
% |
| 301 |
% |\imagelabelset| can be put anywhere, but it makes sense to put it into the |
| 302 |
% preamble of a document to ensure all images have the same look. |
| 303 |
% |
| 304 |
% There is also a default style. If no |\imagelabelset| command is present, the |
| 305 |
% default values for all options are taken. The default style used is as |
| 306 |
% follows: |
| 307 |
% |
| 308 |
% \begin{verbatim} |
| 309 |
% \imagelabelset{ |
| 310 |
% coarse grid color = red, |
| 311 |
% fine grid color = gray, |
| 312 |
% image label font = \sffamily\bfseries\small, |
| 313 |
% image label distance = 2mm, |
| 314 |
% image label back = black, |
| 315 |
% image label text = white, |
| 316 |
% coordinate label font = \sffamily\bfseries\scriptsize, |
| 317 |
% coordinate label distance = 2mm, |
| 318 |
% coordinate label back = black, |
| 319 |
% coordinate label text = white, |
| 320 |
% annotation font = \normalfont\small, |
| 321 |
% arrow distance = 1.5mm, |
| 322 |
% border thickness = 0.6pt, |
| 323 |
% arrow thickness = 0.4pt, |
| 324 |
% tip size = 1.2mm, |
| 325 |
% outer dist = 0.5cm, |
| 326 |
% } |
| 327 |
% \end{verbatim} |
| 328 |
% |
| 329 |
% The individual keys are described in the following sections. |
| 330 |
% |
| 331 |
% \subsection{Grid color} |
| 332 |
% |
| 333 |
% In most cases, it will not be necessary to adjust the grid colors. However, |
| 334 |
% depending on the image, it may be desirable to do so. This is exactly what the |
| 335 |
% \meta{coarse grid color} and \meta{fine grid color} are used for. Any color |
| 336 |
% specification compatible to \tkz{} may be used. The defaults are red for the |
| 337 |
% coarse grid and gray for the fine grid. |
| 338 |
% |
| 339 |
% \subsection{Font and color for the labels} |
| 340 |
% |
| 341 |
% The font for the image labels may be configured with \meta{image label font}. |
| 342 |
% By default, the image labels are typeset with bold, small, sans-serif font. |
| 343 |
% |
| 344 |
% The background color of the image labels may be set using the |
| 345 |
% \meta{image label back} kay, whereas the text color is specified with the |
| 346 |
% \meta{image label text} key. Defaults for the background color and for the |
| 347 |
% text color are black and white, respectively. |
| 348 |
% |
| 349 |
% \subsection{Distance of image labels to the image border} |
| 350 |
% |
| 351 |
% The \meta{image label distance} key configures the distance, $d$, from the |
| 352 |
% image's border to the border of the image label, as shown in |
| 353 |
% \autoref{fig:imagelabeldistance_example}. By default, it is set to 2\,mm. |
| 354 |
% |
| 355 |
% \begin{figure} |
| 356 |
% \centering |
| 357 |
% \imagelabelset{ |
| 358 |
% image label distance = 1cm} |
| 359 |
% \begin{annotationimage}{width=5cm}{example-image} |
| 360 |
% \draw[image label = {Label at south east}]; |
| 361 |
% \draw[>=latex, red, <->] (1,0.3) -- ++(-1cm,0) node[above, midway] {$d$}; |
| 362 |
% \draw[>=latex, red, <->] (0.7,0) -- ++(0,1cm) node[midway, right] {$d$}; |
| 363 |
% \end{annotationimage} |
| 364 |
% \caption{Illustration of the \meta{image label distance}} |
| 365 |
% \label{fig:imagelabeldistance_example} |
| 366 |
% \end{figure} |
| 367 |
% |
| 368 |
% \subsection{Font for annotations} |
| 369 |
% |
| 370 |
% The font used for annotations is set by \meta{annotation font}. By default, |
| 371 |
% the |\normalfont| is used with small size. |
| 372 |
% |
| 373 |
% \subsection{Distance of arrow tips} |
| 374 |
% |
| 375 |
% As mentioned earlier, the arrows are shortened such that their tips don't |
| 376 |
% cover the desired point. \autoref{fig:arrowdistance_example} illustrates this. |
| 377 |
% All the arrows point to the same coordinate, $(0.5, 0.5)$, but they end at |
| 378 |
% the distance $x$ away from the point. This distance may be configured using |
| 379 |
% the \meta{arrow distance}. By default, this distance is set to 1.5\,mm. This |
| 380 |
% ensures that the arrow tips are close enough to the interesting features, but |
| 381 |
% not so close that they cover important parts of the image. |
| 382 |
% |
| 383 |
% \begin{figure} |
| 384 |
% \centering |
| 385 |
% \imagelabelset{arrow distance = 1cm} |
| 386 |
% \begin{annotationimage}{width=5cm}{example-image} |
| 387 |
% \draw[annotation right = {text at 0.5}] to (0.5,0.5); |
| 388 |
% \draw[annotation left = {text at 0.1}] to (0.5,0.5); |
| 389 |
% \draw[annotation left = {text at 0.7}] to (0.5,0.5); |
| 390 |
% \draw[annotation below = {text at 0.4}] to (0.5,0.5); |
| 391 |
% \draw[annotation above = {text at 0.8}] to (0.5,0.5); |
| 392 |
% \draw[red] (0.5,0.5) circle[radius = 1cm]; |
| 393 |
% \draw[>=latex, red, <->] (0.5,0.5) -- ++(60:1cm) node[midway, left] {$x$}; |
| 394 |
% \end{annotationimage} |
| 395 |
% \caption{Illustration of the \meta{arrow distance}} |
| 396 |
% \label{fig:arrowdistance_example} |
| 397 |
% \end{figure} |
| 398 |
% |
| 399 |
% \subsection{Thickness and size of the arrows} |
| 400 |
% |
| 401 |
% The arrows themselves consist of two parts: the inner part, which is the |
| 402 |
% actual arrow, and the border, which is, by default, a white border around the |
| 403 |
% arrow. The border is required to ensure that each arrow is visible, no matter |
| 404 |
% on what background it is drawn. The thickness of the black line can be |
| 405 |
% configured using the \meta{arrow thickness}, whose default value is 0.4\,pt. |
| 406 |
% The thickness of the border around the arrow is configured with the |
| 407 |
% \meta{border thickness}, having a default value of 0.6\,pt. |
| 408 |
% |
| 409 |
% The size of the round dot at the end of the arrows is configured using the |
| 410 |
% \meta{tip size}. \autoref{fig:arrowthickness_tipsize_example} illustrates |
| 411 |
% both, the \meta{arrow thickness}, and the \meta{tip size}, as parameters |
| 412 |
% $a$ and $b$, respectively. |
| 413 |
% |
| 414 |
% \begin{figure} |
| 415 |
% \centering |
| 416 |
% \imagelabelset{arrow thickness = 1cm, tip size = 2cm, arrow distance=0} |
| 417 |
% \let\tikzset\imagelabelset |
| 418 |
% \begin{tikzpicture} |
| 419 |
% \draw[annotation arrow] (0,0) -- (4cm,0); |
| 420 |
% \draw[>=latex, red, <->] (0.5,-0.5) -- ++(0,1cm) node[right, midway] {$a$}; |
| 421 |
% \draw[>=latex, red, <->] (3cm,-1cm) -- ++(0,2cm) node[right, midway] {$b$}; |
| 422 |
% \end{tikzpicture} |
| 423 |
% \caption{Illustration of the \meta{arrow thickness}, $a$, and |
| 424 |
% the \meta{tip size}, $b$} |
| 425 |
% \label{fig:arrowthickness_tipsize_example} |
| 426 |
% \end{figure} |
| 427 |
% |
| 428 |
% \subsection{Distance of annotation texts from the image} |
| 429 |
% |
| 430 |
% The parameter \meta{outer dist} configures how far away from the image the |
| 431 |
% annotation texts will be positioned. By default, this value is 0.5\,cm. |
| 432 |
% |
| 433 |
% \section{Implementation} |
| 434 |
% The only packages required are |tikz| and |xifthen|. If not already loaded, |
| 435 |
% they will be loaded automatically. |
| 436 |
% \begin{macrocode} |
| 437 |
\RequirePackage{tikz} |
| 438 |
\RequirePackage{xifthen} |
| 439 |
% \end{macrocode} |
| 440 |
% Some \tkz{} libraries are also reuiqred for proper operation. |
| 441 |
% \begin{macrocode} |
| 442 |
\usetikzlibrary{ |
| 443 |
arrows.meta, |
| 444 |
calc, |
| 445 |
positioning, |
| 446 |
decorations, |
| 447 |
decorations.markings, |
| 448 |
math, |
| 449 |
} |
| 450 |
% \end{macrocode} |
| 451 |
% \subsection{Configuration} |
| 452 |
% For the |\imagelabelset| command, a |pgfkeys| family is defined. All |
| 453 |
% configurations (e.g. \meta{tip size} and so on) and styles are stored in the |
| 454 |
% PGF key |/imagelabels|. This ensures that these configurations don't overwrite |
| 455 |
% any other parameters the user may have set elsewhere. |
| 456 |
% \begin{macrocode} |
| 457 |
\pgfkeys{ |
| 458 |
/imagelabels/.is family, |
| 459 |
/imagelabels/.search also={/tikz}, |
| 460 |
} |
| 461 |
|
| 462 |
\def\imagelabelset{\pgfqkeys{/imagelabels}} |
| 463 |
% \end{macrocode} |
| 464 |
% Then, a set of macros is created which stores the values for the individual |
| 465 |
% configuration options. |
| 466 |
% \begin{macrocode} |
| 467 |
\imagelabelset{ |
| 468 |
coarse grid color/.store in = \maingridcolor, |
| 469 |
fine grid color/.store in = \finegridcolor, |
| 470 |
} |
| 471 |
|
| 472 |
\imagelabelset{ |
| 473 |
image label font/.store in = \imagelabelfont, |
| 474 |
image label distance/.store in = \imagelabelsep, |
| 475 |
image label back/.store in = \imagelabelback, |
| 476 |
image label text/.store in = \imagelabeltext, |
| 477 |
} |
| 478 |
|
| 479 |
\imagelabelset{ |
| 480 |
coordinate label font/.store in = \coordinatelabelfont, |
| 481 |
coordinate label distance/.store in = \coordinatelabelsep, |
| 482 |
coordinate label back/.store in = \coordinatelabelback, |
| 483 |
coordinate label text/.store in = \coordinatelabeltext, |
| 484 |
} |
| 485 |
|
| 486 |
\imagelabelset{ |
| 487 |
annotation font/.store in = \annotationfont, |
| 488 |
arrow distance/.store in = \arrowdistance, |
| 489 |
arrow thickness/.store in = \arrowthickness, |
| 490 |
tip size/.store in = \tipsize, |
| 491 |
border thickness/.store in = \borderthickness, |
| 492 |
outer dist/.store in = \labeloutersep, |
| 493 |
} |
| 494 |
% \end{macrocode} |
| 495 |
% |
| 496 |
% \subsection{Default configuration} |
| 497 |
% The default configuration is set. This will ensure that each of the previously |
| 498 |
% defined macros has a valid initial value, which may be overwritten by the |
| 499 |
% user. |
| 500 |
% \begin{macrocode} |
| 501 |
\imagelabelset{ |
| 502 |
coarse grid color = red, |
| 503 |
fine grid color = gray, |
| 504 |
image label font = \sffamily\bfseries\small, |
| 505 |
image label distance = 2mm, |
| 506 |
image label back = black, |
| 507 |
image label text = white, |
| 508 |
coordinate label font = \sffamily\bfseries\scriptsize, |
| 509 |
coordinate label distance = 2mm, |
| 510 |
coordinate label back = black, |
| 511 |
coordinate label text = white, |
| 512 |
annotation font = \normalfont\small, |
| 513 |
arrow distance = 1.5mm, |
| 514 |
border thickness = 0.6pt, |
| 515 |
arrow thickness = 0.4pt, |
| 516 |
tip size = 1.2mm, |
| 517 |
outer dist = 0.5cm, |
| 518 |
} |
| 519 |
% \end{macrocode} |
| 520 |
% |
| 521 |
% \subsection{Environment declaration} |
| 522 |
% Next, the |annotationimage| environment is declared. It takes 3 arguments, |
| 523 |
% the first of which is optional. If it is omitted, its default value is empty. |
| 524 |
% \begin{macrocode} |
| 525 |
\newenvironment{annotationimage}[3][]{ |
| 526 |
% \end{macrocode} |
| 527 |
% Each time a new |annotationimage| environment is opened, this code will ensure |
| 528 |
% that all the definitions stored under the PGF key |/imagelabels| are loaded. |
| 529 |
% Then, a new |tikzpicture| is created. |
| 530 |
% \begin{macrocode} |
| 531 |
\let\tikzset\imagelabelset |
| 532 |
\begin{tikzpicture} |
| 533 |
% \end{macrocode} |
| 534 |
% The 2nd and 3rd arguments to the |annotationimage| are the size/scaling |
| 535 |
% options for the image, as well as the actual image file. Thus, a new \tkz{} |
| 536 |
% node called |image| is created; the node's content is the image. |
| 537 |
% \begin{macrocode} |
| 538 |
\node[anchor=south west, inner sep=0] |
| 539 |
(image) at (0,0) {\includegraphics[#2]{#3}}; |
| 540 |
% \end{macrocode} |
| 541 |
% Using a scope ensures that the top-right corner always has coordinate $(1,1)$. |
| 542 |
% \begin{macrocode} |
| 543 |
\begin{scope}[x={(image.south east)},y={(image.north west)}] |
| 544 |
% \end{macrocode} |
| 545 |
% Next, the first (optional) argument's value is checked. If the user said |
| 546 |
% |[grid]| to the first argument, the following code is executed. |
| 547 |
% \begin{macrocode} |
| 548 |
\ifthenelse{\equal{#1}{grid}}{% |
| 549 |
% \end{macrocode} |
| 550 |
% This actually draws the coordinate grid. |
| 551 |
% \begin{macrocode} |
| 552 |
\draw[very thin, draw=\finegridcolor, step=0.02] |
| 553 |
(0,0) grid (1,1); |
| 554 |
\draw[thin, draw=\maingridcolor, xstep=0.1, ystep=0.1] |
| 555 |
(0,0) grid (1,1); |
| 556 |
% \end{macrocode} |
| 557 |
% then, the labels are put to the coordinate axes. |
| 558 |
% \begin{macrocode} |
| 559 |
\foreach \x in {0,1,...,9} { |
| 560 |
\node [anchor=north] at (\x/10,0) {\tiny 0.\x}; |
| 561 |
} |
| 562 |
\node [anchor=north] at (1,0) {\tiny 1}; |
| 563 |
|
| 564 |
\foreach \y in {0,1,...,9} { |
| 565 |
\node [anchor=east] at (0,\y/10) {\tiny 0.\y}; |
| 566 |
} |
| 567 |
\node [anchor=east] at (0,1) {\tiny 1}; |
| 568 |
}{} |
| 569 |
} |
| 570 |
{ |
| 571 |
% \end{macrocode} |
| 572 |
% Each time the |annotationimage| environment is closed, the previously opened |
| 573 |
% |scope| and |tikzpicture| environments need to be closed as well. |
| 574 |
% \begin{macrocode} |
| 575 |
\end{scope} |
| 576 |
\end{tikzpicture}} |
| 577 |
% \end{macrocode} |
| 578 |
% |
| 579 |
% \subsection{Style definitions for the annotations} |
| 580 |
% What follows is the definition of the styling for the annotations. |
| 581 |
% \begin{macrocode} |
| 582 |
\imagelabelset{ |
| 583 |
% \end{macrocode} |
| 584 |
% This is the style for the annotation arrow itself. |
| 585 |
% \begin{macrocode} |
| 586 |
annotation arrow/.style = |
| 587 |
{ |
| 588 |
% \end{macrocode} |
| 589 |
% The |preaction| first draws a thick white arrow. This arrow will become the |
| 590 |
% border. |
| 591 |
% \begin{macrocode} |
| 592 |
preaction = |
| 593 |
{ |
| 594 |
draw, |
| 595 |
-{Circle[fill=white, length=\tipsize+2*\borderthickness, |
| 596 |
width=\tipsize+2*\borderthickness]}, |
| 597 |
line width = 2*\borderthickness + \arrowthickness, |
| 598 |
white, |
| 599 |
shorten >= \arrowdistance, |
| 600 |
}, |
| 601 |
% \end{macrocode} |
| 602 |
% After the |preaction| has been performed, this will actually draw the |
| 603 |
% ``normal'' arrow. |
| 604 |
% \begin{macrocode} |
| 605 |
draw, |
| 606 |
-{Circle[fill=black, length=\tipsize, width=\tipsize]}, |
| 607 |
black, |
| 608 |
line width = \arrowthickness, |
| 609 |
shorten >= \borderthickness + \arrowdistance, |
| 610 |
}, |
| 611 |
% \end{macrocode} |
| 612 |
% All the annotation texts have a common style. This ensures they have the same |
| 613 |
% font etc. Setting the |inner sep| to 0.5\,ex ensures that the distance between |
| 614 |
% the text and the arrow is somewhat aesthetic. It is an empirically determined |
| 615 |
% value. |
| 616 |
% \begin{macrocode} |
| 617 |
annotation node/.style = |
| 618 |
{ |
| 619 |
font=\annotationfont, |
| 620 |
inner sep = 0.5ex, |
| 621 |
}, |
| 622 |
% \end{macrocode} |
| 623 |
% Next comes the styles for the different annotation placements. For an |
| 624 |
% annotation being below the image, this style applies. |
| 625 |
% \begin{macrocode} |
| 626 |
annotation below/.style args = {#1 at #2}{ |
| 627 |
% \end{macrocode} |
| 628 |
% Using the annotation arrow style tells \tkz{} to draw an arrow as specified |
| 629 |
% above, using the geometry defined with |\imagelabelset|. |
| 630 |
% \begin{macrocode} |
| 631 |
annotation arrow, |
| 632 |
% \end{macrocode} |
| 633 |
% After the arrow has been drawn, a further path is inserted, which is the |
| 634 |
% actual annotation text. For the annotations being above and below the image |
| 635 |
% special care must be taken: a |\strut| is appended to the label text to ensure |
| 636 |
% that texts being on the same side of the image are on the same line. Without |
| 637 |
% the strut, the texts may be differently aligned, depending on their letters -- |
| 638 |
% e.g. letters ``p'' and ``g'' go slightly further down in the $y$ direction |
| 639 |
% than ``a'' or ``b''. |
| 640 |
% \begin{macrocode} |
| 641 |
insert path = { |
| 642 |
(#2,0) ++ (0,-\labeloutersep) |
| 643 |
node[anchor = north, annotation node] {#1\strut} |
| 644 |
} |
| 645 |
}, |
| 646 |
% \end{macrocode} |
| 647 |
% The remaining annotation styles are defined similarly. |
| 648 |
% \begin{macrocode} |
| 649 |
annotation above/.style args = {#1 at #2}{ |
| 650 |
annotation arrow, |
| 651 |
insert path = { |
| 652 |
(#2,1.0) ++ (0,\labeloutersep) |
| 653 |
node[anchor = south, annotation node] {#1\strut} |
| 654 |
} |
| 655 |
}, |
| 656 |
annotation left/.style args = {#1 at #2}{ |
| 657 |
annotation arrow, |
| 658 |
insert path = { |
| 659 |
(0,#2) ++ (-\labeloutersep,0) |
| 660 |
node[anchor = east, annotation node] {#1} |
| 661 |
} |
| 662 |
}, |
| 663 |
annotation right/.style args = {#1 at #2}{ |
| 664 |
annotation arrow, |
| 665 |
insert path = { |
| 666 |
(1.0,#2) ++ (\labeloutersep,0) |
| 667 |
node[anchor = west, annotation node] {#1} |
| 668 |
} |
| 669 |
}, |
| 670 |
} |
| 671 |
% \end{macrocode} |
| 672 |
% |
| 673 |
% \subsection{Style definitions for the labels} |
| 674 |
% Next follows the style definition for the image labels. A general style |
| 675 |
% defines the appearance and color. |
| 676 |
% \begin{macrocode} |
| 677 |
\imagelabelset{ |
| 678 |
image label style/.style = { |
| 679 |
rectangle, |
| 680 |
minimum width = 5mm, |
| 681 |
minimum height = 5mm, |
| 682 |
fill = \imagelabelback, |
| 683 |
text = \imagelabeltext, |
| 684 |
font = \imagelabelfont, |
| 685 |
}, |
| 686 |
coordinate label style/.style = { |
| 687 |
rectangle, |
| 688 |
minimum width = 3mm, |
| 689 |
minimum height = 3mm, |
| 690 |
fill = \coordinatelabelback, |
| 691 |
text = \coordinatelabeltext, |
| 692 |
font = \coordinatelabelfont, |
| 693 |
}, |
| 694 |
% \end{macrocode} |
| 695 |
% On the other hand, the |image label| style defines the actual image labels. |
| 696 |
% \begin{macrocode} |
| 697 |
image label/.style args = {#1 at #2}{ |
| 698 |
insert path = { |
| 699 |
(image.#2) node[outer sep = \imagelabelsep, |
| 700 |
anchor=#2, image label style] {#1} |
| 701 |
} |
| 702 |
}, |
| 703 |
coordinate label/.style args = {#1 at (#2)}{ |
| 704 |
insert path = { |
| 705 |
node[outer sep = \coordinatelabelsep, |
| 706 |
anchor=center, coordinate label style] at (#2) {#1} |
| 707 |
} |
| 708 |
}, |
| 709 |
} |
| 710 |
% \end{macrocode} |
| 711 |
% |
| 712 |
% \Finale |
| 713 |
\endinput |