# Include a line break in algorithm-caption while maintaining indentation

I've a question about the alignment of the caption in an algorithm-environment. For instance, the following code-example

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\begin{document}
\begin{algorithm}[t]
\caption{Text Text\newline Text}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}
\end{document}


produces

However, the third "Text" should be directly under the first "Text". How can I accomplish this?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Mar 13 '15 at 10:54

You can use the caption package with a hanging indent style as follows:

\documentclass{article}

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{caption}

\captionsetup[algorithm]{format=hang,singlelinecheck=false}

\begin{document}

\begin{algorithm}[t]
\caption{Text Text\newline Text}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[t]
\caption{Text text text text text text text text text text text text
text text text text text text text text text text text text\newline
More text}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}

\end{document}

• Thank you both for your answers. Why do you use singlelinecheck=false? This doesn't change anything in my captions. Mar 13 '15 at 11:23
• Without singlelinecheck=false the first example with a short caption doesn't get a hanging indent after the \newline. Mar 13 '15 at 11:26
• I, too, have tried with format=hang but I forgot about singlelinecheck=false :( +1. BTW: hangindent=0pt is superflous. :-) Mar 13 '15 at 11:38
• @karlkoeller You are right about the hangindent=0pt; the internals of the caption set up styles do indeed set this to 0pt, so it is unnecessary and I have now removed it from the code. It would be nice if the documentation told us about the default value. Mar 13 '15 at 11:44

Load the caption package and declare:

\DeclareCaptionFormat{custom}{%
\begin{minipage}[t]{0.2\linewidth}\vspace*{0pt}#1#2\end{minipage}%
\begin{minipage}[t]{0.8\linewidth}\vspace*{0pt}#3\end{minipage}%
}


After that,

\captionsetup[algorithm]{format=custom}


MWE:

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\usepackage{caption}
\DeclareCaptionFormat{custom}{%
\begin{minipage}[t]{0.2\linewidth}\vspace*{0pt}#1#2\end{minipage}%
\begin{minipage}[t]{0.8\linewidth}\vspace*{0pt}#3\end{minipage}%
}
\captionsetup[algorithm]{format=custom}

\begin{document}
\begin{algorithm}[t]
\caption{Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text\newline Text on a new line}
\begin{algorithmic}[1]
\State bla
\end{algorithmic}
\end{algorithm}

\end{document}