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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
% \iffalse meta-comment
%
% Copyright (C) 2019-2023 by Jan Hajer
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{hep-float}[2023/07/01 v1.2 Float adjustments]
%<documentation>\ProvidesFile{hep-float-documentation.tex}[2023/07/01 v1.2 hep-float documentation]
%
%<*documentation>
\documentclass{ltxdoc}
\renewcommand\theCodelineNo{\rmfamily\tstyle\footnotesize\arabic{CodelineNo}}
\AtBeginEnvironment{macrocode}{\renewcommand{\ttdefault}{clmt}}
\renewcommand{\MacroFont}{\codestyle}
\AtBeginDocument{\DeleteShortVerb{\|}}
\AtBeginDocument{\MakeShortVerb{\"}}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage{hologo}
\usepackage[parskip,oldstyle,font=10pt]{hep-paper}
\bibliography{bibliography}
%</documentation>
%<*driver>
\expandafter\newif\csname ifshort\endcsname
\shortfalse
\begin{document}
\DocInput{hep-float-implementation.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
% {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
% 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
% Digits \0\1\2\3\4\5\6\7\8\9
% Exclamation \! Double quote \" Hash (number) \#
% Dollar \$ Percent \% Ampersand \&
% Acute accent \' Left paren \( Right paren \)
% Asterisk \* Plus \+ Comma \,
% Minus \- Point \. Solidus \/
% Colon \: Semicolon \; Less than \<
% Equals \= Greater than \> Question mark \?
% Commercial at \@ Left bracket \[ Backslash \\
% Right bracket \] Circumflex \^ Underscore \_
% Grave accent \` Left brace \{ Vertical bar \|
% Right brace \} Tilde \~}
%
% \changes{v1.0}{2021/09/01}{Initial version of the style file.}
% \changes{v1.1}{2023/07/01}{Bug fixes.}
%
% \ifshort
%<*documentation>
% \fi
%
\GetFileInfo{hep-float.sty}
\title{The \software{hep-float} package\thanks{This document corresponds to \software{hep-float}~\fileversion.}}
\subtitle{Convenience package for float placement}
\author{Jan Hajer \email{jan.hajer@tecnico.ulisboa.pt}}
\date{\filedate}
% \ifshort
\begin{document}
% \fi
\newgeometry{vscale=.8, vmarginratio=3:4, includeheadfoot, left=11em, marginparwidth=4.6cm, marginparsep=3mm, right=7em}
\maketitle
\begin{abstract}
The \software{hep-float} package redefines some \hologo{LaTeX} float placement defaults and defines convenience wrappers for floats.
\end{abstract}
The \software{hep-float} package can be loaded with "\usepackage{hep-float}".
\DescribeEnv{figure}
\DescribeEnv{table}
Automatic float placement is adjusted to place a single float at the top of pages and to reduce the number of float pages, using the \hologo{LaTeX} macros.
"\setcounter{bottomnumber}{0}" \hfill no floats at the bottom of a page (default 1) \\
"\setcounter{topnumber}{1}" \hfill a single float at the top of a page (default 2) \\
"\setcounter{dbltopnumber}{1}" \hfill same for full widths floats in two-column mode \\
"\renewcommand{\textfraction}{.1}" \hfill large floats are allowed (default 0.2)\\
"\renewcommand{\topfraction}{.9}" \hfill (default 0.7) \\
"\renewcommand{\dbltopfraction}{.9}" \hfill (default 0.7) \\
"\renewcommand{\floatpagefraction}{.8}" \hfill float pages must be full (default 0.5)
The most useful float placement is usually archived by placing the float \emph{in front} of the paragraph it is referenced in first.
\DescribeMacro{manualplacement}
Additionally, manual float placement can be deactivated using the "manualplacement" package option.
\DescribeMacro{\raggedright}
The float environments have been adjusted to center their content.
The usual behaviour can be reactivated using "\raggedright".
\begin{table}
\begin{panels}{2}
\begin{verbatim}
\begin{panels}{2}
code
\panel
\begin{tabular}...\end{tabular}
\end{panels}
\end{verbatim}
\caption{Code for this panel environment.}
\label{tab:panels}
\panel
\begin{tabular}{cccc}
\toprule
\multicolumn{2}{c}{one}& \multicolumn{2}{c}{two} \\ \cmidrule(r){1-2} \cmidrule(l){3-4}
\multirow{2}{*}{a} & b & c & d \\
& b & c & d \\
\bottomrule
\end{tabular}
\caption{The \protecting{"booktabs"} and \protecting{"multirow"} features.}
\label{tab:booktabs}
\end{panels}
\caption{Example use of the \protecting{"panels"} environment in Panel \subref{tab:panels} and the features from the \software{booktabs} and \software{multirow} packages in Panel \subref{tab:booktabs}.
} \label{tab:table}
\end{table}
\DescribeEnv{panels}
\DescribeMacro{\panel}
The "panels" environment makes use of the \software{subcaption} package \cite{subcaption}.
It provides sub-floats and takes as mandatory argument either the number of sub-floats (default~2) or the width of the first sub-float as fraction of the "\linewidth".
Within the "\begin{panels}"\oarg{vertical alignment}\marg{width} environment the "\panel" macro initiates a new sub-float.
In the case that the width of the first sub-float has been given as an optional argument to the "panels" environment the "\panel"\marg{width} macro takes the width of the next sub-float as mandatory argument.
The example code is presented in \cref{tab:panels}.
\DescribeMacro{\panelhspace}
\DescribeMacro{\panelvspace}
The spacing between the panels can be adjusted by adjusting the "\panelvspace" in terms of a "\linewidth" fraction "\renewcommand{\panelhspace}"{fraction} and the "\panelvspace" in terms of a length "\renewcommand{\panelvspace}"\marg{length}.
\DescribeEnv{tabular}
The \software{booktabs} \cite{booktabs} and \software{multirow} \cite{multirow} packages are loaded enabling publication quality tabulars such as in \cref{tab:booktabs}.
\DescribeMacro{\graphic}
\DescribeMacro{\graphics}
The \software{graphicx} package \cite{graphicx} is loaded and the "\graphic"\oarg{width}\marg{figure} macro is defined, which is a wrapper for the "\includegraphics"\marg{figure} macro and takes the figure width as fraction of the "\linewidth" as optional argument (default~1).
If the graphics are located in a sub-folder its path can be indicated by "\graphics"\marg{subfolder}.
% \ifshort
\printbibliography
\end{document}
%
%</documentation>
% \fi
%
% \StopEventually{
% \printbibliography
% \PrintChanges
% }
%
% \appendix
% \section{Implementation}
%
%<*package>
%
% Load the \software{kvoptions} package \cite{kvoptions} and define a "hepfloat" namespace.
% \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=hepfloat,
prefix=hepfloat@
}
% \end{macrocode}
%
% \begin{macro}{manualplacement}
% Provide the "manualplacement" option for reactivating the manual placement of floats.
% \begin{macrocode}
\DeclareBoolOption[true]{manualplacement}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\ProcessKeyvalOptions*
% \end{macrocode}
%
% Adjust the \hologo{LaTeX} float placement defaults
% \begin{macrocode}
\setcounter{bottomnumber}{0} % 1
\setcounter{topnumber}{1} % 2
\setcounter{dbltopnumber}{1} % 2
\renewcommand{\topfraction}{.9} % .7
\renewcommand{\dbltopfraction}{.9} % .7
\renewcommand{\textfraction}{.1} % .2
\renewcommand{\floatpagefraction}{.8} % .5
% \end{macrocode}
%
% \begin{environment}{figure}
% \begin{environment}{table}
% Center the content of "figure" and "table" environments.
% Ignore the manual placement if the "manualplacement" option is set to false.
% \begin{macrocode}
\let\hep@figure\figure%
\let\end@hep@figure\endfigure%
\let\hep@table\table%
\let\end@hep@table\endtable%
\ifhepfloat@manualplacement%
\renewenvironment{figure}[1][tbp]{%
\hep@figure[#1]\centering\small%
}{\end@hep@figure}%
\renewenvironment{table}[1][tbp]{%
\hep@table[#1]\centering\small%
}{\end@hep@table}%
\else%
\renewenvironment{figure}[1][]{%
\hep@figure\centering\small%
}{\end@hep@figure}%
\renewenvironment{table}[1][]{%
\hep@table\centering\small%
}{\end@hep@table}
\fi%
% \end{macrocode}
% \end{environment}
% \end{environment}
%
%
% \subsection{floats}
%
% \begin{environment}{figures}
% \begin{macro}{\figure}
% Define the "figures" environment that places figures next to each other.
% \begin{macrocode}
\newcommand{\figurehspace}{0.0333}
\newcommand{\figurevspace}{.5\baselineskip}
\newenvironment{figures}[2][b]{%
\begin{figure}
\let\oldcaption\caption
\renewcommand{\caption}[1]{%
\renewcommand{\caption}{\oldcaption}%
\captionof{figure}{##1}\vspace{\figurevspace}%
}
\ifdim#2pt>1pt%
\newcommand{\hep@figure@space}{\figurehspace\linewidth/#2}%
\renewcommand{\figure}[1][b]{%
\end{minipage}\hfill%
\begin{minipage}[##1]{\linewidth/#2-\hep@figure@space}%
}
\begin{minipage}[#1]{\linewidth/#2-\hep@figure@space}
\else%
\newcommand{\hep@figure@space}[1]{##1\linewidth*\real{\figurehspace}}
\renewcommand{\figure}[2][b]{%
\end{minipage}\hfill%
\begin{minipage}[##1]{##2\linewidth-\hep@figure@space{##2}}%
}
\begin{minipage}[#1]{#2\linewidth-\hep@figure@space{#2}}
\fi%
}{%
\end{minipage}\end{figure}%
}
% \end{macrocode}
% \end{macro}
% \end{environment}
% \begin{environment}{tables}
% \begin{macro}{\table}
% Define the "tables" environment that places tables next to each other.
% \begin{macrocode}
\newcommand{\tablehspace}{0.0333}
\newcommand{\tablevspace}{.5\baselineskip}
\newenvironment{tables}[2][b]{%
\begin{table}
\let\oldcaption\caption
\renewcommand{\caption}[1]{%
\renewcommand{\caption}{\oldcaption}%
\captionof{table}{##1}\vspace{\tablevspace}%
}
\ifdim#2pt>1pt%
\newcommand{\hep@table@space}{\tablehspace\linewidth/#2}%
\renewcommand{\table}[1][b]{%
\end{minipage}\hfill%
\begin{minipage}[##1]{\linewidth/#2-\hep@table@space}\centering%
}
\begin{minipage}[#1]{\linewidth/#2-\hep@table@space}\centering
\else%
\newcommand{\hep@table@space}[1]{##1\linewidth*\real{\tablehspace}}
\renewcommand{\table}[2][b]{%
\end{minipage}\hfill%
\begin{minipage}[##1]{##2\linewidth-\hep@table@space{##2}}%
\centering%
}
\begin{minipage}[#1]{#2\linewidth-\hep@table@space{#2}}%
\centering
\fi%
}{%
\end{minipage}\end{table}%
}
% \end{macrocode}
% \end{macro}
% \end{environment}
%
% \subsection{Sub-floats}
%
% Load the \software{subcaption} package \cite{subcaption}.
% \begin{macrocode}
\PassOptionsToPackage{subrefformat=parens}{subcaption}
\RequirePackage{subcaption}
\captionsetup{font=small}
\captionsetup[sub]{font=small}
% \end{macrocode}
% Provide the macros for older versions of the \software{subcaption} package using the \software{xparse} \cite{xparse} package.
% \begin{macrocode}
\RequirePackage{xparse}
\providecommand*\subcaption@minipage[2]{%
\minipage#1{#2}\setcaptionsubtype\relax%
}
\ProvideDocumentEnvironment{subcaptionblock}{O{b}m}{%
\caption@withoptargs\subcaption@minipage[#1]{#2}%
}{\endminipage}
% \end{macrocode}
% \begin{environment}{panels}
%
% \begin{macro}{\panel}
% \begin{macro}{\panelhspace}
% \begin{macro}{\panelvspace}
% Define the "panels" environment and the "\panel" macro using the \software{calc} \cite{calc} and \software{etoolbox} \cite{etoolbox} packages.
% \begin{macrocode}
\RequirePackage{calc}
\RequirePackage{etoolbox}
\newcommand{\panelhspace}{0.0333}
\newcommand{\panelvspace}{.5\baselineskip}
\newenvironment{panels}[2][b]{%
\addtolength{\belowcaptionskip}{\panelvspace}%
% \end{macrocode}
% Define an internal macro for global behaviour.
% \begin{macrocode}
\newcommand{\begin@subcaption@minipage}[2][b]{%
% \caption@withoptargs\subcaption@minipage[##1]{##2}%
\subcaptionblock[##1]{##2}%
\centering\vskip 0pt%
% \renewcommand{\hep@panel@vspace}{\panelvspace}%
}%
% \end{macrocode}
% Define the "\panel" macro for the case that the number of panels is given.
% \begin{macrocode}
\ifdim#2pt>1pt%
\newcommand{\hep@panel@space}{\panelhspace\linewidth/#2}%
\newcommand{\panel}[1][b]{%
\endminipage\hfill\begin@subcaption@minipage[#1]{%
\linewidth/#2-\hep@panel@space%
}%
}%
\begin@subcaption@minipage[#1]{\linewidth/#2-\hep@panel@space}%
% \end{macrocode}
% Define the "\panel" macro for the case that the width of the panel is given.
% \begin{macrocode}
\else%
\newcommand{\hep@panel@space}[1]{##1\linewidth*\real{\panelhspace}}%
\newcommand{\panel}[2][b]{%
\endminipage\hfill\begin@subcaption@minipage[#1]{%
##2\linewidth-\hep@panel@space{##2}%
}%
}%
\begin@subcaption@minipage[#1]{%
#2\linewidth-\hep@panel@space{#2}%
}%
\fi%
}{%
\endsubcaptionblock%
\vspace{-\panelvspace}%
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{environment}
%
% \subsection{Tables}
%
% \begin{environment}{tabular}
% Enhance tabulars with the \software{booktabs} and \software{multirow} packages \cite{booktabs, multirow}.
% \begin{macrocode}
\RequirePackage{booktabs}
\RequirePackage{multirow}
% \end{macrocode}
% \end{environment}
% \subsection{Figures}
%
% \begin{macro}{\graphic}
% Provide the "\graphic" macro for the inclusion of figures using the \software{graphicx} package \cite{graphicx}.
% \begin{macrocode}
\RequirePackage{graphicx}
\providecommand{\tikzsetnextfilename}[1]{}
\newcommand{\graphic}[2][1]{\tikzsetnextfilename{#2}{%
\centering\includegraphics[width=#1\linewidth]{#2}\par%
}}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\graphics}
% Provide the "\graphics" macro for the inclusion of figures located in a subfolder.
% \begin{macrocode}
\newcommand{\graphics}[1]{\graphicspath{{./#1/}}}
% \end{macrocode}
% \end{macro}
%
%</package>
%
% \section{Test}
%
%<*test>
%
% \begin{macrocode}
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{hep-float}
\begin{document}
\begin{figure}
\graphic[.5]{example-image-4x3}
\caption{test}
\end{figure}
\begin{figures}{.3}
\graphic{example-image-4x3}
\caption{one}
\figure{.4}
\graphic{example-image-16x9}
\caption{two}
\figure{.3}
\graphic{example-image-4x3}
\caption{three}
\figure{.3}
\graphic{example-image-4x3}
\caption{one}
\figure{.4}
\graphic{example-image-16x9}
\caption{two}
\figure{.3}
\graphic{example-image-4x3}
\caption{three}
\end{figures}
\begin{figures}{3}
\graphic{example-image-1x1}
\caption{one}
\figure
\graphic{example-image-1x1}
\caption{two}
\figure
\graphic{example-image-1x1}
\caption{three}
\figure
\graphic{example-image-1x1}
\caption{one}
\figure
\graphic{example-image-1x1}
\caption{two}
\figure
\graphic{example-image-1x1}
\caption{three}
\end{figures}
\begin{figure}
\begin{panels}{3}
\graphic{example-image-1x1}
\caption{a}
\panel
\graphic{example-image-1x1}
\caption{b}
\panel
\graphic{example-image-1x1}
\caption{c}
\panel
\graphic{example-image-1x1}
\caption{d}
\panel
\graphic{example-image-1x1}
\caption{e}
\panel
\graphic{example-image-1x1}
\caption{f}
\end{panels}
\caption{Panels}
\end{figure}
\begin{figure}
\begin{panels}{.3}
\graphic{example-image-4x3}
\caption{a}
\panel{.4}
\graphic{example-image-16x9}
\caption{b}
\panel{.3}
\graphic{example-image-4x3}
\caption{c}
\panel{.225}
\graphic{example-image-1x1}
\caption{d}
\panel{.4}
\graphic{example-image-16x9}
\caption{e}
\panel{.225}
\graphic[.8]{example-image-1x1}
\caption{f}
\end{panels}
\caption{Panels 2}
\end{figure}
\begin{tables}{2}
\begin{tabular}{cc}\toprule
a & b \\
\bottomrule\end{tabular}
\caption{a}
\table
\begin{tabular}{cc}\toprule
a & b \\
\bottomrule\end{tabular}
\caption{b}
\end{tables}
\end{document}
% \end{macrocode}
%
%</test>
%
% \section{Readme}
%
%<*readme>
%
% \begin{macrocode}
# The `hep-float` package
Convenience package for float placement
## Introduction
The `hep-float` package redefines some `LaTeX` float placement defaults
and defines convenience wrappers for floats. The `hep-float` package can
be loaded with `\usepackage{hep-float}`.
## Author
Jan Hajer
## License
This file may be distributed and/or modified under the conditions of the
`LaTeX` Project Public License, either version 1.3c of this license or
(at your option) any later version. The latest version of this license is
in `http://www.latex-project.org/lppl.txt` and version 1.3c or later is
part of all distributions of LaTeX version 2005/12/01 or later.
% \end{macrocode}
%
%</readme>
%
% \Finale
\endinput
% \PrintIndex
% makeindex -s gglo.ist -o hep-float-implementation.gls hep-float-implementation.glo
% makeindex -s gglo.ist -o hep-float-implementation.ind hep-float-implementation.idx
|