5

I am using the KOMA-Script class scrreprt with the ragged2e package to achieve ragged right document text. I still want to retain paragraph indentation (and have no inter-paragraph spacing, i.e., parskip=0), so I set \RaggedRightParindent{2em}, but this seems to also affect my float captions when the subcaption package is loaded.

Example:

\documentclass{scrreprt}
\usepackage {mwe}%
\usepackage[document]{ragged2e} % for creating ragged right edge etc
\setlength{\RaggedRightParindent}{2em}% sets the indent size of the first line
\usepackage{subcaption}% for creating figures in figures

\setcapindent{0em}

\begin{document}

\section{title}

\lipsum[11]


  \begin{figure}[tbh]
  \setcapindent{0em}
  \centering
    \includegraphics[width=0.4\linewidth]{example-image}
      \caption{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. }
  \end{figure}


\end{document}

which produces:

enter image description here

How can I get rid of this indentation? (I still want to keep these packages if possible...)

4

You could set the value of \RaggedRightParindent to zero for all figure and table environments by adding the following three lines of code in the preamble:

\usepackage{etoolbox}
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}

A full MWE:

enter image description here

\documentclass{scrreprt}
\usepackage {mwe}

\usepackage[document]{ragged2e}
\setlength{\RaggedRightParindent}{2em}

\usepackage{subcaption}
\setcapindent{0em}

\usepackage{etoolbox}
\AtBeginEnvironment{figure}{\setlength{\RaggedRightParindent}{0em}}
\AtBeginEnvironment{table}{\setlength{\RaggedRightParindent}{0em}}

\begin{document}

\section{title}

\lipsum[11]

\begin{figure}[h!]
  \centering
  \includegraphics[width=0.4\linewidth]{example-image}
  \caption{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.}
\end{figure}

\begin{table}[h!]
  \centering 
  \begin{tabular}{ccc}
  \hline
  u & v & w\\
  \hline
  \end{tabular}
  \caption{The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.}
\end{table}

\lipsum[2-3]

\end{document}

1
  • Odd, this works for the MWE, but didn't for my larger document. Something else is muddying the waters. I have put \AtBeginEnvironment{figure}{\setcapindent{0em}} as well, and that does it. Nov 17 '14 at 5:04
5

Define a caption style:

\documentclass{scrreprt}

\usepackage[document]{ragged2e} % for creating ragged right edge etc
\usepackage{caption}% for creating figures in figures

\setlength{\RaggedRightParindent}{2em}% sets the indent size of the first line

\DeclareCaptionFormat{komaflush}{\noindent\hspace{-\RaggedRightParindent}#1#2#3\par}
\captionsetup{format=komaflush}

\begin{document}

\section{title}

\lipsum[11-12]


\begin{figure}[tbh]
\centering

\includegraphics[width=0.4\linewidth]{example-image}

\caption{The quick brown fox jumps over the lazy dog. The quick brown
  fox jumps over the lazy dog. The quick brown fox jumps over the lazy
  dog. The quick brown fox jumps over the lazy dog.}

\end{figure}


\end{document}

enter image description here

5
  • Thanks, this is a tidy solution. I get some overlap of figure and caption text when using a \captionbeside environment though, any idea why? And where is \DeclareCaptionFormat from? Nov 17 '14 at 10:54
  • @adifferentben I don't know about \captionbeside; \DeclareCaptionFormat is part of caption.
    – egreg
    Nov 17 '14 at 10:59
  • \captionbeside is an environment from the KOMA-Script classes. Allows floats to have their captions placed beside them :) It has some additional width and placement options (see page 115 for version 2012-07-22 of the docs). Nov 17 '14 at 23:30
  • @adifferentben I understand it, but I won't try and guess how you're using it.
    – egreg
    Nov 17 '14 at 23:34
  • @adifferentben My impression is that \RaggedRight thoroughly confuses captionbeside.
    – egreg
    Nov 17 '14 at 23:54

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.