4

I'm using a KOMA-script based twocolumn layout and modifying float captions with the caption package. Unfortunately, when redefining the default style, the new options will apply to both column-wide figures and text-wide figure*s. This results in captions that do not always have the intended width:

\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}
\usepackage{blindtext}

\usepackage[
  justification=RaggedRight,
  width=.9\columnwidth,
]{caption}

\begin{document}


\blindtext
\begin{figure}[htpb]
  \rule{\columnwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is as intended.
  }
\end{figure}
\blindtext

\clearpage
\begin{figure*}[htpb]
  \rule{\textwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is too small.
  }
\end{figure*}
\clearpage

\captionsetup{
  justification=RaggedRight,
  width=.9\textwidth,
}

\blindtext
\begin{figure}[htpb]
  \rule{\columnwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is too large.
  }
\end{figure}
\blindtext

\clearpage
\begin{figure*}[htpb]
  \rule{\textwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is as intended.
  }
\end{figure*}
\clearpage

\end{document}

enter image description here


enter image description here


enter image description here


enter image description here


I'm circumventing this for now by manually switching to a separate style defined through \DeclareCaptionStyle{colfigure}{...} for column figures using \captionsetup{style=colfigure} but I'd prefer not to do this manually. Is there a way to automatise this?

  • 1
    Usually using width=... as global option is a bad idea; it makes more sense when using as (local) option within an environment. Try something like calcwidth=.9\linewidth instead. – Axel Sommerfeldt Jul 5 '18 at 21:31
  • @AxelSommerfeldt Can you add an answer too? I did not found option calcwidth in the package documentation. – esdd Jul 6 '18 at 7:43
  • @esdd Yes, unfortunately the calcwidth option is only mentioned in the CHANGELOG file. I just took a look, it's available for about 7 years. Shame on me, hopefully an updated documentation will be available at the end of this year. – Axel Sommerfeldt Jul 6 '18 at 8:05
2

While the width=... option sets the width of the caption to a fixed amount immediately, calcwidth=... will evaluate the value if needed, i.e. every time a caption is actually typeset.

So usually using width=... as global option is a bad idea; it makes more sense when using as (local) option within a single figure or table.

So try something like calcwidth=.9\linewidth instead:

\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}
\usepackage{blindtext}

\usepackage[
  justification=RaggedRight,
  calcwidth=.9\linewidth,
]{caption}

\begin{document}

\blindtext
\begin{figure}[htpb]
  \rule{\columnwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is as intended.
  }
\end{figure}
\blindtext

\clearpage
\begin{figure*}[htpb]
  \rule{\textwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is as intended.
  }
\end{figure*}

\end{document}

calcwidth=... was introduced with v3.2 of the caption package on 2011/07/30 but is still not part of the documentation. (It's only mentioned in the CHANGELOG file.) See also: https://gitlab.com/axelsommerfeldt/caption/issues/1

A new version v3.4 with a completely revised documentation is planned for the end of this year.

3

Here is a suggestion that needs at least KOMA-Script version 3.25 and works only without package caption.

\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}[2018/03/30]% needs version 3.25 or newer
\usepackage{blindtext}

\setcaptionalignment{l}% needs version 3.25
\setcapdynwidth{.9\linewidth}% needs version 3.20

\begin{document}
\blindtext
\begin{figure}[htpb]
  \rule{\columnwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is as intended.
  }
\end{figure}
\blindtext

\clearpage
\begin{figure*}[htpb]
  \rule{\textwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is too small.
  }
\end{figure*}
\end{document}

Result:

enter image description here

Or with package ragged2e and caption alignment L:

\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}[2018/03/30]% needs version 3.25 or newer
\usepackage{blindtext}

\usepackage{ragged2e}
\setcaptionalignment{L}% needs version 3.25
\setcapdynwidth{.9\linewidth}% needs version 3.20

\begin{document}
\blindtext
\begin{figure}[htpb]
  \rule{\columnwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is as intended.
  }
\end{figure}
\blindtext

\clearpage
\begin{figure*}[htpb]
  \rule{\textwidth}{2cm}
  \caption{A few words that consume more space than a single line.
    The width of this caption is too small.
  }
\end{figure*}
\end{document}

\documentclass{article} \begin{document} [ \left{ x\in\mathbf{R} \middle] 0<{|x|}<\frac{5}{3} \right} ]

\end{document}

Result:

enter image description here

  • 1
    But this should work with caption package, too, so it seems I have additional work to do. I opened an issue: gitlab.com/axelsommerfeldt/caption/issues/23 – Axel Sommerfeldt Jul 6 '18 at 8:50
  • Thank you, that looks like a reasonable fix to the problem. The example was somewhat simplified, my actual caption style uses more options (maybe that could be done in KOMA, too, didn't try). I prefer the key-value input syntax of the caption package over KOMA-scripts syntax however, thus accepting @AxelSommerfeldt 's answer. – Wisperwind Jul 6 '18 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.