| 1 |
% !TeX root = ../easyfloats.tex |
| 2 |
|
| 3 |
\section{Examples} |
| 4 |
\label{examples} |
| 5 |
|
| 6 |
Let's start with a few examples. |
| 7 |
Environments, commands and keys defined by this package are links (both in the code and in the text). |
| 8 |
Clicking on them will get you to their explanation in \cref{documentation}. |
| 9 |
|
| 10 |
\Cref{motivation} gives a motivation why this package is useful. |
| 11 |
There is a list of related packages in \cref{used-packages,other-packages}. |
| 12 |
Package names link to the rather short description in that list. |
| 13 |
|
| 14 |
The examples have been tested with \input{../test/generated/latex_version}\unskip. |
| 15 |
|
| 16 |
|
| 17 |
\subsection{Table} |
| 18 |
\label{table} |
| 19 |
Use the \env{tableobject} environment for inserting tables. |
| 20 |
Pass caption and label as keyword arguments. |
| 21 |
You can't mess up the order of caption and label and you get a warning if you forget to specify them. |
| 22 |
You don't need two environments (one for the float, one for the table---`tableobject` can do both). |
| 23 |
\pkg{booktabs} (and \pkg{array}) are loaded automatically (if not disabled, see \cref{package-options}). |
| 24 |
|
| 25 |
The last argument, `cl`, is not an argument of the `tableobject` environment but of the standard \LaTeX\ `tabular` environment which is started by the `tableobject` environment because it is specified with `env`. |
| 26 |
It specifies the columns of the table: The `l` stands for one left aligned column and the `c` for one centered column. |
| 27 |
An `r` would stand for a right aligned column and a \xc.p{<width>}. for a column which breaks the cell contents to a specified width. |
| 28 |
The \pkg{siunitx} package defines `S` for a column which aligns numbers and in the `tabularx` environment defined by the \pkg{tabularx} package `X` is available for a `p` column which automatically takes as much space as there is available. |
| 29 |
You can use the `\newcolumntype` command (defined by the \pkg{array} package) to define your own column types, e.g.\ `\newcolumntype{M}{>{$}c<{$}}` to define a column type `M` for centered math content. |
| 30 |
See the \pkg{array} package documentation~\autocite[chapter~1]{array} for more column specification options. |
| 31 |
|
| 32 |
`&` is the column separator and `\\` specifies the end of a row. |
| 33 |
|
| 34 |
The table is formatted with `\toprule`, `\midrule` and `\bottomrule` as explained in the \pkg{booktabs} documentation~\autocite[chapter~2]{booktabs}. |
| 35 |
|
| 36 |
\inputexamplecode{../test/exp-table} |
| 37 |
|
| 38 |
You can reduce typing effort even further by using the `table head` key, see \cref{longtable}. |
| 39 |
|
| 40 |
If you are not familiar with how to reference a label, see \cref{vref}. |
| 41 |
|
| 42 |
|
| 43 |
\subsection{Graphic} |
| 44 |
\label{graphic} |
| 45 |
Use the \cmd{\includegraphicobject} command to insert a graphic. |
| 46 |
It is a wrapper around \pkg{graphicx}' `\includegraphics` command taking the same arguments. |
| 47 |
No need for a surrounding `figure` environment. |
| 48 |
I have extended the allowed optional keyword argument to also accept caption, label and more, see \cref{includegraphicobject-command}. |
| 49 |
`details` are appended to the caption below the figure but not in the list of figures. |
| 50 |
Select with the \pkgoptn{graphicx} or \pkgoptn{graphbox} package options whether you want to use the commonly used \pkg{graphicx} package or it's extension \pkg{graphbox}. |
| 51 |
|
| 52 |
\inputexamplecode{../test/exp-graphic} |
| 53 |
|
| 54 |
The graphic automatically gets the label \formatlabel{fig:graphics/ctan_lion}, based on the file name and the specified prefix. |
| 55 |
You can override the automatically generated label by passing the key `label` to the optional argument. |
| 56 |
If you omit \key{caption} the file name \formatcaption{graphics/ctan_lion} is used. |
| 57 |
See `auto label`, `auto caption`, `auto label strip path`, `auto caption strip path` and `auto label prefix`. |
| 58 |
|
| 59 |
If you are not familiar with how to reference a label, see \cref{vref}. |
| 60 |
|
| 61 |
|
| 62 |
\subsection{Subfigures} |
| 63 |
\label{exp:subfigures} |
| 64 |
The following example shows a figure consisting of two graphics displayed side by side, each having their own caption and label. |
| 65 |
The graphics have a distance of one quad, i.e. 1\,em, and fill the entire width of the line. |
| 66 |
(em is a unit of distance relative to the font. |
| 67 |
If you are unfamiliar with the units supported by \TeX\ you can read up on them in \mycite[pages 57 and~60]{texbook} or \mycite[chapters 8.2.1 and~4.3.1]{texbytopic}. |
| 68 |
|
| 69 |
I am loading the \pkg{calc} package in order to use an expression as `subobject linewidth`. |
| 70 |
(Alternatively you could use the \eTeX\ primitive `\dimexpr`.) |
| 71 |
As I want to put two graphics next to each other, each of them should be half of the available line width minus half of the distance between them wide. |
| 72 |
Additionally I need to subtract a tiny bit more in order to compensate for rounding errors in the division which would cause an uninteded line break with the initial setting `align = \centering`. |
| 73 |
(The rounding errors would not need to be compensated if you set the value of `align` to an empty string). |
| 74 |
|
| 75 |
Pay attention to *not* insert an empty line between the subobjects, otherwise they will be placed below each other instead of side by side. |
| 76 |
If you want them to be placed below each other you can use the `ver` option. |
| 77 |
|
| 78 |
By default subobjects do not show up in the list of figures. |
| 79 |
You can change that with `\captionsetup[sub]{list=true}`. |
| 80 |
`\captionsetup` is explained in the \pkg{caption} package documentation~\autocite{caption}. |
| 81 |
|
| 82 |
\inputexamplecode{../test/exp-subgraphic} |
| 83 |
|
| 84 |
Each of the subfigures gets it's own label, generated based on the given prefix and the file name: \formatlabel{fig:ctan_lion} and \formatlabel{fig:tex_engines}. |
| 85 |
You can override the automatically generated labels with the \key[/subobject]{label} key if needed. |
| 86 |
How to reference the labels is shown in \cref{vref}. |
| 87 |
|
| 88 |
If you want to use the full width for graphics in subobjects but less than the full width for graphics in main objects you can achieve that with |
| 89 |
%If you want a different width for `\includegraphicsubobject` and `\includegraphicobject` you could achieve that with |
| 90 |
\begin{examplecode} |
| 91 |
\objectset[figure]{graphic width = .8\linewidth} |
| 92 |
\AtBeginSubobject{\AtBeginGraphicObject{% |
| 93 |
\objectset{graphic width = \linewidth}% |
| 94 |
}} |
| 95 |
\end{examplecode} |
| 96 |
|
| 97 |
|
| 98 |
\subsection{Other subobjects} |
| 99 |
\label{subobjects-2} |
| 100 |
|
| 101 |
Use the \env{subobject} environment to combine two (or more) subobjects to one big object. |
| 102 |
The `contains subobjects` option causes the `env` option to be applied to the subobjects instead of the containing object. |
| 103 |
I am decreasing the `subobject linewidth` because the tables fill only a small part of the width |
| 104 |
so the distance between them would be too big if each was centered on `.5\linewidth`. |
| 105 |
(If you don't want to set the `subobject linewidth` to an explicit value take a look at the `subcaptionbox` option and the example provided there. |
| 106 |
Setting `subobject sep` to the desired distance and aligning the subojects with `subpage align=\raggedleft` and `subpage align=\raggedright` does not work well because `\raggedleft` and `\raggedright` do not affect the caption. The alignment of the caption could be changed with `\captionsetup{justification=raggedleft,singlelinecheck=false}` but then the caption would not be centered relative to the tabular.) |
| 107 |
|
| 108 |
Pay attention to *not* insert an empty line between the subobjects, otherwise they will be placed below each other instead of side by side. |
| 109 |
If you want them to be placed below each other you can use the `ver` option. |
| 110 |
|
| 111 |
By default subobjects do not show up in the list of tables. |
| 112 |
You can change that with `\captionsetup[sub]{list=true}`. |
| 113 |
`\captionsetup` is explained in the \pkg{caption} package documentation~\autocite{caption}. |
| 114 |
|
| 115 |
\inputexamplecode{../test/exp-subobject} |
| 116 |
|
| 117 |
|
| 118 |
\subsection{Longtable} |
| 119 |
\label{longtable} |
| 120 |
If you are undecided whether to use floating `tabular`s or \env{longtable}s which can break across pages you can use the following approach. |
| 121 |
Changing between them is as easy as changing `env=longtable` to `env=tabular` once. |
| 122 |
The table head and foot are set by the key `table head` and are by default formatted with the \pkg{booktabs} package. |
| 123 |
(If you don't like this you can change the definition of `table head` with `table head style`.) |
| 124 |
The column specification cannot be given as a separate argument (like in the example above) but must be set with the `arg` key |
| 125 |
because otherwise the column specification would be after the table head. |
| 126 |
|
| 127 |
\inputexamplecode{../test/exp-longtable} |
| 128 |
|
| 129 |
|
| 130 |
\subsection{Local definitions in tables} |
| 131 |
\label{local-definitions-in-tables} |
| 132 |
|
| 133 |
If you want to define a command locally for one table you cannot put it's definition in the first cell because each cell is a separate group |
| 134 |
(meaning that the definition will be forgotten at the end of the cell). |
| 135 |
Instead I provide the `exec` key whose value is executed inside of the object but before `env`. |
| 136 |
If you want to tinker around with catcodes keep in mind that arguments are always read entirely before expansion and execution. |
| 137 |
The \eTeX\ primitive `\scantokens` can be useful to define active characters. |
| 138 |
If you are unfamiliar with how \TeX\ processes a file you can read up on it in \mycite[section~1]{texbytopic}. |
| 139 |
|
| 140 |
\inputexamplecode{../test/exp-exec} |
| 141 |
|
| 142 |
|
| 143 |
\subsection{New object style~\slash\ `tikzobject`} |
| 144 |
\label{new-object-style-tikzobject} |
| 145 |
|
| 146 |
You can easily define new object environments. |
| 147 |
For more information see \cref{new-object-styles-and-types}. |
| 148 |
|
| 149 |
\inputexamplecode{../test/exp-tikzobject} |
| 150 |
|
| 151 |
If you are interested in three dimensional drawing see also the \TikZ\ library \tikzlibrary{perspective} \autocite[section~63 Three Point Perspective Drawing Library]{tikz}. |
| 152 |
|
| 153 |
|
| 154 |
\subsection{New float type `diagram`} |
| 155 |
\label{exp:new-object-type} |
| 156 |
|
| 157 |
I am using `\AtEndPreamble` defined by the \pkg{etoolbox} package to defer loading of \pkg{cleveref} after \pkg{hyperref}. |
| 158 |
For more information about \pkg{cleveref} and \pkg{varioref} see \cref{vref}. |
| 159 |
|
| 160 |
I am defining `\listofdiagrams` analogous to `\listoffigures` and `\listoftables` with the help of the `\listof` command defined by the \pkg{float} package (which is loaded automatically by \pkg{easyfloats}). |
| 161 |
|
| 162 |
For more information see \cref{new-object-styles-and-types}. |
| 163 |
|
| 164 |
\inputexamplecode{../test/exp-new-object-style} |
| 165 |
|
| 166 |
|
| 167 |
\subsection{Split object} |
| 168 |
\label{split-object-example} |
| 169 |
|
| 170 |
If a float gets too big you can split it up with the `\splitobject` command so that the object can be broken across a page break. |
| 171 |
I am using `\DeclareCaptionLabelFormat` and `\captionsetup` to add the prefix \enquote{Continued} to the caption of the continuation as shown in the package \pkg{caption} documentation~\autocite[section~3.3 |
| 172 |
Continued floats]{caption}. |
| 173 |
|
| 174 |
\inputexamplecode{../test/exp-splitobject} |
| 175 |
|
| 176 |
|
| 177 |
\subsection{Custom options} |
| 178 |
\label{custom-options} |
| 179 |
This package uses the \pkg{pgfkeys} package to define the options which can be passed to the environments and commands defined by this package. |
| 180 |
Therefore you can use the usual pgfkeys handlers to add custom options. |
| 181 |
The following example defines a new key `center subcaptions` which centers the captions of all subobjects. |
| 182 |
For more information see \cref{options} and the \mycite[Utilities/Key Management]{tikz}. |
| 183 |
|
| 184 |
\inputexamplecode{../test/exp-custom-option} |
| 185 |
|
| 186 |
|
| 187 |
\subsection{Nonfloating objects} |
| 188 |
\label{nonfloating-objects} |
| 189 |
If your professor absolutely won't allow floating objects you can easily disable them globally |
| 190 |
(for all objects based on the \env{object} environment defined by this package which is internally used by \env{tableobject} and \cmd{\includegraphicobject}). |
| 191 |
|
| 192 |
\begin{examplecode} |
| 193 |
\objectset{placement=H} |
| 194 |
\end{examplecode} |
| 195 |
|
| 196 |
|
| 197 |
\subsection{How to reference objects} |
| 198 |
\label{vref} |
| 199 |
When you insert floating objects you probably want to reference them in the text. |
| 200 |
Although this package does not change anything about referencing I have added an example for the sake of completeness. |
| 201 |
|
| 202 |
The standard \LaTeX\ commands are `\ref{<label>}` (to insert the number of a figure/table/whatever) and `\pageref{<label>}` (to insert the page number). |
| 203 |
The \pkg{hyperref} package automatically turns them into links. |
| 204 |
The \pkg{varioref} package defines new commands `\vref{<label>}` and `\Vref{<label>}` which automatically add a reference to the page if the label is on a different page. |
| 205 |
The \pkg{cleveref} package redefines `\vref{<label>}` and `\Vref{<label>}` to automatically insert the type of object in front of the reference so that you don't need to write out \enquote{figure\string~}. |
| 206 |
|
| 207 |
`\Vref{<label>}` is to be used at the beginning of the sentence and `\vref{<label>}` is to be used inside of a sentence. |
| 208 |
The distinction is important for capitalization and whether to use an abbreviation. |
| 209 |
You can disable abbreviations by loading the \pkg{cleveref} package with the `noabbrev` option. |
| 210 |
|
| 211 |
Note that \pkg{cleveref} must be loaded last, even after \pkg{hyperref} which should usually be loaded last. |
| 212 |
|
| 213 |
\inputexamplecode{../test/exp-vref} |
| 214 |
|
| 215 |
Warning: Using \pkg{varioref} can lead to not converging behavior. |
| 216 |
For example: You use `\vref{sec:foo}` in section~1 to reference `\label{sec:foo}` at the beginning of section~2. |
| 217 |
In the first run it prints \enquote{??} as reference because it does not know the referenced object yet. The reference is on page~1 and section~2 begins at the end of page~2. |
| 218 |
In the second run it therefore prints \enquote{section~2 on the following page}. Section~2 moves to the beginning of page~3 because the reference text is now longer. |
| 219 |
In the third run it therefore prints \enquote{section~2 on page~3}. Section~2 moves back to page~2 because the reference text is now shorter. |
| 220 |
In the fourth run it therefore prints \enquote{section~2 on the following page} again. And section~2 moves to the beginning of page~3 again. |
| 221 |
Every time you compile the document the beginning of section~2 will be somewhere else and the reference will never be correct. |
| 222 |
This may cause other references (e.g. `\pageref{LastPage}` (defined by the \pkg{lastpage} package) to jump as well. |
| 223 |
The same can happen when referencing an earlier label. |
| 224 |
|
| 225 |
You don't need to worry about this until the very end because this behavior may get resolved while inserting, deleting or rewriting contents or formatting the document. |
| 226 |
But if this still happens when you have finished everything else you can solve this by inserting a `\clearpage` or replacing the `\vref` with a `\fullref`. |
| 227 |
`\fullref{<label>}` is defined by the \pkg{varioref} package and is by default equivalent to `\cref{<label>} on \cpageref{<label>}` (if \pkg{cleveref} is loaded---if not it's default is equivalent to `\ref{<label>} on page~\pageref{<label>}`). |
| 228 |
Using `\clearpage` may be preferable in order to keep the referencing manner consistent. |
| 229 |
|
| 230 |
See also the \pkg{varioref} documentation, section~7 \sectionname{A few warnings}. |