Debian Codegraph @

texmf-dist/source/latex/koma-script/scrkernel-floats.dtx

raw
1 % \iffalse meta-comment
2 % ======================================================================
3 % scrkernel-floats.dtx
4 % Copyright (c) Markus Kohm, 2002-2025
5 %
6 % This file is part of the LaTeX2e KOMA-Script bundle.
7 %
8 % This work may be distributed and/or modified under the conditions of
9 % the LaTeX Project Public License, version 1.3c of the license.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later and of this work.
14 %
15 % This work has the LPPL maintenance status "author-maintained".
16 %
17 % The Current Maintainer and author of this work is Markus Kohm.
18 %
19 % This work consists of all files listed in MANIFEST.md.
20 % ======================================================================
21 %%% From File: $Id: scrkernel-floats.dtx 4197 2025-08-15 09:13:30Z kohm $
22 %<option>%%% (run: option)
23 %<body>%%% (run: body)
24 %<*dtx>
25 \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
26 \begingroup
27 \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
28 \filedate$Date: 2025-08-15 11:13:30 +0200 (Fr, 15. Aug 2025) $
29 \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
30 \filerevision$Revision: 4197 $
31 \edef\reserved@a{%
32 \noexpand\endgroup
33 \noexpand\ProvidesFile{scrkernel-floats.dtx}%
34 [\filedate\space\filerevision\space
35 KOMA-Script source
36 (floats)]
37 }%
38 \reserved@a
39 \documentclass[USenglish]{koma-script-source-doc}
40 \usepackage{babel}
41 \setcounter{StandardModuleDepth}{2}
42 \begin{document}
43 \DocInput{scrkernel-floats.dtx}
44 \end{document}
45 %</dtx>
46 % \fi
47 %
48 % \changes{v2.95}{2002/07/01}{new by splitting \file{scrclass.dtx}}
49 % \changes{v3.36}{2022/02/22}{switch over from \cls*{scrdoc} to
50 % \cls*{koma-script-source-doc}}
51 % \changes{v3.36}{2022/02/22}{implementation documentation in English}
52 % \changes{v3.40}{2023/04/17}{guide names changed}
53 %
54 % \GetFileInfo{scrkernel-floats.dtx}
55 % \title{Code for the Foats of the
56 % \href{https://komascript.de}{\KOMAScript} Classes}
57 % \author{\href{mailto:[email protected]}{Markus Kohm}}
58 % \date{Revision \fileversion{} of \filedate}
59 % \maketitle
60 % \begin{abstract}
61 % The code for floats in \file{scrkernel-floats.dtx} is older than the
62 % generic hook mechanism in the \LaTeX{} kernel. Because of this, it
63 % currently does not use the kernel hook mechanism. Mostly it is also older
64 % then the \KOMAScript{} package \pkg*{tocbasic} to implement and manage
65 % floats. So several code has been adapted several times and maybe a general
66 % re-implementation would be a good idea.
67 % \end{abstract}
68 % \tableofcontents
69 %
70 % \section{User Manual}
71 %
72 % You can find the user documentation the commands implemented here in the
73 % \KOMAScript{} manual, either the German \file{scrguide-de.pdf} or the English
74 % \file{scrguide-en.pdf}.
75 %
76 % \subsection{Features not yet in the user manuals}
77 %
78 % \DescribeCommand{\MakeCaptionLabelCase}
79 % \DescribeCommand{\MakeCaptionTextCase}
80 % These commands can be used to change the case (aka capitalization) of the
81 % caption label (without the \cs{captionformat}) and the caption text
82 % independently. For example, use
83 %\begin{verbatim}
84 %\let\MakeCaptionLabelCase\MakeUppercase
85 %\let\MakeCaptionTextCase\MakeTitlecase
86 %\end{verbatim}
87 % to automatically use upper case for the whole caption label, and the first
88 % letter of the caption text. You should not use it to change other formatting
89 % aspects like the font or the color!
90 %
91 % Note: This feature is currently not documented, because it could happen,
92 % that is will be removed again or replaced by an internal command and some
93 % option values. Or maybe we also support one command for every caption type.
94 %
95 %
96 % \MaybeStop{\PrintIndex}
97 %
98 %
99 % \section{Implementation of Floats}
100 %
101 % All this code is for the classes only and not for the \KOMAScript{} letter
102 % class, because letter classes usually do not provide floats. If you need
103 % letters with floats, just use \KOMAScript{} class \cls*{scrartcl} with
104 % \KOMAScript{} package \pkg*{scrletter}.
105 %
106 % \begin{macrocode}
107 %<*class&!letter>
108 % \end{macrocode}
109 %
110 % \subsection{Some macros and configurations for the options}
111 %
112 % We need some of the macros an settings already when processing the options.
113 %
114 % \begin{macro}{\@captionabovefalse,\@captionabovetrue,\if@captionabove}
115 % \changes{v2.8h}{2001/07/19}{added}
116 % \changes{v3.09}{2011/03/23}{moved before definition of options}
117 % \changes{v3.46}{2025/06/13}{kept for \pkg{caption} and \pkg{longtable} only}
118 % With new versions this switch is only used for captions inside
119 % \env{longtable}.
120 % \begin{macrocode}
121 %<*option>
122 \newif\if@captionabove\@captionabovefalse
123 % \end{macrocode}
124 % \end{macro}^^A \if@captionabove
125 %
126 % \begin{macro}{\@tablecaptionabovefalse,\@tablecaptionabovetrue,\if@tablecaptionabove}
127 % \changes{v2.8h}{2001/07/19}{added}
128 % \changes{v2.8k}{2001/08/15}{moved from \pkg*{typearea} into the classes}
129 % \changes{v2.98c}{2008/02/18}{moved before definition of options}
130 % \changes{v3.46}{2025/06/17}{removed}
131 % \end{macro}^^A \if@tablecaptionabove
132 % \begin{macro}{\@figurecaptionabovefalse,\@figurecaptionabovetrue,\if@figurecaptionabove}
133 % \changes{v3.09}{2011/03/23}{added}
134 % \changes{v3.46}{2025/06/13}{removed}
135 % \end{macro}^^A \if@figurecaptionabove
136 %
137 % \begin{macro}{\onelinecaptionsfalse,\onelinecaptionstrue,\ifonelinecaptions}
138 % \changes{v2.8q}{2001/11/17}{added}
139 % \changes{v2.98c}{2008/03/03}{earlier definition}
140 % \changes{v3.46}{2025/06/23}{\pkg{caption3} support added}
141 % The boolean is used to distinguish whether or not use a special handling of
142 % captions with one text line only. The name of the boolean is traditionally
143 % but nevertheless should seen as internal.
144 % \begin{macrocode}
145 \newif\ifonelinecaptions\onelinecaptionstrue
146 \AddToHook{package/caption3/after}{%
147 \DeclareCaptionSinglelinecheck{koma}{%
148 \ifonelinecaptions
149 \expandafter\@firstoftwo
150 \else
151 \expandafter\@secondoftwo
152 \fi}%
153 \SetCaptionDefault{singlelinecheck}{koma}%
154 }
155 % \end{macrocode}
156 % \end{macro}^^A \ifonelinecaptions
157 %
158 % \begin{macro}{\scap@pos}
159 % \changes{v2.8q}{2001/11/22}{added}
160 % \changes{v2.98c}{2008/03/03}{earlier definition}
161 % Environment \env{captionbeside} supports several horizontal placements for
162 % the caption beside the object:
163 % \begin{description}
164 % \item[\texttt{i}:] caption inner beside the object, which means left beside
165 % on odd pages and right beside on even pages (note: single-sided documents
166 % have only odd pages),
167 % \item[\texttt{l}:] caption left beside the object,
168 % \item[\texttt{o}:] caption outer beside the object, which means right beside
169 % on odd pages and left beside on even pages (note: single-sided documents
170 % have only odd pages),
171 % \item[\texttt{r}:] caption right beside the object.
172 % \end{description}
173 % The default is right beside.
174 % \begin{macrocode}
175 \newcommand*{\scap@pos}{r}
176 % \end{macrocode}
177 % \end{macro}^^A \scap@pos
178 %
179 % \begin{macro}{\scap@valign}
180 % \changes{v2.8q}{2001/11/22}{added}
181 % \changes{v2.98c}{2008/03/03}{earlier definition}
182 % Environment \env{captionbeside} support different vertical alignments
183 % for the object box:
184 % \begin{description}
185 % \item[\texttt{c}:] centered,
186 % \item[\texttt{b}:] bottom,
187 % \item[\texttt{t}:] top.
188 % \end{description}
189 % The default is bottom.
190 % \begin{macrocode}
191 \newcommand*{\scap@valign}{b}
192 % \end{macrocode}
193 % \end{macro}^^A \scap@valign
194 %
195 % \subsection{Options for the captions}
196 %
197 % \begin{option}{captions}
198 % \changes{v2.98c}{2008/02/18}{new \pkg*{keyval} option}
199 % \changes{v3.09}{2011/04/02}{new values \opt{heading}, \opt{signature},
200 % \opt{figureheading}, \opt{figuresignature}}
201 % \changes{v3.17}{2015/03/11}{using \cs{FamilyKeyState}}
202 % \changes{v3.17}{2015/03/11}{using internal value storage}
203 % \changes{v3.39}{2022/11/11}{initial dot removed from member argument of
204 % option storage commands}
205 % \changes{v3.46}{2025/06/13}{several values are processed by \pkg*{tocbasic}}
206 % This is the general option for the settings of captions. Because of
207 % compatibility with package \pkg{caption}, several of the macros, that are
208 % used to handle the values to the option, cannot be renamed and have to be
209 % used. This makes it difficult to change anything here. However, the
210 % currently provides values are:
211 % \begin{macrocode}
212 \KOMA@key{captions}{%
213 \KOMA@set@ncmdkey{captions}{@tempa}{%
214 % \end{macrocode}
215 % \begin{description}
216 % \item[\opt{=heading}:] change the \cs{caption} default to \cs{captionabove}.
217 % \end{description}
218 % \begin{macrocode}
219 {heading}{0},{above}{0},{top}{0},%
220 % \end{macrocode}
221 % \begin{description}
222 % \item[\opt{=signature}:] change the \cs{caption} default to \cs{captionbelow}.
223 % \end{description}
224 % \begin{macrocode}
225 {signature}{1},{below}{1},{bot}{1},{bottom}{1},%
226 % \end{macrocode}
227 % \begin{description}
228 % \item[\opt{=tableheading}:] change the \cs{caption} default inside
229 % \env{table} environments to \cs{captionabove}.
230 % \end{description}
231 % \begin{macrocode}
232 {tableheading}{2},%
233 {tableabove}{2},{abovetable}{2},{abovetabular}{2},{topattable}{2},%
234 % \end{macrocode}
235 % \begin{description}
236 % \item[\opt{=tablesignature}:] change the \cs{caption} default inside
237 % \env{table} environment to \cs{captionbelow}.
238 % \end{description}
239 % \begin{macrocode}
240 {tablesignature}{3},%
241 {tablebelow}{3},{belowtable}{3},{belowtabular}{3},{bottomattable}{3},%
242 % \end{macrocode}
243 % \begin{description}
244 % \item[\opt{=figureheading}:] change the \cs{caption} default inside
245 % \env{figure} environments to \cs{captionabove}.
246 % \end{description}
247 % \begin{macrocode}
248 {figureheading}{4},{figureabove}{4},{abovefigure}{4},{topatfigure}{4},%
249 % \end{macrocode}
250 % \begin{description}
251 % \item[\opt{=figuresignature}:] change the \cs{caption} default inside
252 % \env{figure} environment to \cs{captionbelow}.
253 % \end{description}
254 % \begin{macrocode}
255 {figuresignature}{5},{figurebelow}{5},{belowfigure}{5},{bottomatfigure}{5},%
256 % \end{macrocode}
257 % \begin{description}
258 % \item[\opt{=oneline}:] special treatment for one line captions.
259 % \end{description}
260 % \begin{macrocode}
261 {oneline}{6},%
262 % \end{macrocode}
263 % \begin{description}
264 % \item[\opt{=oneline}:] no special treatment for one line captions.
265 % \end{description}
266 % \begin{macrocode}
267 {nooneline}{7},%
268 % \end{macrocode}
269 % \begin{description}
270 % \item[\opt{=rightbeside}:] change horizontal \env{captionbeside} placement
271 % to right beside (see \cs{scap@pos} above).
272 % \end{description}
273 % \begin{macrocode}
274 {rightbeside}{8},{besideright}{8},%
275 % \end{macrocode}
276 % \begin{description}
277 % \item[\opt{=leftbeside}:] change horizontal \env{captionbeside} placement
278 % to left beside (see \cs{scap@pos} above).
279 % \end{description}
280 % \begin{macrocode}
281 {leftbeside}{9},{besideleft}{9},%
282 % \end{macrocode}
283 % \begin{description}
284 % \item[\opt{=innerbeside}:] change horizontal \env{captionbeside} placement
285 % to inner beside (see \cs{scap@pos} above).
286 % \end{description}
287 % \begin{macrocode}
288 {innerbeside}{10},{besideinner}{10},%
289 % \end{macrocode}
290 % \begin{description}
291 % \item[\opt{=outerbeside}:] change horizontal \env{captionbeside} placement
292 % to outer beside (see \cs{scap@pos} above).
293 % \end{description}
294 % \begin{macrocode}
295 {outerbeside}{11},{besideouter}{11},%
296 % \end{macrocode}
297 % \begin{description}
298 % \item[\opt{=topbeside}:] change vertical \env{captionbeside} alignment
299 % to top (see \cs{scap@valign} above).
300 % \end{description}
301 % \begin{macrocode}
302 {topbeside}{12},{besidetop}{12},%
303 % \end{macrocode}
304 % \begin{description}
305 % \item[\opt{=centeredbeside}:] change vertical \env{captionbeside} alignment
306 % to centered (see \cs{scap@valign} above).
307 % \end{description}
308 % \begin{macrocode}
309 {centeredbeside}{13},{besidecentered}{13},%
310 {middlebeside}{13},{besidemiddle}{13},%
311 % \end{macrocode}
312 % \begin{description}
313 % \item[\opt{=bottombeside}:] change vertical \env{captionbeside} alignment
314 % to bottom (see \cs{scap@valign} above).
315 % \end{description}
316 % \begin{macrocode}
317 {bottombeside}{14},{besidebottom}{14}%
318 }{#1}%
319 \ifx\FamilyKeyState\FamilyKeyStateProcessed
320 \ifcase \@tempa\relax % heading
321 \SetKeys[tocbasic]{captionabove}%
322 \KOMA@kav@remove{\KOMAClassFileName}{captions}{heading}%
323 \KOMA@kav@remove{\KOMAClassFileName}{captions}{signature}%
324 \KOMA@kav@add{\KOMAClassFileName}{captions}{heading}%
325 \or % signature
326 \SetKeys[tocbasic]{captionbelow}%
327 \KOMA@kav@remove{\KOMAClassFileName}{captions}{heading}%
328 \KOMA@kav@remove{\KOMAClassFileName}{captions}{signature}%
329 \KOMA@kav@add{\KOMAClassFileName}{captions}{signature}%
330 \or % tableheading
331 \SetKeys[tocbasic]{tablecaptionabove}
332 \KOMA@kav@remove{\KOMAClassFileName}{captions}{tableheading}%
333 \KOMA@kav@remove{\KOMAClassFileName}{captions}{tablesignature}%
334 \KOMA@kav@add{\KOMAClassFileName}{captions}{tableheading}%
335 \or % tablesignature
336 \SetKeys[tocbasic]{tablecaptionbelow}
337 \KOMA@kav@remove{\KOMAClassFileName}{captions}{tableheading}%
338 \KOMA@kav@remove{\KOMAClassFileName}{captions}{tablesignature}%
339 \KOMA@kav@add{\KOMAClassFileName}{captions}{tablesignature}%
340 \or % figureheading
341 \SetKeys[tocbasic]{figurecaptionabove}
342 \KOMA@kav@remove{\KOMAClassFileName}{captions}{figureheading}%
343 \KOMA@kav@remove{\KOMAClassFileName}{captions}{figuresignature}%
344 \KOMA@kav@add{\KOMAClassFileName}{captions}{figureheading}%
345 \or % figuresignature
346 \SetKeys[tocbasic]{figurecaptionbelow}
347 \KOMA@kav@remove{\KOMAClassFileName}{captions}{figureheading}%
348 \KOMA@kav@remove{\KOMAClassFileName}{captions}{figuresignature}%
349 \KOMA@kav@add{\KOMAClassFileName}{captions}{figuresignature}%
350 \or % oneline
351 \onelinecaptionstrue
352 \KOMA@kav@remove{\KOMAClassFileName}{captions}{oneline}%
353 \KOMA@kav@remove{\KOMAClassFileName}{captions}{nooneline}%
354 \KOMA@kav@add{\KOMAClassFileName}{captions}{oneline}%
355 \or % nooneline
356 \onelinecaptionsfalse
357 \KOMA@kav@remove{\KOMAClassFileName}{captions}{oneline}%
358 \KOMA@kav@remove{\KOMAClassFileName}{captions}{nooneline}%
359 \KOMA@kav@add{\KOMAClassFileName}{captions}{nooneline}%
360 \or % rightbeside
361 \renewcommand*{\scap@pos}{r}%
362 \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
363 \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
364 \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
365 \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
366 \KOMA@kav@add{\KOMAClassFileName}{captions}{rightbeside}%
367 \or % leftbeside
368 \renewcommand*{\scap@pos}{l}%
369 \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
370 \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
371 \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
372 \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
373 \KOMA@kav@add{\KOMAClassFileName}{captions}{leftbeside}%
374 \or % innerbeside
375 \renewcommand*{\scap@pos}{i}%
376 \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
377 \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
378 \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
379 \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
380 \KOMA@kav@add{\KOMAClassFileName}{captions}{innerbeside}%
381 \or % outerbeside
382 \renewcommand*{\scap@pos}{o}%
383 \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
384 \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
385 \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
386 \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
387 \KOMA@kav@add{\KOMAClassFileName}{captions}{outerbeside}%
388 \or % topbeside
389 \renewcommand*{\scap@valign}{t}%
390 \KOMA@kav@remove{\KOMAClassFileName}{captions}{topbeside}%
391 \KOMA@kav@remove{\KOMAClassFileName}{captions}{centeredbeside}%
392 \KOMA@kav@remove{\KOMAClassFileName}{captions}{bottombeside}%
393 \KOMA@kav@add{\KOMAClassFileName}{captions}{topbeside}%
394 \or % centeredbeside
395 \renewcommand*{\scap@valign}{c}%
396 \KOMA@kav@remove{\KOMAClassFileName}{captions}{topbeside}%
397 \KOMA@kav@remove{\KOMAClassFileName}{captions}{centeredbeside}%
398 \KOMA@kav@remove{\KOMAClassFileName}{captions}{bottombeside}%
399 \KOMA@kav@add{\KOMAClassFileName}{captions}{centeredbeside}%
400 \or % bottombeside
401 \renewcommand*{\scap@valign}{b}%
402 \KOMA@kav@remove{\KOMAClassFileName}{captions}{topbeside}%
403 \KOMA@kav@remove{\KOMAClassFileName}{captions}{centeredbeside}%
404 \KOMA@kav@remove{\KOMAClassFileName}{captions}{bottombeside}%
405 \KOMA@kav@add{\KOMAClassFileName}{captions}{bottombeside}%
406 \fi
407 \fi
408 }
409 \KOMA@kav@add{\KOMAClassFileName}{captions}{signature}
410 \KOMA@kav@add{\KOMAClassFileName}{captions}{oneline}
411 \KOMA@kav@add{\KOMAClassFileName}{captions}{rightbeside}
412 \KOMA@kav@add{\KOMAClassFileName}{captions}{bottombeside}
413 % \end{macrocode}
414 % \end{option}^^A captions
415 %
416 % \begin{option}{tablecaptionabove,tablecaptionbelow}
417 % \changes{v2.8h}{2001/07/19}{added}
418 % \changes{v2.8k}{2001/08/15}{moved from \pkg*{typearea} into the classes}
419 % \changes{v2.98c}{2008/02/18}{obsolete}
420 % \changes{v3.01a}{2008/11/20}{deprecated}
421 % \changes{v3.99}{2022/11/16}{not with \KOMAScript~4}
422 % Implementation of deprecated options by mapping them to corresponding
423 % \pkg*{keyval} options.
424 % \begin{macrocode}
425 %<*!v4>
426 \KOMA@DeclareDeprecatedOption{tablecaptionabove}{captions=tableheading}
427 \KOMA@DeclareDeprecatedOption{tablecaptionbelow}{captions=tablesignature}
428 %</!v4>
429 % \end{macrocode}
430 % \end{option}^^A tablecaptionabove,tablecaptionbelow
431 %
432 % \begin{option}{origlongtable}
433 % \changes{v2.8l}{2001/08/16}{added}
434 % If package \pkg{longtable} is loaded, the classes redefine table titles
435 % of that package. However, if the option has been set, this is prevented.
436 % \begin{macro}{\@komalongtablefalse,\@komalongtabletrue,\if@komalongtable}
437 % \changes{v2.8l}{2001/08/16}{added}
438 % The wanted behaviour is stored in a boolean.
439 % \begin{macrocode}
440 \newif\if@komalongtable\@komalongtabletrue
441 \DeclareOption{origlongtable}{\@komalongtablefalse}
442 % \end{macrocode}
443 % \end{macro}^^A \if@komalongtable
444 % \end{option}^^A origlongtable
445 %
446 % \begin{option}{onelinecaption,noonelinecaption}
447 % \changes{v2.8q}{2001/11/17}{new option}
448 % \changes{v2.98c}{2008/03/03}{obsolete}
449 % \changes{v2.98c}{2008/03/03}{extra code for \pkg{caption2} removed}
450 % \changes{v3.01a}{2008/11/20}{deprecated}
451 % \changes{v3.99}{2022/11/16}{not with \KOMAScript~4}
452 % Implementation of deprecated options by mapping them to corresponding
453 % \pkg*{keyval} options.
454 % \begin{macrocode}
455 %<*!v4>
456 \KOMA@DeclareDeprecatedOption{onelinecaption}{captions=oneline}
457 \KOMA@DeclareDeprecatedOption{noonelinecaption}{captions=nooneline}
458 %</!v4>
459 %</option>
460 % \end{macrocode}
461 % \end{option}^^A onelinecaption,noonelinecaption
462 %
463 %
464 % \subsection{Macros and commands for the captions}
465 %
466 % \changes{v2.2c}{1995/05/25}{support for CJK added}
467 % The initial feature for defining captions somehow different from the
468 % standard classes was a request of Werner Lember to add support for CJK
469 % languages. However not everything is changed. For example the usual lengths
470 % of the standard classes are still defined, but interpreted somehow different.
471 %
472 % \begin{length}{\abovecaptionskip,\belowcaptionskip}
473 % The distance above and below a caption. The default for captions below the
474 % object is 10\,pt above the caption and 0 below. Note: For captions above
475 % the object the lengths are switched: \len{abovecaptionskip} is used
476 % \emph{below} the caption and \len{belowcaptionskip} is used \emph{above}
477 % the caption then.
478 % \begin{macrocode}
479 %<*body>
480 \newlength{\abovecaptionskip}
481 \newlength{\belowcaptionskip}
482 \setlength{\abovecaptionskip}{10\p@}
483 \setlength{\belowcaptionskip}{0\p@}
484 % \end{macrocode}
485 % \end{length}^^A \abovecaptionskip,\belowcaptionskip
486 % \begin{command}{\captionformat}
487 % \changes{v2.3c}{1995/08/06}{added}
488 % \changes{v3.46}{2025/06/23}{\pkg*{caption3} support added}
489 % Separator between label (with number) an text only.
490 % \begin{macrocode}
491 \newcommand*{\captionformat}{:\ }
492 \AddToHook{package/caption3/after}{%
493 \DeclareCaptionLabelSeparator{koma}{\captionformat}%
494 \SetCaptionDefault{labelseparator}{koma}%
495 }
496 % \end{macrocode}
497 % \end{command}^^A \captionformat
498 % \begin{command}{\captionabove,\captionbelow}
499 % \changes{v2.8h}{2001/07/19}{added}
500 % \changes{v3.46}{2025/06/16}{moved to \pkg*{tocbasic}}
501 % \end{command}^^A \captionabove,\captionbelow
502 % \begin{macro}{\scr@caption}
503 % \changes{v2.8h}{2001/07/19}{added}
504 % \changes{v3.46}{2025/06/13}{removed to deactivate \pkg{caption} patches}
505 % \end{macro}^^A \scr@caption
506 %
507 %
508 % \begin{environment}{captionbeside}
509 % \changes{v2.8q}{2001/11/22}{added}
510 % Placing captions above or below the object inside a float is easy. But to
511 % place it beside the object an additional environment is needed. This has to
512 % collect the object (environment body) into a box and then print it side by
513 % side with a second box with the caption. Note: This cannot work with
514 % tables of package \pkg{longtable} or \pkg{supertabular} or similar packages.
515 % \begin{quote}\raggedright
516 % |\begin{captionbeside}|\oarg{list
517 % entry}\marg{caption}\oarg{position}\oarg{with}\oarg{offset}|*|\\
518 % \dots\\
519 % |\end{captionbeside}|
520 % \end{quote}
521 % Note: The asterisk is optional and changes the meaning of \meta{offset}.
522 % \begin{macro}{\scap@caption}
523 % \changes{v2.8q}{2001/11/22}{added}
524 % The \meta{caption} is locally stored into helper macro \cs{scap@caption}.
525 % \begin{macrocode}
526 \newcommand*{\scap@caption}{}
527 % \end{macrocode}
528 % \end{macro}^^A \scap@caption
529 % \begin{macro}{\scap@width}
530 % \changes{v2.8q}{2001/11/22}{added}
531 % The optional \meta{width}, which is the width of the whole environment
532 % inclusive caption, is locally stored into helper macro \cs{scap@width}. The
533 % default is the while line width.
534 % \begin{macrocode}
535 \newcommand*{\scap@width}{\linewidth}
536 % \end{macrocode}
537 % \end{macro}^^A \scap@width
538 % \begin{macro}{\scap@move}
539 % \changes{v2.8q}{2001/11/22}{added}
540 % If \cs{scap@width} is not the line width, the environment is horizontal
541 % centered by default. But if \meta{offset} is used, this is used as a
542 % distance from the left margin. This is locally stored into helper macro
543 % \cs{scap@move}.
544 % \begin{macrocode}
545 \newcommand*{\scap@move}{\z@}
546 % \end{macrocode}
547 % \end{macro}^^A \scap@move
548 % \begin{macro}{\scap@altfalse,\scap@alttrue,\ifscap@alt}
549 % \changes{v2.8q}{2001/11/22}{added}
550 % The boolean switch \cs{ifscap@alt} is used to decide if in twoside mode the
551 % movement of \cs{scap@move} has to be done from the left or the right margin
552 % and to left or to the right.
553 % \begin{macrocode}
554 \newif\ifscap@alt
555 % \end{macrocode}
556 % \end{macro}^^A \ifscap@alt
557 % \begin{macro}{\scap@currentlabel}
558 % \changes{v2.8q}{2001/11/24}{added}
559 % \begin{macro}{\scap@currentcounter,\scap@currentlabelname,\scap@currentHref}
560 % \changes{v3.38}{2022/07/30}{added}
561 % Because of using \cs{caption} inside a box and inside an environment, a
562 % label after the \env{captionbeside} environment usually would not reference
563 % the caption number. To preserve this after the end of the
564 % \env{captionbeside} the current label and counter are locally stored into
565 % global \cs{scap@currentlabel} and restored after the end of the environment
566 % using \cs{aftergroup}. Note: You can have only one \cs{label} inside!
567 % \begin{macrocode}
568 \newcommand*{\scap@currentlabel}{}
569 \newcommand*{\scap@currentlabelname}{}
570 \newcommand*{\scap@currentHref}{}
571 % \end{macrocode}
572 % \end{macro}^^A \scap@currentcounter … \scap@currentHref
573 % \end{macro}^^A \scap@currentlabel
574 % \begin{macro}{\@@@captionbeside,\@@captionbeside,\@captionbeside}
575 % \changes{v2.8q}{2001/11/22}{added}
576 % \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by \cs{kernel@ifnextchar}}
577 % \begin{macro}{\@@@@captionbeside}
578 % \changes{v2.8q}{2001/11/22}{added}
579 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
580 % To handle all the optional arguments and the optional star at the end,
581 % several helper macros are needed (because we currently do not use \pkg{xparse}).
582 % \begin{macrocode}
583 \newcommand*{\@captionbeside}{}
584 \long\def\@captionbeside[#1]#2{%
585 \kernel@ifnextchar [%]
586 {\@@captionbeside[{#1}]{#2}}
587 {\c@pti@nb@sid@[{#1}]{#2}}%
588 }
589 \newcommand*{\@@captionbeside}{}
590 \long\def\@@captionbeside[#1]#2[#3]{%
591 \def\scap@pos{#3}%
592 \kernel@ifnextchar [%]
593 {\@@@captionbeside[{#1}]{#2}}
594 {\c@pti@nb@sid@[{#1}]{#2}}%
595 }
596 \newcommand*{\@@@captionbeside}{}
597 \long\def\@@@captionbeside[#1]#2[#3]{%
598 \def\scap@width{#3}%
599 \kernel@ifnextchar [%]
600 {\@@@@captionbeside[{#1}]{#2}}
601 {\setlength{\@tempdima}{#3}%
602 \addtolength{\@tempdima}{-\linewidth}%
603 \setlength{\@tempdima}{-.5\@tempdima}%
604 \edef\scap@move{\the\@tempdima}%
605 \c@pti@nb@sid@[{#1}]{#2}}%
606 }
607 \newcommand*{\@@@@captionbeside}{}
608 \long\def\@@@@captionbeside[#1]#2[#3]{%
609 \def\scap@move{#3}%
610 \kernel@ifstar
611 {\scap@alttrue\c@pti@nb@sid@[{#1}]{#2}}
612 {\scap@altfalse\c@pti@nb@sid@[{#1}]{#2}}%
613 }
614 % \end{macrocode}
615 % \end{macro}^^A \@@@@captionbeside
616 % \end{macro}^^A \@@@captionbeside … \@captionbeside
617 % \begin{macro}{\c@pti@nb@sid@b@x}
618 % \changes{v2.8q}{2001/11/22}{added}
619 % We also use our own box register to collect the environment body.
620 % \begin{macrocode}
621 \newbox\c@pti@nb@sid@b@x
622 % \end{macrocode}
623 % \end{macro}
624 % \begin{macro}{\c@pti@nb@sid@}
625 % \changes{v2.8q}{2001/11/22}{added}
626 % \changes{v2.98c}{2008/03/11}{vertical alignment fixed}
627 % \changes{v3.07a}{2010/11/04}{vertical alignment \texttt{t} and \texttt{b}
628 % fixed}
629 % \changes{v3.99}{2022/11/10}{vertical alignment fixed}
630 % This is the real beginning of the environment. After collecting all the
631 % arguments into local macros. Until version 4 the vertical alignment was
632 % totally broken at least, if font element \fnt{caption} changes font
633 % size. From version 4 we try to take care on this. However, the current
634 % solution could still fail, if the first resp. last line of content of the
635 % environment changes the font size.
636 % \begin{macrocode}
637 \newcommand{\c@pti@nb@sid@}{}
638 %<*!v4>
639 \long\def\c@pti@nb@sid@[#1]#2{%
640 \def\scap@caption{%
641 \if c\scap@valign
642 \setlength{\abovecaptionskip}{\z@}%
643 \else \if t\scap@valign
644 \setlength{\abovecaptionskip}{-\ht\strutbox}%
645 \else \if b\scap@valign
646 \setlength{\abovecaptionskip}{\z@}%
647 \fi
648 \fi
649 \fi
650 \setlength{\belowcaptionskip}{-\dp\strutbox}%
651 \captionbelow[{#1}]{#2}%
652 }%
653 \begin{lrbox}{\c@pti@nb@sid@b@x}%
654 }
655 %</!v4>
656 %<*v4>
657 \long\def\c@pti@nb@sid@[#1]#2{%
658 \def\scap@caption{%
659 \abovecaptionskip\z@
660 \belowcaptionskip\z@
661 \if t\scap@valign
662 {%
663 \usekomafont{caption}{%
664 \global\@tempdima\ht\strutbox
665 }%
666 }%
667 \setlength{\abovecaptionskip}{-\@tempdima}%
668 \fi
669 \if b\scap@valign
670 {%
671 \usekomafont{caption}{%
672 \global\@tempdima\dp\strutbox
673 }%
674 }%
675 \setlength{\belowcaptionskip}{\dimexpr\dp\strutbox-2\@tempdima\relax}%
676 \fi
677 \captionbelow[{#1}]{#2}%
678 }%
679 \begin{lrbox}{\c@pti@nb@sid@b@x}%
680 }
681 %</v4>
682 % \end{macrocode}
683 % \end{macro}^^A \c@pti@nb@sid@
684 % Now we can use all of the helper macros to begin the environment. We use
685 % \LaTeX{} kernel macro \cs{@dblarg} to define an argument with first
686 % optional argument defaults to mandatory second argument.
687 % \begin{macrocode}
688 \newenvironment*{captionbeside}{%
689 \@dblarg\@captionbeside
690 }{%
691 % \end{macrocode}
692 % This was easy (because of using all the helper macros), but the end of the
693 % environment isn't. Here we do all the calculations for printing.
694 % \changes{v2.9a}{2002/06/27}{\cs{ifthispageodd} replaced by \cs{if@thispageodd}}
695 % \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
696 % \begin{macrocode}
697 \end{lrbox}%
698 \settowidth{\@tempdima}{\usebox\c@pti@nb@sid@b@x}%
699 \setlength{\@tempdimb}{\scap@width}%
700 \addtolength{\@tempdimb}{-\@tempdima}%
701 \addtolength{\@tempdimb}{-\columnsep}%
702 \ifdim \@tempdimb<2em
703 \ClassWarning{\KOMAClassName}{%
704 caption beside will be very, very small.\MessageBreak
705 In most cases this will result in overfull and\MessageBreak
706 underfull \string\hbox\space messages%
707 }%
708 \fi
709 \onelinecaptionsfalse
710 \setcapwidth[r]{\@tempdimb}%
711 \let\@tempa\scap@pos
712 \setlength{\@tempdimc}{\scap@move}%
713 \if i\scap@pos\def\@tempa{l}\fi
714 \if o\scap@pos\def\@tempa{r}\fi
715 \if@twoside
716 \Ifthispageodd{}{%
717 \if o\scap@pos\def\@tempa{l}\fi
718 \if i\scap@pos\def\@tempa{r}\fi
719 \ifscap@alt
720 \addtolength{\@tempdimc}{\scap@width}%
721 \addtolength{\@tempdimc}{-\linewidth}%
722 \setlength{\@tempdimc}{-\@tempdimc}%
723 \fi
724 }%
725 \fi
726 \hspace*{\@tempdimc}%
727 % \end{macrocode}
728 % \changes{v2.9p}{2003/12/10}{\cs{@temdima} replaced by
729 % \cs{wd}\cs{c@pti@nb@sid@b@x}, because \cs{@temdima} would be changed}
730 % \changes{v3.38}{2022/07/20}{using \cs{scap@currentcounter}}
731 % \changes{v3.38}{2022/07/20}{using \cs{scap@currentlabelname}}
732 % \changes{v3.38}{2022/07/20}{using \cs{scap@currentHref}}
733 % \begin{macrocode}
734 \if l\@tempa
735 \rlap{%
736 \parbox[\scap@valign]{\@tempdimb}{\scap@caption
737 \global\let\scap@currentlabel\@currentlabel
738 \global\let\scap@currentcounter\@currentcounter
739 \global\let\scap@currentlabelname\@currentlabelname
740 \global\let\scap@currentHref\@currentHref
741 }%
742 \nobreak\hskip\columnsep
743 \parbox[\scap@valign]{\wd\c@pti@nb@sid@b@x}{\usebox\c@pti@nb@sid@b@x}%
744 }%
745 \else
746 \rlap{%
747 \parbox[\scap@valign]{\wd\c@pti@nb@sid@b@x}{\usebox\c@pti@nb@sid@b@x}%
748 \nobreak\hskip\columnsep
749 \parbox[\scap@valign]{\@tempdimb}{\scap@caption
750 \global\let\scap@currentlabel\@currentlabel
751 \global\let\scap@currentcounter\@currentcounter
752 \global\let\scap@currentlabelname\@currentlabelname
753 \global\let\scap@currentHref\@currentHref
754 }%
755 }%
756 \fi
757 \par
758 \aftergroup\let\aftergroup\@currentlabel\aftergroup\scap@currentlabel
759 \aftergroup\let\aftergroup\@currentcounter\aftergroup\scap@currentcounter
760 \aftergroup\let\aftergroup\@currentlabelname\aftergroup\scap@currentlabelname
761 \aftergroup\let\aftergroup\@currentHref\aftergroup\scap@currentHref
762 }
763 % \end{macrocode}
764 % \end{environment}^^A captionbeside
765 %
766 %
767 % \begin{fontelement}{caption,captionlabel}
768 % We need two font elements for the caption at whole and the label part only.
769 % \begin{macro}{\capfont,\caplabelfont}
770 % \changes{v2.8c}{2001/06/29}{\cs{normalcolor} added}
771 % Originally two user macros has been used to change the fonts. To stay
772 % compatible with old \KOMAScript{} and also i.e. with package \pkg{caption},
773 % we still define \cs{capfont} and \cs{caplabelfont} as internal storage of
774 % the font elements. But already from \KOMAScript{} version 2.8c these should
775 % be interpreted as internal macros.
776 % \begin{macrocode}
777 \newcommand*\capfont{\normalfont\normalcolor}
778 \newcommand*\caplabelfont{\normalfont\normalcolor}
779 % \end{macrocode}
780 % \end{macro}^^A \capfont,\caplabelfont
781 % \begin{macro}{\scr@fnt@caption,\scr@fnt@captionlabel}
782 % \changes{v2.8o}{2001/09/14}{added}
783 % \changes{v3.46}{2025/06/23}{\pkg{caption3} support added}
784 % Because of that non-default for the internal storage the font elements
785 % have to be defined \emph{manually} instead of using \cs{newkomafont}.
786 % \begin{macrocode}
787 \newcommand*{\scr@fnt@caption}{\capfont}
788 \newcommand*{\scr@fnt@captionlabel}{\caplabelfont}
789 \AddToHook{package/caption3/after}{%
790 \DeclareCaptionFont{scr@font}{\scr@fnt@caption}%
791 \DeclareCaptionFont{scr@labelfont}{\scr@fnt@captionlabel}%
792 \SetCaptionDefault{font}{scr@font}%
793 \SetCaptionDefault{labelfont}{scr@labelfont}%
794 }
795 % \end{macrocode}
796 % \end{macro}^^A \scr@fnt@caption,\scr@fnt@captionlabel
797 % \end{fontelement}^^A caption,captionlabel
798 %
799 % \begin{macro}{\@makecaption}
800 % \changes{v2.3a}{1995/07/08}{using \cs{sbox} instead of \cs{setbox}}
801 % \changes{v2.3a}{1995/07/08}{using \cs{@minipagefalse}}
802 % \changes{v2.3f}{1995/12/09}{using same font switching for long and short captions}
803 % \changes{v2.5g}{1999/10/09}{supporting partial hanging captions}
804 % \begin{macro}{\dofullc@pfalse,\dofullc@ptrue,\ifdofullc@p}
805 % The boolean switch \cs{ifdofullc@p} is true for caption texts, that should
806 % be full hanging (behind the label part), which is the default.
807 % \begin{macrocode}
808 \newif\ifdofullc@p
809 \dofullc@ptrue
810 % \end{macrocode}
811 % \end{macro}^^A \ifdofullc@p
812 % \begin{macro}{\if@capbreak}
813 % \changes{v2.8j}{2001/07/30}{added}
814 % The boolean switch \cs{if@capbreak} is true, if the label should be followed
815 % by a line break, which is not the case by default.
816 % \begin{macrocode}
817 \newif\if@capbreak
818 \@capbreakfalse
819 % \end{macrocode}
820 % \end{macro}^^A \@capbreakfalse
821 % \begin{command}{\setcapindent}
822 % \begin{macro}{\@@setcaptindent,\@setcapindent}
823 % \changes{v2.8j}{2001/07/30}{using \cs{if@capbreak}}
824 % \changes{v2.8l}{2001/08/17}{using \cs{edef}\cs{cap@indent} instead of
825 % \cs{def}\cs{cap@indent}}
826 % \changes{v2.8q}{2001/11/17}{redefined after loading \pkg{caption2}}
827 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
828 % \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
829 % \changes{v3.46}{2025/06/23}{removed}
830 % \end{macro}^^A \@@setcaptindent,\@setcapindent
831 % \changes{v3.46}{2025/06/23}{re-written to add support for the \pkg{caption}
832 % package}
833 % \changes{v3.46}{2025/06/25}{undocumented feature for indent greater than
834 % \len{hsize} removed}
835 % The user can configure the indent using:
836 % \begin{quote}
837 % \cs{setcapindent}*\marg{indent}
838 % \end{quote}
839 % The optional asterisk activates a line break between the label and the
840 % text. The \meta{indent} is always an indent of the text from the left. A
841 % local dimension assignment is done to report errors here and not at
842 % usage of \cs{cap@indent}.
843 % \begin{macrocode}
844 %<@@=scrkernel>
845 \ExplSyntaxOn
846 \NewDocumentCommand { \setcapindent } { s m }
847 {
848 \IfBooleanTF {#1}
849 {
850 \cs_set:Npe \cap@indent { \dim_eval:n { #2 } }
851 \@capbreaktrue
852 }
853 {
854 \cs_set:Npe \cap@indent { \dim_eval:n { #2 } }
855 \@capbreakfalse
856 }
857 \dofullc@pfalse
858 \@@_at_caption_package:n
859 {
860 \exp_args:No \msg_warning:nnee { \KOMAClassName }
861 { using-caption }
862 { \token_to_str:N\setcapindent\IfBooleanT{#1}*{#2} }
863 {
864 \token_to_str:N \captionsetup
865 { indent=\ifdim\cap@indent<\z@\z@\else\cap@indent\fi }
866 }
867 \captionsetup { indent=\ifdim\cap@indent<\z@\z@\else\cap@indent\fi }
868 }
869 }
870 \ExplSyntaxOff
871 %<@@=>
872 % \end{macrocode}
873 % \end{command}^^A \setcapindent
874 % \begin{command}{\setcaphanging}
875 % \changes{v2.8q}{2001/11/17}{redefined after loading \pkg{caption2}}
876 % \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
877 % Alternatively the user can select the full hanging printing.
878 % \begin{macrocode}
879 \newcommand*{\setcaphanging}{\dofullc@ptrue\@capbreakfalse}
880 % \end{macrocode}
881 % \end{command}
882 % \begin{command}{\captionnopagebreak}
883 % \changes{v3.41}{2023/05/10}{added}
884 % \changes{v3.46}{2025/06/13}{use socket to inject additional code}
885 % Can be redefined by users to allow page breaks between content and caption.
886 % \begin{macrocode}
887 \expandafter\ifnum\scr@v@is@ge{3.41}%
888 \newcommand*{\captionnopagebreak}{\nopagebreak}
889 \else
890 \newcommand*{\captionnopagebreak}{}
891 \fi
892 \newcommand*{\@abovecaptionbreak}{}
893 \newcommand*{\@belowcaptionbreak}{}
894 \let\@belowcaptionbreak\captionnopagebreak
895 \IfFormatAtLeastTF{2023/11/01}{%
896 \NewSocketPlug{tocbasic/swapskip/after}{swapbreak}{%
897 \let\@abovecaptionbreak\captionnopagebreak
898 \let\@belowcaptionbreak\relax
899 }%
900 \AssignSocketPlug{tocbasic/swapskip/after}{swapbreak}%
901 }{%
902 \AddToHook{tocbasic/swapskip/after}{&
903 \let\@abovecaptionbreak\captionnopagebreak
904 \let\@belowcaptionbreak\relax
905 }%
906 }
907 % \end{macrocode}
908 % \end{command}
909 % Now, we have all to define \cs{@makecaption} as needed by the \LaTeX{}
910 % kernel.
911 % \changes{v2.5g}{1999/10/09}{using \cs{newcommand}}
912 % \changes{v2.8h}{2001/07/19}{support for headings and signatures}
913 % \changes{v2.8j}{2001/07/30}{using \cs{@@makecaption}}
914 % \changes{v2.8q}{2001/11/17}{special treatment of one line captions is
915 % optional}
916 % \changes{v2.8q}{2001/11/17}{caption width can be limited}
917 % \changes{v3.41}{2023/05/10}{no page break below caption above or above
918 % caption below content}
919 % \changes{v3.46}{2025/06/13}{moved caption above/below logic to
920 % \pkg*{tocbasic}}
921 % \begin{macrocode}
922 \newcommand{\@makecaption}[2]{%
923 \@abovecaptionbreak\vskip\abovecaptionskip\@abovecaptionbreak
924 \@@makecaption\@firstofone{#1}{#2}%
925 \@belowcaptionbreak\vskip\belowcaptionskip\@belowcaptionbreak
926 }
927 % \end{macrocode}
928 % \begin{macro}{\cap@width,\cap@left,\cap@right}
929 % \changes{v2.8q}{2001/11/17}{added}
930 % Multi line captions can printed with a reduced with. If the width is reduced
931 % the left an right margin can be changed. The defaults are centering.
932 % \begin{macrocode}
933 \newcommand*{\cap@width}{\hsize}
934 \newcommand*{\cap@left}{\hfill}
935 \newcommand*{\cap@right}{\hfill}
936 % \end{macrocode}
937 % \end{macro}^^A \cap@width,\cap@left,\cap@right
938 % \begin{command}{\setcapwidth}
939 % \changes{v2.8q}{2001/11/17}{added}
940 % \changes{v2.9a}{2002/06/27}{\cs{ifthispageodd} replaced by
941 % \cs{if@thispageodd}}
942 % \changes{v2.97}{2007/02/27}{minimum width for captions is 0\,pt}
943 % \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
944 % \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
945 % \changes{v3.46}{2025/06/17}{re-written to add support for the \pkg{caption}
946 % package}
947 % The user command:
948 % \begin{quote}
949 % \cs{setcapwidth}\oarg{alignment}\marg{width}
950 % \end{quote}
951 % is one choice to set \cs{cap@width} to \meta{width}. The optional
952 % \meta{alignment} (as usual |l|, |r|, |o|, or |i|) also changes \cs{cap@left}
953 % and \cs{cap@right}.
954 % \begin{macrocode}
955 %<@@=scrkernel>
956 \ExplSyntaxOn
957 \prop_put:Non \g_msg_module_type_prop { \KOMAClassName } { Class }
958 \exp_args:No \msg_new:nnn { \KOMAClassName }
959 { minimum-value-needed }
960 {
961 You've~tried~#2~\msg_line_context:,~
962 but~values~less~than~#1~are~not~allowed.~
963 Using~#1~instead.
964 }
965 \exp_args:No \msg_new:nnn { \KOMAClassName }
966 { caption-not-support-setcapwidth-option }
967 {
968 Ignoring~command~
969 \token_to_str:N \setcapwidth [#1]{...}\\
970 because~the~caption~package~is~being\\
971 used~\msg_line_context:.
972 }
973 \exp_args:No \msg_new:nnn { \KOMAClassName }
974 { caption-not-support-setcapdynwidth }
975 {
976 Ignoring~\token_to_str:N \setcapdynwidth \c_space_token
977 because~the~caption~package~is~being~used~\msg_line_context:.
978 }
979 \exp_args:No \msg_new:nnnn { \KOMAClassName }
980 { setcaption-unknown-option }
981 { unknown~optional~position~argument~[#1]~\msg_line_context: }
982 {
983 Only~ONE~of~c,~l,~r,~i,~o~is~allowed~as~optional~argument~to~
984 \token_to_str:N \setcapwidth \c_space_tl and~
985 \token_to_str:N \setcapdynwidth \c_space_tl \msg_line_context:.
986 }
987 \exp_args:No \msg_new:nnn { \KOMAClassName }
988 { using-caption }
989 {
990 Mapping~of\\
991 \c_space_tl #1\\
992 to\\
993 \c_space_tl #2\\
994 because~the~caption~package~is~being~used.\\
995 When~using~the~caption~package,~it~is~recommended\\
996 to~use~the~options~of~this~package~directly~instead\\
997 of~the~KOMA-Script~setting~\msg_line_context:.
998 }
999 \NewDocumentCommand { \setcapwidth } { om }
1000 {
1001 \dim_compare:nNnTF { #2 } < { \c_zero_dim }
1002 {
1003 \exp_args:No \msg_warning:nnne { \KOMAClassName }
1004 { minimum-value-needed } { 0pt } { \dim_eval:n { #2 } }
1005 \def\cap@width{0pt}
1006 }
1007 {
1008 \cs_set:Npe \cap@width { \dim_eval:n { #2 } }
1009 }
1010 \IfPackageLoadedF { caption } { \@@_set_cap_left_right:n { #1 } }
1011 \@@_at_caption_package:n
1012 {
1013 \IfValueTF { #1 }
1014 {
1015 \exp_args:No \msg_warning:nne { \KOMAClassName }
1016 { caption-not-support-setcapwidth-option } { #1 }
1017 }
1018 {
1019 \exp_args:No \msg_warning:nnne { \KOMAClassName }
1020 { using-caption }
1021 { \setcapwidth{#2} }
1022 { \token_to_str:N \captionsetup { width=\cap@width } }
1023 \captionsetup { width=\cap@width }
1024 }
1025 }
1026 }
1027 \cs_new:Nn \@@_at_caption_package:n
1028 {
1029 \IfPackageLoadedTF { caption3 }
1030 {
1031 \cs_if_eq:NNTF \AtCaptionPackage \@notprerr
1032 { #1 }
1033 { \AtCaptionPackage { #1 } }
1034 }
1035 {
1036 \hook_gput_code:nnn { pkg / caption3 / after } { \KOMAClassName }
1037 { \AtCaptionPackage { #1 } }
1038 }
1039 }
1040 \@@_at_caption_package:n
1041 {
1042 \cs_set:Nn \@@_at_caption_package:n { ##1 }
1043 }
1044 \cs_new:Nn \@@_set_cap_left_right:n
1045 {
1046 \str_case:enF { #1 }
1047 {
1048 { c } { \cs_set:Npn \cap@margin { \cs_set_eq:NN \cap@left \hfill
1049 \cs_set_eq:NN \cap@right \hfill } }
1050 { l } { \cs_set:Npn \cap@margin { \cs_set_eq:NN \cap@left \relax
1051 \cs_set_eq:NN \cap@right \hfill } }
1052 { r } { \cs_set:Npn \cap@margin { \cs_set_eq:NN \cap@left \hfill
1053 \cs_set_eq:NN \cap@right \relax } }
1054 { i } { \cs_set:Npn \cap@margin { \cs_set_eq:NN \cap@left \relax
1055 \cs_set_eq:NN \cap@right \hfill
1056 \if@twoside
1057 \Ifthispageodd {} {
1058 \cs_set_eq:NN \cap@left \hfill
1059 \cs_set_eq:NN \cap@right \relax
1060 }
1061 \fi } }
1062 { o } { \cs_set:Npn \cap@margin { \cs_set_eq:NN \cap@left \hfill
1063 \cs_set_eq:NN \cap@right \relax
1064 \if@twoside
1065 \Ifthispageodd {
1066 \cs_set_eq:NN \cap@left \relax
1067 \cs_set_eq:NN \cap@right \hfill
1068 } { }
1069 \fi } }
1070 }
1071 {
1072 \IfValueT{ #1 }
1073 {
1074 \exp_args:No \msg_error:nnn { \KOMAClassName }
1075 { setcaption-unknown-option } { #1 }
1076 }
1077 }
1078 }
1079 % \end{macrocode}
1080 % \end{command}^^A \setcapwidth
1081 % \begin{command}{\setcapdynwidth}
1082 % \changes{v3.20}{2016/03/31}{added}
1083 % Ulrike Fischer requested for an alternative, that does not behave like
1084 % \cs{setlength} and therefore sets the length already at usage of
1085 % \cs{setcapwidth} but at usage of \cs{cap@width}. This is
1086 % \cs{setcapdynwidth}. But in this case mistakes can result in errors while
1087 % usage of \cs{cap@width} too.
1088 % \begin{macrocode}
1089 \NewDocumentCommand { \setcapdynwidth } { om }
1090 {
1091 \IfPackageLoadedTF { caption }
1092 {
1093 \exp_args:No \msg_warning:nn { \KOMAClassName }
1094 { caption-not-support-setcapdynwidth }
1095 }
1096 {
1097 \cs_set:Npn \cap@width { #2 }
1098 \@@_set_cap_left_right:n { #1 }
1099 }
1100 }
1101 \ExplSyntaxOff
1102 % \end{macrocode}
1103 % \end{command}^^A \setcapdynwidth
1104 %
1105 % \begin{macro}{\cap@margin}
1106 % \changes{v2.8q}{2001/11/17}{added}
1107 % \cs{cap@margin} is used to recalculate \cs{cap@left} and \cs{cap@right}
1108 % inside \cs{@@makecaption}, if the margins has been set using
1109 % \cs{setcapmargin}. Default is no such action.
1110 % \begin{macrocode}
1111 \newcommand*{\cap@margin}{}
1112 \let\cap@margin=\relax%
1113 % \end{macrocode}
1114 % \end{macro}^^A \cap@margin
1115 % \begin{command}{\setcapmargin}
1116 % \changes{v2.8q}{2001/11/17}{neu}
1117 % \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
1118 % \begin{macro}{\@@setcapmargin,\@setcapmargin}
1119 % \changes{v2.8q}{2001/11/17}{added}
1120 % \changes{v2.9a}{2002/06/27}{\cs{ifthispageodd} replaced by
1121 % \cs{if@thispageodd}}
1122 % \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
1123 % \changes{v3.34}{2021/03/22}{special treatment for \pkg{caption2} removed}
1124 % \changes{v3.46}{2025/06/25}{removed}
1125 % \end{macro}
1126 % \changes{v3.46}{2025/06/23}{re-written to add support for the \pkg{caption}
1127 % package}
1128 % Instead of setting of the width of the caption, the left and right margin
1129 % can be set. The star variant switch left and right depending on odd or even
1130 % side in two side mode.
1131 % \begin{macrocode}
1132 \ExplSyntaxOn
1133 \NewDocumentCommand {\setcapmargin} { s O{#3} m }
1134 {
1135 \IfBooleanTF {#1}
1136 {
1137 \cs_set:Npn \cap@margin
1138 {
1139 \onelinecaptionsfalse
1140 \cs_set:Npe \cap@width { \dim_eval:n { \hsize - #2 - #3 } }
1141 \if@twoside
1142 \Ifthispageodd
1143 {
1144 \cs_set:Npn \cap@left { \hspace*{#2} }
1145 \cs_set:Npn \cap@right { \hspace*{#3} }
1146 }
1147 {
1148 \cs_set:Npn \cap@left { \hspace*{#3} }
1149 \cs_set:Npn \cap@right { \hspace*{#2} }
1150 }
1151 \else
1152 \cs_set:Npn \cap@left { \hspace*{#2} }
1153 \cs_set:Npn \cap@right { \hspace*{#3} }
1154 \fi
1155 }
1156 \@@_at_caption_package:n
1157 {
1158 \exp_args:No \msg_warning:nnne { \KOMAClassName }
1159 { using-caption }
1160 { \setcapmargin*[#2]{#3} }
1161 { \token_to_str:N \captionsetup { twoside, slc=0, margin={#2,#3} } }
1162 \captionsetup{ twoside, slc=0, margin={#2,#3} }
1163 }
1164 }
1165 {
1166 \cs_set:Npn \cap@margin
1167 {
1168 \onelinecaptionsfalse
1169 \cs_set:Npe \cap@width { \dim_eval:n { \hsize - #2 - #3 } }
1170 \cs_set:Npn \cap@left { \hspace*{#2} }
1171 \cs_set:Npn \cap@right { \hspace*{#3} }
1172 }
1173 \@@_at_caption_package:n
1174 {
1175 \exp_args:No \msg_warning:nnne { \KOMAClassName }
1176 { using-caption }
1177 { \setcapmargin[#2]{#3} }
1178 { \token_to_str:N \captionsetup { oneside, slc=0, margin={#2,#3} } }
1179 \captionsetup{oneside,slc=0,margin={#2,#3}}
1180 }
1181 }
1182 }
1183 \ExplSyntaxOff
1184 %<@@=>
1185 % \end{macrocode}
1186 % \end{command}^^A \setcapmargin
1187 % \begin{macro}{\@@makecaption}
1188 % The main job is done by \cs{@@makecaption}. It has an additional first
1189 % argument, that has to be either \cs{@gobble} or \cs{@firstofone}. This is
1190 % used to either set a label or not. This is needed for captions of
1191 % \pkg{longtable}.
1192 % \changes{v2.8q}{2002/05/17}{avoid double increase of footnote number}
1193 % \changes{v2.95}{2004/01/30}{fixing vertical skips also with \pkg{float}}
1194 % \changes{v2.95a}{2006/07/13}{fixing vertical skips with \pkg{color}}
1195 % \changes{v2.97c}{2007/06/06}{\cs{unskip}\cs{strut} added to fix vertical
1196 % positions in some \emph{above} cases}
1197 % \changes{v3.02a}{2009/01/24}{braces fixed}
1198 % \changes{v3.11c}{2013/06/12}{using \cs{usekomafont}}
1199 % \changes{v3.12}{2013/06/12}{one \cs{usekomafont} replaced by \cs{usesizeofkomafont}}
1200 % \changes{v3.21}{2016/05/31}{re-implemented}
1201 % \changes{v3.46}{2025/08/15}{handling of \cs{label}, \cs{index},
1202 % \cs{glossary} in online detection pass improved}
1203 % \begin{macrocode}
1204 \NewHook{\KOMAClassName/makecaption/deactivate}
1205 \newcommand{\@@makecaption}[3]{%
1206 % \end{macrocode}
1207 % Recalculate the margins.
1208 % \begin{macrocode}
1209 \cap@margin
1210 % \end{macrocode}
1211 % Test for special treatment of one line captions.
1212 % \changes{v3.22}{2016/09/01}{local redefinition of \cs{stepcounter} and
1213 % \cs{refstepcounter} because of \pkg{isodate}}
1214 % \begin{macrocode}
1215 \begingroup
1216 \ifonelinecaptions
1217 \def\stepcounter##1{\advance\value{##1}\@ne}%
1218 \let\refstepcounter\stepcounter
1219 \let\label\@gobble@om
1220 \let\index\@gobble@som
1221 \let\glossary\@gobble@om
1222 \let\@footnotetext=\@gobble
1223 \let\hypertarget\@gobbletwo
1224 \UseHook{\KOMAClassName/makecaption/deactivate}%
1225 % \end{macrocode}
1226 % \changes{v3.22}{2016/09/01}{special treatment of hard coded line breaks}
1227 % If there are hard coded line breaks using |\\| or \cs{newline}, we inform
1228 % the user to use a multi-line caption.
1229 % \begin{macrocode}
1230 \edef\@xnewline{%
1231 \unexpanded{\ClassInfo{\KOMAClassName}{%
1232 Workaround for not recommended usage of \string\\ or\MessageBreak
1233 \string\newline in caption text
1234 }%
1235 \hspace*{\linewidth}\hspace{1sp}%
1236 }%
1237 \unexpanded\expandafter{\@xnewline}%
1238 }%
1239 \edef\@xcentercr{%
1240 \unexpanded{\ClassInfo{\KOMAClassName}{%
1241 Workaround for not recommended usage of \string\\ or\MessageBreak
1242 \string\newline in caption text
1243 }%
1244 \hspace*{\linewidth}\hspace{1sp}%
1245 }%
1246 \unexpanded\expandafter{\@xcentercr}%
1247 }%
1248 \settowidth{\@tempdima}{\scr@@makesinglelinecaption{#1}{#2}{#3}}%
1249 % \end{macrocode}
1250 % \changes{v3.34}{2021/03/22}{fix of maximum line width of single line
1251 % captions}
1252 % Until \KOMAScript~3.34 the test here was wrong, because it used
1253 % \cs{linewidth}, which is still the whole line width not the maximum caption
1254 % width. From \KOMAScript~3.34 \cs{cap@width} is used.
1255 % \begin{macrocode}
1256 \ifdim\@tempdima>\cap@width
1257 \aftergroup\scr@makemultilinecaption
1258 \else
1259 \aftergroup\scr@makesinglelinecaption
1260 \fi
1261 \else
1262 \aftergroup\scr@makemultilinecaption
1263 \fi
1264 \endgroup
1265 {#1}{#2}{#3}%
1266 }
1267 % \end{macrocode}
1268 % \begin{macro}{\scr@@makesinglelinecaption,\scr@makesinglelinecaption}
1269 % \changes{v3.21}{2016/05/31}{added}
1270 % \changes{v3.44}{2024/11/27}{\cs{MakeCaptionLabelCase} and
1271 % \cs{MakeCaptionTextCase} added}
1272 % The output of single line captions. The first argument once again is
1273 % \cs{@gobble} (to not show a label) or \cs{@firstofone} (to show the
1274 % label). Argument two and three are the label (without separator, that is
1275 % added here) and the caption text.
1276 % \begin{macrocode}
1277 \newcommand{\scr@makesinglelinecaption}[3]{%
1278 {%
1279 \usefontofkomafont{caption}{%
1280 \hb@xt@\hsize{%
1281 \cap@left
1282 \scr@@makesinglelinecaption{#1}{#2}{#3}%
1283 \cap@right
1284 }\par\kern\dp\strutbox%
1285 }%
1286 }\kern-\dp\strutbox
1287 }
1288 \newcommand{\scr@@makesinglelinecaption}[3]{%
1289 \usekomafont{caption}{\strut\ignorespaces
1290 #1{{\usekomafont{captionlabel}{\MakeCaptionLabelCase{#2}\captionformat}}}%
1291 \MakeCaptionTextCase{#3}\unskip}%
1292 }
1293 % \end{macrocode}
1294 % \end{macro}^^A \scr@@makesinglelinecaption,\scr@makesinglelinecaption
1295 % \begin{macro}{\scr@makemultilinecaption}
1296 % \changes{v3.21}{2016/05/31}{added}
1297 % \changes{v3.44}{2024/11/27}{\cs{MakeCaptionLabelCase} and
1298 % \cs{MakeCaptionTextCase} added}
1299 % The output of multi line captions. The arguments are same as above.
1300 % \begin{macrocode}
1301 \newcommand{\scr@makemultilinecaption}[3]{%
1302 {%
1303 \usefontofkomafont{caption}{%
1304 \hb@xt@\hsize{%
1305 \cap@left
1306 \vbox{\hsize\cap@width\linewidth\hsize
1307 % \end{macrocode}
1308 % \changes{v3.25}{2017/11/15}{caption alignment added}
1309 % First of all we have to use the ragged type depending in the float/caption
1310 % type. If the float/caption type is unknown we can use the general ragged
1311 % type only.
1312 % \begin{macrocode}
1313 \scr@ifundefinedorrelax{@captype}{%
1314 \ClassWarning{\KOMAClassName}{%
1315 `\string\caption' outside float.\MessageBreak
1316 Seems you are using `\string\caption' outside a
1317 float.\MessageBreak
1318 Maybe you are using a package that uses
1319 `\string\@makecaption'\MessageBreak
1320 without setting `\string\@captype' before.\MessageBreak
1321 Because I cannot detect the caption type, I'm using\MessageBreak
1322 the empty one.%
1323 }%
1324 \let\@captype\@empty
1325 }{}%
1326 \scr@ifundefinedorrelax{ragged\@captype caption}{\raggedcaption}{%
1327 \@nameuse{ragged\@captype caption}%
1328 }%
1329 % \end{macrocode}
1330 % Maybe we have to us a full hanging caption.
1331 % \changes{v3.25}{2017/11/15}{Using \cs{scr@endstrut} instead of \cs{unskip}\cs{strut}}
1332 % \begin{macrocode}
1333 \ifdofullc@p
1334 \@hangfrom{%
1335 \strut
1336 \scr@smashdp{%
1337 #1{%
1338 \usekomafont{caption}{%
1339 \usekomafont{captionlabel}{%
1340 \MakeCaptionLabelCase{#2}\captionformat
1341 }%
1342 }%
1343 }%
1344 }%
1345 }%
1346 {\usekomafont{caption}{\MakeCaptionTextCase{#3}\scr@endstrut\par}}%
1347 % \end{macrocode}
1348 % Maybe a partial hanging caption with line break after the label.
1349 % \begin{macrocode}
1350 \else
1351 \ifdim\cap@indent<\z@
1352 \strut
1353 #1{%
1354 \usekomafont{caption}{%
1355 \usekomafont{captionlabel}{%
1356 \MakeCaptionLabelCase{#2}\captionformat\par
1357 }%
1358 }%
1359 }%
1360 \noindent{\usekomafont{caption}{%
1361 \hspace*{-\cap@indent}%
1362 \MakeCaptionTextCase{#3}\scr@endstrut\par
1363 }}%
1364 % \end{macrocode}
1365 % Or a line break after the label with full hanging.
1366 % \begin{macrocode}
1367 \else
1368 \if@capbreak
1369 \strut
1370 #1{%
1371 \usekomafont{caption}{%
1372 \usekomafont{captionlabel}{%
1373 \MakeCaptionLabelCase{#2}\captionformat\par
1374 }%
1375 }%
1376 }%
1377 \noindent\@hangfrom{\hspace*{\cap@indent}}%
1378 {\usekomafont{caption}{%
1379 \MakeCaptionTextCase{#3}\scr@endstrut\par
1380 }}%
1381 % \end{macrocode}
1382 % \changes{v3.27a}{2019/10/21}{missing usage of \fnt{caption} added}
1383 % Or no line break but still with indent.
1384 % \begin{macrocode}
1385 \else
1386 \@hangfrom{\scr@smashdp\strut\hspace*{\cap@indent}}%
1387 {%
1388 \hspace{-\cap@indent}%
1389 \scr@smashdp{%
1390 #1{\usekomafont{caption}{%
1391 \usekomafont{captionlabel}{%
1392 \MakeCaptionLabelCase{#2}\captionformat
1393 }%
1394 }%
1395 }%
1396 }%
1397 {\usekomafont{caption}{%
1398 \MakeCaptionTextCase{#3}\scr@endstrut}\par
1399 }%
1400 }%
1401 \fi
1402 \fi
1403 \fi
1404 % \end{macrocode}
1405 % Here we could also add the not hanging version without line break:
1406 % \begin{macrocode}
1407 %<*neverusethis>
1408 % #1{{\usekomafont{caption}{%
1409 % \usekomafont{captionlabel}{%
1410 % \MakeCaptionLabelCase{#2}\captionformat}}}}%
1411 % {\usekomafont{capion}{\MakeCaptionTextCase{#3}\scr@endstrut\par}%
1412 %</neverusethis>
1413 % \end{macrocode}
1414 % But this is not needed, because it is the same like indent of 0.
1415 % \begin{macrocode}
1416 }%
1417 \cap@right
1418 }\par\kern\dp\strutbox
1419 }%
1420 }\kern-\dp\strutbox
1421 }
1422 % \end{macrocode}
1423 % \begin{command}{\MakeCaptionTextCase,\MakeCaptionLabelCase}
1424 % \changes{v3.44}{2024/11/27}{added}
1425 % \begin{macrocode}
1426 \newcommand{\MakeCaptionLabelCase}[1]{#1}
1427 \newcommand{\MakeCaptionTextCase}[1]{#1}
1428 % \end{macrocode}
1429 % \end{command}
1430 % \begin{command}{\setcaptionalignment}
1431 % \begin{macro}{\@setcaptionalignment}
1432 % \changes{v3.25}{2017/11/15}{added}
1433 % \changes{v3.28}{2019/11/18}{\cs{ifstr} replaced by \cs{Ifstr}}
1434 % It is better for users to not define the \cs{raggedcaption} and
1435 % \cs{ragged\dots caption} commands themselves to avoid mistakes. So we have
1436 % \begin{quote}
1437 % \cs{setcaptionalignment}\oarg{float}\marg{alignment}
1438 % \end{quote}
1439 % If \meta{float} is used, \cs{ragged\meta{float}caption} will be changed. If
1440 % \meta{float} is not used, but \cs{@captype} is defined (and not \cs{relax})
1441 % \cs{ragged\cs{@captype}caption} is defined. If \meta{float} is empty or
1442 % \cs{captype} is undefined (or \cs{relax}) and \meta{float} is not used,
1443 % \cs{raggedcaption} will be changed.
1444 % \begin{macrocode}
1445 \newcommand*\setcaptionalignment{%
1446 \kernel@ifnextchar [%]
1447 {\@setcaptionalignment}
1448 {%
1449 \scr@ifundefinedorrelax{@captype}{\@setcaptionalignment}{%
1450 \edef\reserved@a{\noexpand\@setcaptionalignment[{\@captype}]}\reserved@a
1451 }%
1452 }%
1453 }%
1454 \newcommand*\@setcaptionalignment[2][]{%
1455 % \end{macrocode}
1456 % If \meta{float} is not empty it should be the name of a already defined
1457 % floating environment. Otherwise we report a warning, but nevertheless define
1458 % the command.
1459 % \begin{macrocode}
1460 \IfArgIsEmpty{#1}{}{%
1461 \expandafter\ifnum
1462 \scr@ifundefinedorrelax{#1}{0}{\scr@ifundefinedorrelax{end#1}{0}{1}}=0
1463 \ClassWarning{\KOMAClassName}{%
1464 float type `#1' defined not yet,\MessageBreak
1465 but setting ragged mode for captions of\MessageBreak
1466 float type `#1'%
1467 }%
1468 \fi
1469 }%
1470 % \end{macrocode}
1471 % Depending on \meta{alignment} the command will be changed:
1472 % \begin{description}
1473 % \item[\texttt{j}] -- justified (\cs{ragged\dots caption} becomes \cs{relax}).
1474 % \item[\texttt{l}] -- left aligned (\cs{ragged\dots caption} becomes
1475 % \cs{raggedright}).
1476 % \item[\texttt{r}] -- right aligned (\cs{ragged\dots caption} becomes
1477 % \cs{raggedleft}).
1478 % \item[\texttt{c}] -- centered (\cs{ragged\dots caption} becomes
1479 % \cs{centering}.
1480 % \end{description}
1481 % Note: If \pkg{ragged2e} has been loaded, \cs{LaTeXraggedright},
1482 % \cs{LaTeXraggedleft} and \cs{LaTeXcentering} are used and the following
1483 % additional \meta{alignment}s are supported:
1484 % \begin{description}
1485 % \item[\texttt{J}] -- justified (\cs{ragged\dots caption} becomes \cs{justifying}).
1486 % \item[\texttt{L}] -- left aligned (\cs{ragged\dots caption} becomes
1487 % \cs{RaggedRight}).
1488 % \item[\texttt{R}] -- right aligned (\cs{ragged\dots caption} becomes
1489 % \cs{RaggedLeft}).
1490 % \item[\texttt{C}] -- centered (\cs{ragged\dots caption} becomes
1491 % \cs{Centering}.
1492 % \end{description}
1493 % Without \pkg{ragged2e} the upper case letters are same like lower case
1494 % letters, but additionally warn. Note: The implementation does also work, if
1495 % \pkg*{scrlayer-scrpage} has defined \cs{LaTeXraggedright} etc.
1496 % \begin{macrocode}
1497 \def\reserved@a{#2}%
1498 \Ifstr{\reserved@a}{j}{%
1499 \expandafter\let\csname ragged#1caption\endcsname\@empty
1500 }{%
1501 \Ifstr{\reserved@a}{l}{%
1502 \scr@ifundefinedorrelax{LaTeXraggedright}{%
1503 \expandafter\let\csname ragged#1caption\endcsname\raggedright
1504 }{%
1505 \expandafter\let\csname ragged#1caption\endcsname\LaTeXraggedright
1506 }%
1507 }{%
1508 \Ifstr{\reserved@a}{r}{%
1509 \scr@ifundefinedorrelax{LaTeXraggedleft}{%
1510 \expandafter\let\csname ragged#1caption\endcsname\raggedleft
1511 }{%
1512 \expandafter\let\csname ragged#1caption\endcsname\LaTeXraggedleft
1513 }%
1514 }{%
1515 \Ifstr{\reserved@a}{c}{%
1516 \scr@ifundefinedorrelax{LaTeXcentering}{%
1517 \expandafter\let\csname ragged#1caption\endcsname\centering
1518 }{%
1519 \expandafter\let\csname ragged#1caption\endcsname\LaTeXcentering
1520 }%
1521 }{%
1522 \Ifstr{\reserved@a}{J}{%
1523 \scr@ifundefinedorrelax{justifying}{%
1524 \scr@caption@raggede@warning{J}{\justifying}%
1525 \expandafter\let\csname ragged#1caption\endcsname\@empty
1526 }{%
1527 \expandafter\let\csname ragged#1caption\endcsname\justifying
1528 }%
1529 }{%
1530 \Ifstr{\reserved@a}{L}{%
1531 \scr@ifundefinedorrelax{RaggedRight}{%
1532 \scr@caption@raggede@warning{L}{\RaggedRight}%
1533 \expandafter\let\csname ragged#1caption\endcsname\raggedright
1534 }{%
1535 \expandafter\let\csname ragged#1caption\endcsname\RaggedRight
1536 }%
1537 }{%
1538 \Ifstr{\reserved@a}{R}{%
1539 \scr@ifundefinedorrelax{RaggedLeft}{%
1540 \scr@caption@raggede@warning{R}{\RaggedLeft}%
1541 \expandafter\let\csname ragged#1caption\endcsname\raggedleft
1542 }{%
1543 \expandafter\let\csname ragged#1caption\endcsname\RaggedLeft
1544 }%
1545 }{%
1546 \Ifstr{\reserved@a}{C}{%
1547 \scr@ifundefinedorrelax{Centering}{%
1548 \scr@caption@raggede@warning{C}{\Centering}%
1549 \expandafter\let\csname ragged#1caption\endcsname\centering
1550 }{%
1551 \expandafter\let\csname ragged#1caption\endcsname\Centering
1552 }%
1553 }{%
1554 \Ifstr{\reserved@a}{}{%
1555 \expandafter\let\csname ragged#1caption\endcsname\relax
1556 }{%
1557 \ClassError{\KOMAClassName}{unknown alignment char `#2'}{%
1558 \string\setcaptionalignment\space supports
1559 only:\MessageBreak
1560 \space\space c - centered captions,\MessageBreak
1561 \space\space j - justified captions,\MessageBreak
1562 \space\space l - left align captions,\MessageBreak
1563 \space\space r - right aligned captions,\MessageBreak
1564 \space\space C - centered captions with
1565 `ragged2e',\MessageBreak
1566 \space\space J - justified captions with
1567 `ragged2e',\MessageBreak
1568 \space\space L - left align captions with
1569 `ragged2e',\MessageBreak
1570 \space\space R - right aligned captions with
1571 `ragged2e',\MessageBreak
1572 or an empty argument to remove special
1573 alignment.\MessageBreak
1574 If you'd continue, I'd not change the alignment.%
1575 }%
1576 }%
1577 }%
1578 }%
1579 }%
1580 }%
1581 }%
1582 }%
1583 }%
1584 }%
1585 }
1586 % \end{macrocode}
1587 % \begin{macro}{\scr@caption@raggede@warning}
1588 % \changes{v3.25}{2017/11/15}{added}
1589 % The warning used above.
1590 % \begin{macrocode}
1591 \newcommand*{\scr@caption@raggede@warning}[2]{%
1592 \begingroup
1593 \lowercase{\def\reserved@a{#1}}%
1594 \ClassWarning{\KOMAClassName}{%
1595 `\string#2' undefined!\MessageBreak
1596 To avoid replacing caption alignment `#1' by `\reserved@a'\MessageBreak
1597 you should load package `ragged2e' before using\MessageBreak
1598 `\string\setcaptionalignment'%
1599 }%
1600 \endgroup
1601 }
1602 % \end{macrocode}
1603 % \begin{command}{\raggedcaption}
1604 % \changes{v3.25}{2017/11/15}{added}
1605 % The default alignment is standard alignment (empty means no change).
1606 % \begin{macrocode}
1607 \newcommand*\raggedcaption{}
1608 % \end{macrocode}
1609 % \end{command}^^A \raggedcaption
1610 % \end{macro}^^A \scr@caption@raggede@warning
1611 % \end{macro}^^A \@setcaptionalignment
1612 % \end{command}^^A \setcaptionalignment
1613 % \end{macro}^^A \scr@makemultilinecaption
1614 % \end{macro}^^A \@@makecaption
1615 % \changes{v3.46}{2025/06/23}{\pkg*{caption3} support added}
1616 % \begin{macrocode}
1617 \AddToHook{package/caption3/after}{%
1618 \DeclareCaptionFormat{koma}[#1#2#3\par]{%
1619 \ifdofullc@p
1620 \caption@useformat{hang}{#1}{#2}{#3}%
1621 \else
1622 #1#2%
1623 \ifdim\cap@indent<\z@
1624 \par
1625 \noindent\hspace*{-\cap@indent}%
1626 \else\if@capbreak
1627 \par
1628 \fi\fi
1629 #3\par
1630 \fi}%
1631 \SetCaptionDefault{format}{koma}
1632 \DeclareCaptionLabelFormat{koma}{\bothIfFirst{#1}{\nobreakspace}#2\autodot}
1633 \SetCaptionFallback{labelformat}{koma}
1634 }
1635 % \end{macrocode}
1636 % \end{macro}^^A \@makecaption
1637 %
1638 % \subsection{Special treatment of \texorpdfstring{\pkg*{longtable}}{`longtable'} captions}
1639 %
1640 % \begin{macro}{\LT@makecaption}
1641 % \changes{v2.8j}{2001/07/30}{added}
1642 % \changes{v2.8k}{2001/08/15}{do nothing if \pkg{caption2} has been loaded or
1643 % option \opt{origlongtable} has been used}
1644 % \changes{v2.8q}{2001/11/18}{width and alignment by \KOMAScript{}}
1645 % \changes{v2.8q}{2001/11/18}{using \cs{AfterPackage}}
1646 % \changes{v2.9s}{2004/08/24}{vertical skips fixed by moving \cs{vskip}}
1647 % \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
1648 % \begin{macro}{\LT@array,\LT@caption}
1649 % \changes{v2.8q}{2001/11/18}{added}
1650 % \begin{macro}{\scr@caption@before@longtable@warning}
1651 % \changes{v2.98c}{2008/03/03}{added}
1652 % The code for \pkg{longtable} has to be delayed until loading the package.
1653 % \begin{macrocode}
1654 \newcommand*{\scr@caption@before@longtable@warning}[1]{%
1655 \ClassWarning{\KOMAClassName}{%
1656 you've loaded package `#1' before package\MessageBreak
1657 `longtable'!\MessageBreak
1658 Because of this package `#1' isn't able to\MessageBreak
1659 control `\string\caption' at longtables. \space After loading
1660 \MessageBreak
1661 package `#1' KOMA-Script also doesn't control\MessageBreak
1662 `\string\caption'.\MessageBreak
1663 I think, you should load package `caption' after\MessageBreak
1664 package `longtable'%
1665 }%
1666 }
1667 \AfterPackage{longtable}{%
1668 \if@komalongtable
1669 \renewcommand{\LT@makecaption}[3]{%
1670 \LT@mcol\LT@cols c{%
1671 \hbox to\z@{\hss\parbox[t]\linewidth{%
1672 % \end{macrocode}
1673 % \changes{v3.25}{2017/11/15}{\cs{@captype} set to \texttt{table}}
1674 % \changes{v3.46}{2025/06/13}{use \cs{LTcaptype} if defined and not empty}
1675 % To make \cs{raggedtablecaption} available, \cs{@captype} has to be defined.
1676 % \begin{macrocode}
1677 \if@captionabove\else\vskip\belowcaptionskip\fi
1678 \@@makecaption{#1}{#2}{#3}%
1679 \endgraf
1680 \if@captionabove\vskip\abovecaptionskip\fi
1681 }%
1682 \hss
1683 }%
1684 }%
1685 }%
1686 \newcommand*{\scr@LT@array}{}%
1687 \let\scr@LT@array=\LT@array
1688 \renewcommand*{\LT@array}{%
1689 \def\@captype{table}%
1690 \@ifundefined{LTcaptype}{}{%
1691 \Ifstr{\LTcaptype}{}{}{\let\@captype\LTcaptype}%
1692 }%
1693 \csname tocbasic_if_caption_above:TF\endcsname
1694 {\@captionabovetrue}{\@captionabovefalse}%
1695 \def\captionabove{\noalign{\global\@captionabovetrue}%
1696 \LT@caption}%
1697 \def\captionbelow{\noalign{\global\@captionabovefalse}%
1698 \LT@caption}%
1699 \scr@LT@array
1700 }%
1701 \ClassInfo{\KOMAClassName}{%
1702 longtable captions redefined%
1703 }%
1704 \fi
1705 }
1706 % \end{macrocode}
1707 % \end{macro}^^A \scr@caption@before@longtable@warning
1708 % \end{macro}^^A \LT@array,\LT@caption
1709 % \end{macro}^^A \LT@makecaption
1710 %
1711 % \subsection{Special treatment of the \texorpdfstring{\pkg*{float}}{`float'} package}
1712 %
1713 % \begin{macro}{\fs@komaabove,\fs@komabelow,\floatc@komascript}
1714 % \changes{v2.8j}{2001/07/30}{added}
1715 % We define two float style for package \pkg{float}: \texttt{komaabove} and
1716 % \texttt{komabelow}. However this is done independent of loading \pkg{float},
1717 % because maybe someone else also uses those styles (but I don't think so).
1718 % Note: Internal macros of \pkg{float} has to be used for the definitions.
1719 % \begin{macrocode}
1720 \newcommand*{\fs@komaabove}{%
1721 \let\@fs@capt\floatc@komascript
1722 \let\@fs@pre\@empty
1723 \def\@fs@mid{\vskip\abovecaptionskip}%
1724 \let\@fs@post\@empty
1725 \let\@fs@iftopcapt\iftrue}
1726 \newcommand*{\fs@komabelow}{%
1727 \let\@fs@capt\floatc@komascript
1728 \let\@fs@pre\@empty
1729 \def\@fs@mid{\vskip\abovecaptionskip}%
1730 \let\@fs@post\@empty
1731 \let\@fs@iftopcapt\iffalse}
1732 \newcommand{\floatc@komascript}{\@@makecaption\@firstofone}
1733 % \end{macrocode}
1734 % \end{macro}^^A \fs@komabove,\fs@komabelow,\floatc@komascript
1735 %
1736 %
1737 % \subsection{Where to place floats}
1738 %
1739 % \begin{counter}{topnumber}
1740 % \begin{command}{\topfraction}
1741 % \begin{counter}{bottomnumber}
1742 % \begin{command}{\bottomfraction}
1743 % \begin{counter}{totalnumber}
1744 % \begin{command}{\textfraction}
1745 % \begin{command}{\floatpagefraction}
1746 % \begin{counter}{dbltopnumber}
1747 % \begin{command}{\dbltopfraction}
1748 % \begin{command}{\dblfloatpagefraction}
1749 % These are constants used by the \LaTeX{} kernel to decide where to place a
1750 % float. See the kernel documentation for more information.
1751 % \begin{macrocode}
1752 \setcounter{topnumber}{2}
1753 \renewcommand*\topfraction{.7}
1754 \setcounter{bottomnumber}{1}
1755 \renewcommand*\bottomfraction{.3}
1756 \setcounter{totalnumber}{3}
1757 \renewcommand*\textfraction{.2}
1758 \renewcommand*\floatpagefraction{.5}
1759 \setcounter{dbltopnumber}{2}
1760 \renewcommand*\dbltopfraction{.7}
1761 \renewcommand*\dblfloatpagefraction{.5}
1762 % \end{macrocode}
1763 % \end{command}
1764 % \end{command}
1765 % \end{counter}
1766 % \end{command}
1767 % \end{command}
1768 % \end{counter}
1769 % \end{command}
1770 % \end{counter}
1771 % \end{command}
1772 % \end{counter}
1773 %
1774 %
1775 % \subsection{Caption without float}
1776 %
1777 % \begin{command}{\captionof}
1778 % \changes{v3.05}{2009/07/08}{added}
1779 % \changes{v3.09}{2011/03/21}{using internal \cs{scr@caption}}
1780 % \changes{v3.09a}{2011/04/13}{handling of
1781 % \opt{captions\quotechar=tableheading} and
1782 % \opt{captions\quotechar=figureheading}}
1783 % \changes{v3.46}{2025/06/13}{moved to package \pkg*{tocbasic}}
1784 % \end{command}^^A \captionof
1785 % \begin{command}{\captionaboveof,\captionbelowof}
1786 % \changes{v3.09}{2011/03/21}{added}
1787 % \changes{v3.46}{2025/06/13}{moved to package \pkg*{tocbasic}}
1788 % \end{command}^^A \captionaboveof,\captionbelowof
1789 %
1790 % \begin{environment}{captionofbeside}
1791 % \changes{v3.10}{2011/09/02}{added}
1792 % The analogue environment to \cs{captionbeside} to be used outside
1793 % floats.
1794 % \begin{description}
1795 % \item[ToDo:] Wouldn't it be a good idea to test for already defined
1796 % \cs{@captype} inside \env{captionbeside} and then expect an additional first
1797 % argument \meta{float}? In this case user could simply us \env{captionbeside}
1798 % the same way as \env{captionofbeside}.
1799 % \end{description}
1800 % \begin{macrocode}
1801 \newenvironment{captionofbeside}[1]{%
1802 \def\@captype{#1}%
1803 \captionbeside
1804 }{%
1805 \endcaptionbeside
1806 }
1807 % \end{macrocode}
1808 % \end{environment}
1809 %
1810 %
1811 % \subsection{Names}
1812 %
1813 % \begin{command}{\figurename,\tablename}
1814 % \changes{v3.36}{2022/02/15}{explicit definition for English languages}
1815 % The names to be used for the float labels.
1816 % \begin{macrocode}
1817 \newcommand*\figurename{Figure}
1818 \providecaptionname{american,australian,british,canadian,english,newzealand,%
1819 UKenglish,ukenglish,USenglish,usenglish}\figurename{Figure}
1820 \newcommand*\tablename{Table}
1821 \providecaptionname{american,australian,british,canadian,english,newzealand,%
1822 UKenglish,ukenglish,USenglish,usenglish}\tablename{Table}
1823 % \end{macrocode}
1824 % \end{command}^^A \figurename,\tablename
1825 %
1826 %
1827 % \subsection{Defining the \env{figure} environment}
1828 %
1829 % \begin{environment}{figure*,figure-,figure}
1830 % \changes{v2.2c}{1995/05/25}{initial CJK support}
1831 % \changes{v2.8h}{2001/07/19}{\cs{caption} is \cs{captionbelow}}
1832 % \changes{v3.25}{2017/10/10}{re-implemented using \pkg*{tocbasic}}
1833 % \changes{v3.36}{2022/02/22}{define additional non-float}
1834 % \begin{counter}{figure}
1835 % \changes{v3.25}{2017/10/10}{implicit by \cs{DeclareNewTOC}}
1836 % \end{counter}
1837 % We do the main job using \cs{DeclareNewTOC}:
1838 % \begin{macrocode}
1839 \DeclareNewTOC[%
1840 type=figure,
1841 float,
1842 nonfloat,
1843 %<book|report> counterwithin=chapter,
1844 % \end{macrocode}
1845 % \begin{macro}{\fps@figure}
1846 % Default placement (by \cs{DeclareNewTOC}) \textbf{t}op, \textbf{b}ottom,
1847 % \textbf{p}age.
1848 % \begin{macrocode}
1849 floatpos=tbp,
1850 % \end{macrocode}
1851 % \end{macro}
1852 % \begin{macro}{\ftype@figure}
1853 % Numerical float type 1 (by \cs{DeclareNewTOC}).
1854 % \begin{macrocode}
1855 floattype=1,
1856 % \end{macrocode}
1857 % \end{macro}
1858 % \changes{v3.11c}{2013/03/01}{fix: one \cs{caption} change removed}
1859 % \changes{v3.20}{2016/04/07}{internal redefinition of \cs{caption}}
1860 % \changes{v3.46}{2025/06/13}{internal redefinition of \cs{caption} removed}
1861 % \begin{macrocode}
1862 tocentryindent=1.5em,
1863 tocentrynumwidth=2.3em,
1864 % \end{macrocode}
1865 % \begin{macro}{\ext@figure}
1866 % Extension to be used (by \cs{DeclareNewTOC})
1867 % \begin{macrocode}
1868 ]{lof}
1869 % \end{macrocode}
1870 % \end{macro}
1871 % \begin{command}{\thefigure}
1872 % \changes{v2.97e}{2007/11/23}{using chapter number in main-matter only}
1873 % \changes{v3.27}{2019/06/26}{\cs{relax} replaced by percent}
1874 % \changes{v3.35}{2021/10/12}{use chapter number only of greater than zero}
1875 % \changes{v3.35}{2021/10/12}{redefine \cs{thefigure} only if compatibility is
1876 % less or equal 2.97d resp. less than 3.35}
1877 % \begin{macrocode}
1878 %<*!v4>
1879 %<*book|report>
1880 \expandafter\ifnum\scr@v@is@le{2.97d}%
1881 \renewcommand*\thefigure{\thechapter.\@arabic\c@figure}
1882 \fi
1883 %</book|report>
1884 %<*article>
1885 \expandafter\ifnum\scr@v@is@lt{3.35}%
1886 \renewcommand*\thefigure{\@arabic\c@figure}
1887 \fi
1888 %</article>
1889 %</!v4>
1890 % \end{macrocode}
1891 % \end{command}
1892 % \begin{macro}{\fnum@figure}
1893 % \begin{command}{\figureformat}
1894 % \changes{v2.3c}{1995/08/06}{added}
1895 % The print format of the number (by \cs{DeclareNewTOC}).
1896 % \end{command}
1897 % \end{macro}
1898 % \end{environment}
1899 %
1900 %
1901 % \subsection{Defining the \env{table} environment}
1902 %
1903 % Note: This is almost the same as defining the \env{figure} environment. So
1904 % read the previous section first.
1905 %
1906 % \begin{environment}{table*,table-,table}
1907 % \changes{v2.2c}{1995/05/25}{initial CJK support}
1908 % \changes{v2.8h}{2001/07/19}{\cs{caption} is \cs{captionbelow}}
1909 % \changes{v3.25}{2017/10/10}{re-implemented using \pkg*{tocbasic}}
1910 % \changes{v3.36}{2022/02/22}{define additional non-float}
1911 % \begin{counter}{table}
1912 % \changes{v3.25}{2017/10/10}{implicit by \cs{DeclareNewTOC}}
1913 % \end{counter}
1914 % We do the main job using \cs{DeclareNewTOC}:
1915 % \begin{macrocode}
1916 \DeclareNewTOC[%
1917 type=table,
1918 float,
1919 nonfloat,
1920 %<book|report> counterwithin=chapter,
1921 % \end{macrocode}
1922 % \begin{macro}{\fps@table}
1923 % Default placement (by \cs{DeclareNewTOC}) \textbf{t}op, \textbf{b}ottom,
1924 % \textbf{p}age.
1925 % \begin{macrocode}
1926 floatpos=tbp,
1927 % \end{macrocode}
1928 % \end{macro}
1929 % \begin{macro}{\ftype@table}
1930 % Numerical float type 2 (by \cs{DeclareNewTOC}).
1931 % \begin{macrocode}
1932 floattype=2,
1933 % \end{macrocode}
1934 % \end{macro}
1935 % \changes{v3.20}{2016/04/07}{internal redefinition of \cs{caption}}
1936 % \changes{v3.46}{2025/06/13}{internal redefinition of \cs{caption} removed}
1937 % \begin{macrocode}
1938 tocentryindent=1.5em,
1939 tocentrynumwidth=2.3em,
1940 % \end{macrocode}
1941 % \begin{macro}{\ext@table}
1942 % Extension to be used (by \cs{DeclareNewTOC})
1943 % \begin{macrocode}
1944 ]{lot}
1945 % \end{macrocode}
1946 % \end{macro}
1947 % \begin{command}{\thetable}
1948 % \changes{v2.97e}{2007/11/23}{using chapter number in main-matter only}
1949 % \changes{v3.27}{2019/06/26}{\cs{relax} replaced by percent}
1950 % \changes{v3.35}{2021/10/12}{use chapter number only of greater than zero}
1951 % \changes{v3.35}{2021/10/12}{redefine \cs{thetable} only if compatibility is
1952 % less or equal 2.97d resp. less than 3.35}
1953 % \begin{macrocode}
1954 %<*!v4>
1955 %<*book|report>
1956 \expandafter\ifnum\scr@v@is@le{2.97d}%
1957 \renewcommand*\thetable{\thechapter.\@arabic\c@table}
1958 \fi
1959 %</book|report>
1960 %<*article>
1961 \expandafter\ifnum\scr@v@is@lt{3.35}%
1962 \renewcommand*\thetable{\@arabic\c@table}
1963 \fi
1964 %</article>
1965 %</!v4>
1966 %</body>
1967 % \end{macrocode}
1968 % \end{command}
1969 % \begin{macro}{\fnum@table}
1970 % \begin{command}{\tableformat}
1971 % \changes{v2.3c}{1995/08/06}{added}
1972 % The print format of the number (by \cs{DeclareNewTOC}).
1973 % \end{command}
1974 % \end{macro}
1975 % \end{environment}
1976 %
1977 % \begin{macrocode}
1978 %</class&!letter>
1979 % \end{macrocode}
1980 %
1981 % \Finale
1982 % \PrintChanges
1983 %
1984 \endinput
1985 % Local Variables:
1986 % mode: doctex
1987 % ispell-local-dictionary: "en_US"
1988 % eval: (flyspell-mode 1)
1989 % TeX-master: t
1990 % TeX-engine: luatex-dev
1991 % eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-alist TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "mkindex %s" TeX-run-index nil t :help "makeindex for dtx"))
1992 % End: