Changing Default Captions In Latex With Babel, Polyglossia, And Koma-Script

The Problem with Default Captions

The default caption formatting in LaTeX often does not meet the needs of publishers and authors. The plain LaTeX document class produces captions that simply read "Figure 1: Caption text" or "Table 1: Caption text". While this may be sufficient in some cases, many authors require more customizable and aesthetically pleasing caption formatting.

Some common issues that authors face with LaTeX's default caption formatting include inconsistent styling between figure and table captions, no options to remove the label prefix like "Figure" or "Table", and limited control over font choices, text size, and position. Additionally, for documents with translated content, LaTeX does not automatically translate captions into other languages.

In this article, we will explore several methods for customizing caption formatting in LaTeX using the powerful Babel, Polyglossia, and KOMA-Script packages. Through examples and explanations, you will learn techniques to take control over the appearance, translation, and consistency of captions in LaTeX documents.

Using the Babel Package

The Babel package provides easy access to customized captions by enabling language-dependent typesetting. This package can only be used with caption definitions from the standard LaTeX document classes. To begin using it, first install Babel if it is not already present in your LaTeX distribution:

\usepackage[LANGUAGE]{babel}

Replace LANGUAGE with the language option for your document, such as english, french, spanish, etc. Note that language names are lowercase when used with Babel.

Next, update the caption formatting using the \addto command to recreate the caption definition. For example, to remove the "Figure 1:" prefix from captions, use:

\addto\captionsLANGUAGE{
  \renewcommand{\figurename}{}  
}

Where LANGUAGE is again the lowercase language name. This will strip out the figure name text from figure captions, leaving only the user-defined caption text. The table name prefix can be customized in the same manner by altering \tablename instead of \figurename.

Additional caption formatting customization possible with Babel includes:

  • Font changes using \captionfont
  • Label separation with \captionlabelsep
  • Margin alignment via \captionstyle

Though powerful, a downside to Babel is captions must adhere to the strict structure defined by standard document classes. For more flexible customization, other packages like KOMA-Script prove useful.

Caption Translation with Polyglossia

The Polyglossia package provides an alternative method for multi-language typesetting compared to Babel. As well as easier access to hyphenation patterns and language variants, Polyglossia enables automatic caption translation to secondary languages defined in the document preamble.

To begin using Polyglossia, first install and load the package:

\usepackage{polyglossia}

Next, set the main document language using the \setmainlanguage command:

\setmainlanguage{LANGUAGE}

Replace LANGUAGE with options like english, french, german, etc. Unlike Babel, language names in Polyglossia are capitalized.

If your document contains sections in secondary languages, define them with:\

\setotherlanguage[VARIANT]{LANGUAGE}

For example, to enable British English subtitles in an American English document:

\setotherlanguage[spelling=british]{english}

With at least one secondary language configured, caption translation occurs automatically. The main language captions will appear in the document body with translated versions in subtitles, as shown in Figure \ref{fig1}:

\begin{figure}
  \includegraphics{...}
  \caption{An informative graph} 
  \label{fig1}
\end{figure}

In this way, Polyglossia provides effortless caption formatting across multiple languages. However, similar to Babel, there remains limited control over visual style.

Customizing Captions in KOMA-Script

For ultimate flexibility in caption customization, the KOMA-Script bundle proves invaluable. As an alternative to the default LaTeX document classes, KOMA-Script grants extensive control over document design through packages like scrartcl, scrreprt, and scrbook.

To unleash the caption formatting power of KOMA-Script, begin by importing the bundle:

\usepackage{scrbase, scrextend}

Now caption parameters can be manipulated with commands like \setcaptype:

\setcaptype{type}[options]

Where "type" is figure or table, and "options" configure parameters like name prefix text, label separator, font properties, and indentation. For example:

\setcaptype{figure}
   [name=,labelsep=quad,font=small, indention=0em]

Would strip the figure name prefix, set the space between label and text, use a smaller font just for captions, and remove indentation from the caption paragraph.

Additional useful caption commands provided by KOMA-Script include:

  • \setcapmargin{margin} to set side margin
  • \setcaptionsubtype{type} for custom sub-types like "Algorithm"
  • \newcaptionname{language}{type} for multi-lingual names

Through the power and breadth of KOMA-Script, captions can be customized far beyond the constraints of standard LaTeX or even many other packages.

Achieving Consistent Style Across Document

Regardless of the solution used customize LaTeX captions - whether Babel, Polyglossia, KOMA-Script or otherwise - applying changes globally promotes a consistent document style.

First, set universal caption parameters in the preamble before customizing figure or table captions separately. KOMA-Script options like \setcapmargin, \setcapfont and \setcaplabelsep apply uniformly to all caption types when defined up front.

Next, use these global attributes as defaults for figure and table captions. For example:

\setcapmargin{0em} % Global 
\setcaptype{figure}
   [margin=0em,labelsep=colon]

Ensures all captions share the same side margin while figures have unique ":" label separation.

Lastly, create custom caption styles with descriptive names like "CompactCaptionStyle" using:\

\DeclareCaptionStyle{...}[justification=centering,labelfont=bf,textfont=it]}

Such styles help avoid verbose repeated code when declaring layouts for subfigures, algorithms, listings, etc:

\captionsetup[subfigure]{style=CompactCaptionStyle}

Following these best practices results in cleanly defined, reusable caption formatting - simplifying maintenance for complex document formatting needs.

Leave a Reply

Your email address will not be published. Required fields are marked *