| 1 |
% !TeX root = tcolorbox.tex |
| 2 |
% include file of tcolorbox.tex (manual of the LaTeX package tcolorbox) |
| 3 |
\clearpage |
| 4 |
\section{Library \mylib{fitting}}\label{sec:fitting}% |
| 5 |
\tcbset{external/prefix=external/fitting_}% |
| 6 |
The library is loaded by a package option or inside the preamble by: |
| 7 |
\begin{dispListing} |
| 8 |
\tcbuselibrary{fitting} |
| 9 |
\end{dispListing} |
| 10 |
|
| 11 |
\subsection{Macros of the Library} |
| 12 |
|
| 13 |
\begin{docCommand}{tcboxfit}{\oarg{options}\marg{box content}} |
| 14 |
Creates a colored box where the given \meta{box content} is fitted to |
| 15 |
the width and height of the box. A |\tcboxfit| has to have a fixed height. |
| 16 |
If no fixed height is given, a square box is constructed. |
| 17 |
In principle, most \meta{options} for a \refEnv{tcolorbox} |
| 18 |
can be used for |\tcboxfit| with some restrictions. A |\tcboxfit| cannot have |
| 19 |
a lower part and cannot be broken. |
| 20 |
|
| 21 |
\enlargethispage*{1cm} |
| 22 |
\begin{dispExample} |
| 23 |
% \usepackage{lipsum} \tcbuselibrary{raster} |
| 24 |
\tcbset{colframe=blue!50!black,colback=red!10!white, |
| 25 |
boxsep=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm, |
| 26 |
fit algorithm=hybrid*,raster equal skip=1mm} |
| 27 |
\begin{tcbraster}[raster columns=3,raster valign=bottom] |
| 28 |
\tcboxfit[height=8cm]{\lipsum[1]} |
| 29 |
\tcboxfit[height=4cm]{\lipsum[1]} |
| 30 |
\tcboxfit[height=2cm]{\lipsum[1]} |
| 31 |
\end{tcbraster} |
| 32 |
\begin{tcbraster}[colback=green!10!white,boxsep=1mm] |
| 33 |
\tcboxfit[height=4cm]{\lipsum[2]} |
| 34 |
\tcboxfit[height=4cm,title=With a title]{\lipsum[2]} |
| 35 |
\end{tcbraster} |
| 36 |
\end{dispExample} |
| 37 |
\end{docCommand} |
| 38 |
|
| 39 |
|
| 40 |
\clearpage |
| 41 |
|
| 42 |
|
| 43 |
\begin{docCommands}[ |
| 44 |
doc name = tcbfitdim, |
| 45 |
doc description = {read-only \LaTeX\ length}, |
| 46 |
doc updated = 2020-04-24, |
| 47 |
]{} |
| 48 |
This is a \LaTeX\ length adapted automatically by most variants of |
| 49 |
\refKey{/tcb/fit algorithm}. Therefore, it never is to be |
| 50 |
changed by the user, but may be applied read-only. |
| 51 |
The \refCom{tcbfitdim} corresponds to the font size and may also |
| 52 |
be used to calculate box margins or other distances in dependency. |
| 53 |
The initial and maximum value for \refCom{tcbfitdim} is set by |
| 54 |
\refKey{/tcb/fit basedim}. |
| 55 |
\end{docCommands} |
| 56 |
|
| 57 |
|
| 58 |
\begin{docCommand}{tcbfontsize}{\marg{factor}} |
| 59 |
Selects a font size inside a tcolorbox which is scaled with the given |
| 60 |
\meta{factor} relative to \refCom{tcbfitdim}. |
| 61 |
Also see \refKey{/tcb/fit fontsize macros} |
| 62 |
|
| 63 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 64 |
\tcbset{colback=red!5!white,size=small, |
| 65 |
colframe=red!75!black} |
| 66 |
\begin{tcolorbox}[fit basedim=10pt] |
| 67 |
{\tcbfontsize{0.25} Very tiny,}\\ |
| 68 |
{\tcbfontsize{0.5} Small,}\\ |
| 69 |
{\tcbfontsize{1} Normal,}\\ |
| 70 |
{\tcbfontsize{2} Large,}\\ |
| 71 |
{\tcbfontsize{4} Huge.} |
| 72 |
\end{tcolorbox} |
| 73 |
\end{dispExample*} |
| 74 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 75 |
\tcbset{colback=red!5!white,size=small, |
| 76 |
colframe=red!75!black} |
| 77 |
\begin{tcolorbox}[fit basedim=10pt, |
| 78 |
fit to height=2cm] |
| 79 |
{\tcbfontsize{0.25} Very tiny,}\\ |
| 80 |
{\tcbfontsize{0.5} Small,}\\ |
| 81 |
{\tcbfontsize{1} Normal,}\\ |
| 82 |
{\tcbfontsize{2} Large,}\\ |
| 83 |
{\tcbfontsize{4} Huge.} |
| 84 |
\end{tcolorbox} |
| 85 |
\end{dispExample*} |
| 86 |
\end{docCommand} |
| 87 |
|
| 88 |
|
| 89 |
\clearpage |
| 90 |
\subsection{Producing \texttt{\textbackslash tcboxfit} Commands}\label{subsec:fitting_new} |
| 91 |
|
| 92 |
|
| 93 |
\begin{docCommand}{newtcboxfit}{\oarg{init options}\brackets{\texttt{\textbackslash}\rmfamily\meta{name}}\oarg{number}\oarg{default}\marg{options}} |
| 94 |
Creates a new macro \texttt{\textbackslash}\meta{name} based on \refCom{tcboxfit}. |
| 95 |
Basically, |\newtcboxfit| operates like |\newcommand|. |
| 96 |
The new macro \texttt{\textbackslash}\meta{name} optionally takes \meta{number}$+1$ arguments, where |
| 97 |
\meta{default} is the default value for the optional first argument. |
| 98 |
The \meta{options} are given to the underlying |\tcboxfit|. |
| 99 |
The \meta{init options} allow setting up automatic numbering, |
| 100 |
see Section \ref{sec:initkeys} from page \pageref{sec:initkeys}. |
| 101 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 102 |
\newtcboxfit{\mybox}{colback=red!5!white, |
| 103 |
colframe=red!75!black,width=4cm, |
| 104 |
height=1.5cm,halign=center} |
| 105 |
|
| 106 |
\mybox{This is my own box.}\par |
| 107 |
\mybox{This is my own box with more text |
| 108 |
to be written.} |
| 109 |
\end{dispExample*} |
| 110 |
|
| 111 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 112 |
% \usepackage{lipsum} |
| 113 |
\newtcboxfit{\mybox}[2]{colback=red!5!white, |
| 114 |
colframe=red!75!black,fonttitle=\bfseries, |
| 115 |
boxsep=1mm,left=0mm,right=0mm,top=0mm, |
| 116 |
bottom=0mm,halign=center,valign=center, |
| 117 |
nobeforeafter,width=#1,height=#2} |
| 118 |
|
| 119 |
\mybox{2.5cm}{1cm}{First box}% |
| 120 |
\mybox{2.5cm}{1cm}{Second box with more text}\\ |
| 121 |
\mybox{5cm}{2cm}{Third box with text}\\ |
| 122 |
\mybox{5cm}{3cm}{\lipsum[1]} |
| 123 |
\end{dispExample*} |
| 124 |
|
| 125 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 126 |
% \usepackage{lipsum} |
| 127 |
\newtcboxfit{\mybox}[2][]{colback=red!5!white, |
| 128 |
colframe=red!75!black, |
| 129 |
width=#2,height=#2/3*2,#1} |
| 130 |
|
| 131 |
\mybox[colback=yellow]{5cm}% |
| 132 |
{\lipsum[2]} |
| 133 |
\end{dispExample*} |
| 134 |
\end{docCommand} |
| 135 |
|
| 136 |
|
| 137 |
\begin{docCommand}{renewtcboxfit}{\oarg{init options}\brackets{\texttt{\textbackslash}\rmfamily\meta{name}}\oarg{number}\oarg{default}\marg{options}} |
| 138 |
Operates like \refCom{newtcboxfit}, but based on |\renewcommand| instead of |\newcommand|. |
| 139 |
An existing macro is redefined. |
| 140 |
\end{docCommand} |
| 141 |
|
| 142 |
|
| 143 |
\clearpage |
| 144 |
|
| 145 |
\begin{docCommand}{NewTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}} |
| 146 |
Creates a new command \texttt{\textbackslash}\meta{name} based on \refCom{tcboxfit}. |
| 147 |
Basically, \refCom{NewTCBoxFit} operates like |\NewDocumentCommand|. This means, |
| 148 |
the new command \texttt{\textbackslash}\meta{name} is constructed with the given |
| 149 |
\LaTeX3 argument \meta{specification} following \cite{latexproject:usrguide}. |
| 150 |
An error is issued if \texttt{\textbackslash}\meta{name} has already been defined. |
| 151 |
The \meta{options} are given to the underlying \refCom{tcboxfit}.\\ |
| 152 |
Note that \refKey{/tcb/savedelimiter} is set to the given \meta{name} |
| 153 |
automatically.\\ |
| 154 |
The \meta{init options} allow setting up automatic numbering, |
| 155 |
see Section \ref{sec:initkeys} from page \pageref{sec:initkeys}. |
| 156 |
|
| 157 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 158 |
% \usepackage{lipsum} |
| 159 |
|
| 160 |
\NewTCBoxFit{\mybox}{ O{} m !o } |
| 161 |
{colback=red!5!white, |
| 162 |
colframe=red!75!black, |
| 163 |
width=#2,height=#2/3*2, |
| 164 |
IfValueT={#3}{height=#3}, |
| 165 |
#1} |
| 166 |
|
| 167 |
\mybox[colback=yellow]{5cm}% |
| 168 |
{\lipsum[2]} |
| 169 |
|
| 170 |
\mybox[colback=yellow]{5cm}[4cm]{\lipsum[2]} |
| 171 |
\end{dispExample*} |
| 172 |
\end{docCommand} |
| 173 |
|
| 174 |
\begin{docCommand}{RenewTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}} |
| 175 |
Operates like \refCom{NewTCBoxFit}, but based on |\RenewDocumentCommand| instead of |\NewDocumentCommand|. |
| 176 |
An existing command is redefined. |
| 177 |
\end{docCommand} |
| 178 |
|
| 179 |
\begin{docCommand}{ProvideTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}} |
| 180 |
Operates like \refCom{NewTCBoxFit}, but based on |\ProvideDocumentCommand| instead of |\NewDocumentCommand|. |
| 181 |
The command \texttt{\textbackslash}\meta{name} is only created if it is not already defined. |
| 182 |
\end{docCommand} |
| 183 |
|
| 184 |
\begin{docCommand}{DeclareTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}} |
| 185 |
Operates like \refCom{NewTCBoxFit}, but based on |\DeclareDocumentCommand| instead of |\NewDocumentCommand|. |
| 186 |
The new command \texttt{\textbackslash}\meta{name} is always created, irrespective of an already existing |
| 187 |
command with the same name. |
| 188 |
\end{docCommand} |
| 189 |
|
| 190 |
\clearpage |
| 191 |
|
| 192 |
\begin{docCommand}{NewTotalTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}\marg{content}} |
| 193 |
Creates a new command \texttt{\textbackslash}\meta{name} based on \refCom{tcboxfit}. |
| 194 |
In contrast to \refCom{NewTCBoxFit}, also the \meta{content} of the |\tcboxfit| is specified.\\ |
| 195 |
Basically, \refCom{NewTotalTCBoxFit} operates like |\NewDocumentCommand|. This means, |
| 196 |
the new command \texttt{\textbackslash}\meta{name} is constructed with the given |
| 197 |
\LaTeX3 argument \meta{specification} following \cite{latexproject:usrguide}. |
| 198 |
An error is issued if \texttt{\textbackslash}\meta{name} has already been defined. |
| 199 |
The \meta{options} are given to the underlying \refCom{tcboxfit} which is filled with |
| 200 |
the specified \meta{content}.\\ |
| 201 |
Note that \refKey{/tcb/savedelimiter} is set to the given \meta{name} |
| 202 |
automatically.\\ |
| 203 |
The \meta{init options} allow setting up automatic numbering, |
| 204 |
see Section \ref{sec:initkeys} from page \pageref{sec:initkeys}. |
| 205 |
|
| 206 |
\begin{dispExample} |
| 207 |
% \usepackage{lipsum} |
| 208 |
|
| 209 |
\NewTotalTCBoxFit{\multibox}{ O{} m O{10} m } |
| 210 |
{nobeforeafter,colback=red!5!white,colframe=red!75!black,width=#2,height=#2/3*2, |
| 211 |
valign=center,#1} |
| 212 |
{ \foreach \n in {1,...,#3} { #4} } |
| 213 |
|
| 214 |
\multibox{5cm}{I shall not repeat.} |
| 215 |
\multibox[colframe=blue!75!white]{5cm}[20]{I shall not repeat.}\\ |
| 216 |
\multibox[colback=yellow,height=5cm]{14cm}[100]{I shall not repeat.} |
| 217 |
\end{dispExample} |
| 218 |
\end{docCommand} |
| 219 |
|
| 220 |
\begin{docCommand}{RenewTotalTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}\marg{content}} |
| 221 |
Operates like \refCom{NewTotalTCBoxFit}, but based on |\RenewDocumentCommand| instead of |\NewDocumentCommand|. |
| 222 |
An existing command is redefined. |
| 223 |
\end{docCommand} |
| 224 |
|
| 225 |
\begin{docCommand}{ProvideTotalTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}\marg{content}} |
| 226 |
Operates like \refCom{NewTotalTCBoxFit}, but based on |\ProvideDocumentCommand| instead of |\NewDocumentCommand|. |
| 227 |
The command \texttt{\textbackslash}\meta{name} is only created if it is not already defined. |
| 228 |
\end{docCommand} |
| 229 |
|
| 230 |
\begin{docCommand}{DeclareTotalTCBoxFit}{\oarg{init options}\brackets{\texttt{\textbackslash}\meta{name}}\marg{specification}\marg{options}\marg{content}} |
| 231 |
Operates like \refCom{NewTotalTCBoxFit}, but based on |\DeclareDocumentCommand| instead of |\NewDocumentCommand|. |
| 232 |
The new command \texttt{\textbackslash}\meta{name} is always created, irrespective of an already existing |
| 233 |
command with the same name. |
| 234 |
\end{docCommand} |
| 235 |
|
| 236 |
|
| 237 |
\clearpage |
| 238 |
\subsection{Option Keys of the Library}\label{subsec:fit} |
| 239 |
|
| 240 |
The font size for the content of a box with fixed width and fixed height |
| 241 |
can be adjusted automatically. This is called the \emph{fitbox capture mode}. |
| 242 |
Note that the fit control algorithm |
| 243 |
constructs a series of versions for the box and selects the \enquote{best}. |
| 244 |
Therefore, the compilation time is quite longer than for a normal box. |
| 245 |
The algorithm will fail, if a different selected font size does not change the |
| 246 |
overall size of the box content. |
| 247 |
The \refCom{tcboxfit} macro uses this algorithm by default. |
| 248 |
|
| 249 |
|
| 250 |
\medskip |
| 251 |
\begin{marker} |
| 252 |
The fit control keys are only applicable to unbreakable boxes without |
| 253 |
a lower part. |
| 254 |
The box content should not change counters. |
| 255 |
\end{marker} |
| 256 |
\medskip |
| 257 |
|
| 258 |
\enlargethispage*{5mm} |
| 259 |
\begin{docTcbKey}{fit}{}{style, initially unset} |
| 260 |
Sets the \refKey{/tcb/capture} mode to \docValue{fitbox}, i.\,e., enables the |
| 261 |
font size adjustment algorithm. Thereby, a \refEnv{tcolorbox} acts |
| 262 |
like \refCom{tcboxfit} where the given \meta{box content} is fitted to |
| 263 |
the width and height of the box. Therefore, the box has to have a fixed height. |
| 264 |
If no fixed height is given, a square box is constructed. |
| 265 |
The font dimension \refCom{tcbfitdim} can also be used to adjust |
| 266 |
the margins of the box since a box with a tiny font may not need large |
| 267 |
margins. The number of constructed boxes is saved to the macro \docAuxCommand{tcbfitsteps} |
| 268 |
for analysis. |
| 269 |
|
| 270 |
\begin{dispExample} |
| 271 |
% \usepackage{lipsum} |
| 272 |
% \tcbuselibrary{skins} |
| 273 |
\newtcolorbox{fitting}[2][]{fit,height=#2,boxsep=1pt,valign=center,opacityupper=0.5, |
| 274 |
top=0.4\tcbfitdim,bottom=0.4\tcbfitdim,left=0.75\tcbfitdim,right=0.75\tcbfitdim, |
| 275 |
enhanced,watermark text={\tcbfitsteps},colframe=blue!75!black,colback=white,#1} |
| 276 |
|
| 277 |
\begin{fitting}{4cm} |
| 278 |
\lipsum[1] |
| 279 |
\end{fitting} |
| 280 |
|
| 281 |
\begin{fitting}{2cm} |
| 282 |
\lipsum[2] |
| 283 |
\end{fitting} |
| 284 |
|
| 285 |
\begin{fitting}{1cm} |
| 286 |
\lipsum[3] |
| 287 |
\end{fitting} |
| 288 |
\end{dispExample} |
| 289 |
\end{docTcbKey} |
| 290 |
|
| 291 |
|
| 292 |
\clearpage |
| 293 |
\begin{docTcbKey}{fit to}{=\meta{width} and \meta{height}}{style, initially unset} |
| 294 |
Shortcut for using \refKey{/tcb/fit} and setting the \meta{width} and \meta{height} values |
| 295 |
separately. |
| 296 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 297 |
\tcbset{colback=red!5!white,colframe=red!75!black} |
| 298 |
|
| 299 |
\begin{tcolorbox}[fit to=3cm and 2cm] |
| 300 |
This box content is fitted to the given |
| 301 |
dimensions. |
| 302 |
\end{tcolorbox} |
| 303 |
\end{dispExample*} |
| 304 |
\end{docTcbKey} |
| 305 |
|
| 306 |
|
| 307 |
\begin{docTcbKey}{fit to height}{=\meta{height}}{style, initially unset} |
| 308 |
Shortcut for using \refKey{/tcb/fit} and setting the \meta{height} value separately. |
| 309 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 310 |
\tcbset{colback=red!5!white,colframe=red!75!black} |
| 311 |
|
| 312 |
\begin{tcolorbox}[fit to height=2cm] |
| 313 |
This box content is fitted to the given |
| 314 |
height. |
| 315 |
\end{tcolorbox} |
| 316 |
\end{dispExample*} |
| 317 |
\end{docTcbKey} |
| 318 |
|
| 319 |
\begin{docTcbKey}{fit basedim}{=\meta{length}}{no default, initially |10pt|} |
| 320 |
Sets the starting font dimension for the font size adjustment algorithm |
| 321 |
to \meta{length}. The algorithm never enlarges this dimension. |
| 322 |
Therefore, the final \refCom{tcbfitdim} is identical to or small than |
| 323 |
\meta{length}. |
| 324 |
|
| 325 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 326 |
\tcbset{colback=red!5!white,colframe=red!75!black} |
| 327 |
|
| 328 |
\begin{tcolorbox}[fit to=4cm and 2cm] |
| 329 |
Too few words for the box. |
| 330 |
\end{tcolorbox} |
| 331 |
|
| 332 |
\begin{tcolorbox}[fit to=4cm and 2cm, |
| 333 |
fit basedim=50pt] |
| 334 |
Enough words for the box. |
| 335 |
\end{tcolorbox} |
| 336 |
\end{dispExample*} |
| 337 |
\end{docTcbKey} |
| 338 |
|
| 339 |
|
| 340 |
\begin{docTcbKey}{fit skip}{=\meta{real value}}{no default, initially |1.2|} |
| 341 |
Sets the skip value of the selected font to \meta{real value} times \refCom{tcbfitdim}. |
| 342 |
|
| 343 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 344 |
% \usepackage{lipsum} |
| 345 |
\tcbset{colback=red!5!white, |
| 346 |
colframe=red!75!black,left=1mm, |
| 347 |
right=1mm,boxsep=0mm} |
| 348 |
|
| 349 |
\begin{tcolorbox}[fit to=5cm and 4cm, |
| 350 |
fit skip=1.0 ] |
| 351 |
\lipsum[1] |
| 352 |
\end{tcolorbox} |
| 353 |
\end{dispExample*} |
| 354 |
\end{docTcbKey} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
\clearpage |
| 359 |
\begin{docTcbKey}{fit fontsize macros}{}{style, initially unset} |
| 360 |
Redefines the standard \LaTeX\ font size macros |
| 361 |
|\tiny|, |\scriptsize|, |\footnotesize|, |\small|, |\normalsize|, |
| 362 |
|\large|, |\Large|, |\LARGE|, |\huge|, and |\Huge|, |
| 363 |
to set font sizes relative to |
| 364 |
the current \refCom{tcbfitdim}. Note that the display skip values for |
| 365 |
mathematical formulas are respected by the redefined macros. |
| 366 |
Also see \refCom{tcbfontsize}. |
| 367 |
|
| 368 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 369 |
% \usepackage{lipsum} |
| 370 |
\tcbset{colback=red!5!white, |
| 371 |
colframe=red!75!black,left=1mm, |
| 372 |
right=1mm,boxsep=0mm} |
| 373 |
|
| 374 |
\begin{tcolorbox}[fit to height=4cm] |
| 375 |
{\Large\bfseries This text is |
| 376 |
not adapted:\par} |
| 377 |
\lipsum[2] |
| 378 |
\end{tcolorbox} |
| 379 |
|
| 380 |
\begin{tcolorbox}[fit to height=4cm, |
| 381 |
fit fontsize macros ] |
| 382 |
{\Large\bfseries This text is adapted:\par} |
| 383 |
\lipsum[2] |
| 384 |
\end{tcolorbox} |
| 385 |
\end{dispExample*} |
| 386 |
|
| 387 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 388 |
\tcbset{colback=red!5!white, |
| 389 |
colframe=red!75!black,left=1mm, |
| 390 |
right=1mm,boxsep=0mm} |
| 391 |
|
| 392 |
\let\realHuge=\Huge |
| 393 |
|
| 394 |
\begin{tcolorbox}[fit basedim=7pt, |
| 395 |
fontupper=\normalsize, |
| 396 |
fit fontsize macros] |
| 397 |
The relative font size macros |
| 398 |
are also usable without the |
| 399 |
\textit{fit} algorithm.\par |
| 400 |
{\Huge Adapted Huge} --- |
| 401 |
{\realHuge Original Huge} |
| 402 |
\end{tcolorbox} |
| 403 |
|
| 404 |
\end{dispExample*} |
| 405 |
|
| 406 |
|
| 407 |
\begin{dispExample*}{sbs,lefthand ratio=0.6} |
| 408 |
\tcbset{size=fbox,colback=red!5!white, |
| 409 |
colframe=red!75!black} |
| 410 |
|
| 411 |
\tcboxfit[height=5cm, |
| 412 |
fit fontsize macros, |
| 413 |
fonttitle=\normalsize\bfseries, |
| 414 |
title=Adapted title] |
| 415 |
{\lipsum[2]} |
| 416 |
|
| 417 |
\end{dispExample*} |
| 418 |
\end{docTcbKey} |
| 419 |
|
| 420 |
|
| 421 |
\clearpage |
| 422 |
\begin{docTcbKey}{fit height plus}{=\meta{dimension}}{no default, initially |0pt|} |
| 423 |
The box is allowed to enlarge the fixed height up to the given \meta{dimension}, |
| 424 |
before a font size fit is applied. An optional \refKey{/tcb/fit width plus} |
| 425 |
is tried after the height adaption. |
| 426 |
\begin{dispExample} |
| 427 |
% \usepackage{lipsum} |
| 428 |
\tcbset{colback=red!5!white,colframe=red!75!black,left=1mm,top=1mm,bottom=1mm, |
| 429 |
right=1mm,boxsep=0mm,width=3cm,height=3cm,nobeforeafter} |
| 430 |
|
| 431 |
\begin{tcolorbox}[fit] |
| 432 |
This is a tcolorbox. |
| 433 |
\end{tcolorbox} |
| 434 |
\begin{tcolorbox}[fit,fit height plus=1cm] |
| 435 |
This is a tcolorbox. |
| 436 |
\end{tcolorbox} |
| 437 |
\begin{tcolorbox}[fit] |
| 438 |
\lipsum[2] |
| 439 |
\end{tcolorbox} |
| 440 |
\begin{tcolorbox}[fit,fit height plus=1cm] |
| 441 |
\lipsum[2] |
| 442 |
\end{tcolorbox} |
| 443 |
\end{dispExample} |
| 444 |
\end{docTcbKey} |
| 445 |
|
| 446 |
|
| 447 |
\begin{docTcbKey}{fit width plus}{=\meta{dimension}}{no default, initially |0pt|} |
| 448 |
The box is allowed to enlarge the fixed width up to the given \meta{dimension}, |
| 449 |
before a font size fit is applied. An optional \refKey{/tcb/fit height plus} |
| 450 |
is tried before the width adaption. |
| 451 |
\enlargethispage*{1cm} |
| 452 |
\begin{dispExample} |
| 453 |
% \usepackage{lipsum} |
| 454 |
\tcbset{colback=red!5!white,colframe=red!75!black,left=1mm,top=1mm,bottom=1mm, |
| 455 |
right=1mm,boxsep=0mm,width=3cm,height=3cm,nobeforeafter} |
| 456 |
|
| 457 |
\begin{tcolorbox}[fit] |
| 458 |
This is a tcolorbox. |
| 459 |
\end{tcolorbox} |
| 460 |
\begin{tcolorbox}[fit,fit width plus=1cm] |
| 461 |
This is a tcolorbox. |
| 462 |
\end{tcolorbox} |
| 463 |
\begin{tcolorbox}[fit] |
| 464 |
\lipsum[2] |
| 465 |
\end{tcolorbox} |
| 466 |
\begin{tcolorbox}[fit,fit width plus=1cm] |
| 467 |
\lipsum[2] |
| 468 |
\end{tcolorbox} |
| 469 |
\end{dispExample} |
| 470 |
\end{docTcbKey} |
| 471 |
|
| 472 |
|
| 473 |
\begin{marker} |
| 474 |
Typically but not necessarily, the optional title of a |tcolorbox| is not part of the fit operation. |
| 475 |
If a \refKey{/tcb/fit width plus} is applied, the title is also adapted to |
| 476 |
the new width. If counters are increased inside the title text, they may be |
| 477 |
increased more than one time. |
| 478 |
To avoid this, you are encouraged to use \refKey{/tcb/phantom} or \refKey{/tcb/step and label} |
| 479 |
to set counters or use automatic numbering, see Subsection \ref{sec:numberedboxes} |
| 480 |
from page \pageref{sec:numberedboxes}. |
| 481 |
\end{marker} |
| 482 |
|
| 483 |
|
| 484 |
\begin{docTcbKey}{fit width from}{=\meta{min} \texttt{to} \meta{max}}{style, no default} |
| 485 |
Sets the box width to \meta{min} and allows the width to grow up to \meta{max}. |
| 486 |
\begin{dispExample} |
| 487 |
% \usepackage{lipsum} |
| 488 |
\tcbset{colback=red!5!white,colframe=red!75!black,left=1mm,top=1mm,bottom=1mm, |
| 489 |
right=1mm,boxsep=0mm,height=4cm} |
| 490 |
|
| 491 |
\begin{tcolorbox}[fit,width=\linewidth/2] |
| 492 |
\lipsum[2] |
| 493 |
\end{tcolorbox}\par |
| 494 |
\begin{tcolorbox}[fit width from=\linewidth/2 to \linewidth] |
| 495 |
\lipsum[2] |
| 496 |
\end{tcolorbox}\par |
| 497 |
\end{dispExample} |
| 498 |
\end{docTcbKey} |
| 499 |
|
| 500 |
\clearpage |
| 501 |
\begin{docTcbKey}{fit height from}{=\meta{min} \texttt{to} \meta{max}}{style, no default} |
| 502 |
Sets the box height to \meta{min} and allows the height to grow up to \meta{max}. |
| 503 |
\begin{dispExample} |
| 504 |
% \usepackage{lipsum} |
| 505 |
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black,left=1mm,top=1mm, |
| 506 |
bottom=1mm,right=1mm,boxsep=0mm,width=4cm,nobeforeafter, |
| 507 |
fit height from=1cm to 8cm} |
| 508 |
|
| 509 |
\begin{mybox} |
| 510 |
This is a tcolorbox. |
| 511 |
\end{mybox} |
| 512 |
\begin{mybox} |
| 513 |
This is a tcolorbox. This is a tcolorbox. This is a tcolorbox. |
| 514 |
\end{mybox} |
| 515 |
\begin{mybox} |
| 516 |
\lipsum[2] |
| 517 |
\end{mybox} |
| 518 |
\end{dispExample} |
| 519 |
\end{docTcbKey} |
| 520 |
|
| 521 |
\clearpage |
| 522 |
\begin{docTcbKey}{fit algorithm}{=\meta{name}}{no default, initially |fontsize|} |
| 523 |
Sets the algorithm for the fitting process \emph{after} optionally width and height |
| 524 |
are adapted. In the following, adapting the font size means adapting |
| 525 |
\refCom{tcbfitdim}. |
| 526 |
Feasible values for \meta{name} are: |
| 527 |
\begin{itemize} |
| 528 |
\item\docValue{fontsize} (initial): |
| 529 |
The algorithm is a bisection method that adapts the font size until |
| 530 |
certain stop conditions are fulfilled. This is the most time-consuming |
| 531 |
method but it is robust and gives pleasant results. |
| 532 |
\begin{marker} |
| 533 |
The used font has to be freely scalable for this method! |
| 534 |
Other content than text is not scaled down. |
| 535 |
The aspect ratio is fully guaranteed. |
| 536 |
\end{marker} |
| 537 |
\item\docValue{fontsize*}:\tcbdocmarginnote{\tcbdocnew{2014-10-29}} |
| 538 |
First, the \docValue{fontsize} algorithm is applied. If the font was scaled down |
| 539 |
and the resulting height is too small, the box is squeezed to fit the area. |
| 540 |
\begin{marker} |
| 541 |
The used font has to be freely scalable for this method! |
| 542 |
Other content than text may be slightly rescaled. |
| 543 |
The aspect ratio cannot be fully guaranteed. |
| 544 |
\end{marker} |
| 545 |
\item\docValue{areasize}: |
| 546 |
The algorithm calculates the area size for the text without scaling the font. |
| 547 |
The text box is shaped for the needed aspect ratio in one or two |
| 548 |
steps. Finally, it is scaled down with a standard |\resizebox| macro. |
| 549 |
\begin{marker} |
| 550 |
The used font has not to be scalable. Every box content is scaled down. |
| 551 |
The aspect ratio cannot be fully guaranteed. |
| 552 |
\end{marker} |
| 553 |
\item\docValue{areasize*}:\tcbdocmarginnote{\tcbdocnew{2014-10-29}} |
| 554 |
The \docValue{areasize} algorithm is applied, but if the content was scaled |
| 555 |
down and the resulting height is too small, the box is squeezed to fit the area. |
| 556 |
\begin{marker} |
| 557 |
The used font has not to be scalable. Every box content is scaled down. |
| 558 |
The aspect ratio cannot be fully guaranteed. |
| 559 |
\end{marker} |
| 560 |
\item\docValue{hybrid}: |
| 561 |
First, this algorithm estimates the needed font size in one or two steps. |
| 562 |
Then an \docValue{areasize} fitting as above is a applied. |
| 563 |
\begin{marker} |
| 564 |
The used font has to be freely scalable for this method! |
| 565 |
Other content than text may be slightly rescaled. |
| 566 |
The aspect ratio cannot be fully guaranteed. |
| 567 |
\end{marker} |
| 568 |
\item\docValue{hybrid*}:\tcbdocmarginnote{\tcbdocnew{2014-10-29}} |
| 569 |
First, this algorithm estimates the needed font size in one or two steps. |
| 570 |
Then an \docValue{areasize*} fitting as above is a applied. |
| 571 |
\begin{marker} |
| 572 |
The used font has to be freely scalable for this method! |
| 573 |
Other content than text may be slightly rescaled. |
| 574 |
The aspect ratio cannot be fully guaranteed. |
| 575 |
\end{marker} |
| 576 |
\item\docValue{squeeze}: |
| 577 |
The text box is brutally scaled down to fit. |
| 578 |
\begin{marker} |
| 579 |
The aspect ratio is very likely to be horrible. |
| 580 |
You should not use this method for final documents. |
| 581 |
\end{marker} |
| 582 |
\end{itemize} |
| 583 |
|
| 584 |
|
| 585 |
\end{docTcbKey} |
| 586 |
\begin{dispExample} |
| 587 |
% \usepackage{lipsum} |
| 588 |
\newtcboxfit{\mybox}[1]{colback=red!5!white,colframe=red!75!black,left=1mm,top=1mm, |
| 589 |
bottom=1mm,right=1mm,boxsep=0mm,width=3.5cm,height=7cm,nobeforeafter, |
| 590 |
before upper=\textcolor{blue}{\rule{5mm}{5mm}}\ , |
| 591 |
enhanced,watermark text={\tcbfitsteps}, |
| 592 |
fonttitle=\bfseries,adjusted title={#1},fit algorithm=#1} |
| 593 |
|
| 594 |
\mybox{fontsize}{\lipsum[2]}\hfill |
| 595 |
\mybox{hybrid}{\lipsum[2]}\hfill |
| 596 |
\mybox{areasize}{\lipsum[2]}\hfill |
| 597 |
\mybox{squeeze}{\lipsum[2]} |
| 598 |
|
| 599 |
Quality \dotfill versus \dotfill Speed |
| 600 |
\end{dispExample} |
| 601 |
|
| 602 |
|
| 603 |
\begin{dispExample} |
| 604 |
% \usepackage{lipsum} |
| 605 |
\newtcboxfit{\mybox}[2]{colback=red!5!white,colframe=red!75!black,left=1mm,top=1mm, |
| 606 |
size=tight,width=7.2cm,height=5cm,nobeforeafter, |
| 607 |
before upper=\textcolor{blue}{\rule{5mm}{5mm}}\ , |
| 608 |
enhanced,fonttitle=\bfseries,adjusted title={#2},fit algorithm=#1} |
| 609 |
|
| 610 |
\mybox{hybrid}{hybrid (possible gap at end)}{\lipsum[1]}\hfill |
| 611 |
\mybox{hybrid*}{hybrid* (no gap but possibly squeezed)}{\lipsum[1]} |
| 612 |
\end{dispExample} |
| 613 |
|
| 614 |
|
| 615 |
\clearpage |
| 616 |
\begin{marker} |
| 617 |
The following options set control parameters for the fit algorithm. |
| 618 |
Mainly, they apply to the |fontsize| variant, see \refKey{/tcb/fit algorithm}. |
| 619 |
The options should be seen as experimental and are likely to change in future versions, |
| 620 |
if necessary. |
| 621 |
\end{marker} |
| 622 |
|
| 623 |
\begin{docTcbKey}{fit maxstep}{=\meta{number}}{no default, initially |20|} |
| 624 |
Sets the maximal step size for the font size adjustment algorithm. |
| 625 |
In normal situations, the algorithm stops before reaching the initial value of 20 steps. |
| 626 |
If the box content does not shrink, this value prevents an endless loop. |
| 627 |
\end{docTcbKey} |
| 628 |
|
| 629 |
|
| 630 |
\begin{docTcbKey}{fit maxfontdiff}{=\meta{dimension}}{no default, initially |0.1pt|} |
| 631 |
The algorithm stops, if the font size is determined within a deviation of |
| 632 |
\meta{dimension}. |
| 633 |
\end{docTcbKey} |
| 634 |
|
| 635 |
|
| 636 |
\begin{docTcbKey}{fit maxfontdiffgap}{=\meta{dimension}}{no default, initially |1pt|} |
| 637 |
The algorithm stops, if the number of lines is determined and the font size is |
| 638 |
determined within a deviation of \meta{dimension}. |
| 639 |
\end{docTcbKey} |
| 640 |
|
| 641 |
|
| 642 |
\begin{docTcbKey}{fit maxwidthdiff}{=\meta{dimension}}{no default, initially |1pt|} |
| 643 |
The algorithm stops, if the (optionally) flexible box width |
| 644 |
is determined within a deviation of \meta{dimension}. |
| 645 |
\end{docTcbKey} |
| 646 |
|
| 647 |
|
| 648 |
\begin{docTcbKey}{fit maxwidthdiffgap}{=\meta{dimension}}{no default, initially |10pt|} |
| 649 |
The algorithm stops, if the number of lines is determined and the (optionally) flexible box width |
| 650 |
is determined within a deviation of \meta{dimension}. |
| 651 |
\end{docTcbKey} |
| 652 |
|
| 653 |
|
| 654 |
\begin{docTcbKey}{fit warning}{=\meta{value}}{no default, initially |off|} |
| 655 |
Typically, the fit control algorithm constructs several auxiliary boxes |
| 656 |
to determine the optimal one. If not switched off, the construction of |
| 657 |
the auxiliary boxes may produce many |hbox| warnings. This option key |
| 658 |
changes the |\hbadness| value. |
| 659 |
\begin{itemize} |
| 660 |
\item\docValue{off}: Most of |`Underfull \hbox'| and |`Overfull \hbox'| warnings are |
| 661 |
switched off (including the ones for the finally used box). |
| 662 |
\item\docValue{on}: All warnings for all auxiliary boxes are displayed. |
| 663 |
\item\docValue{final}: Only warnings for the finally used box are displayed. |
| 664 |
Note that an additional box has to be constructed for these messages. |
| 665 |
\end{itemize} |
| 666 |
\end{docTcbKey} |
| 667 |
|