[Tex/LaTex] Include a line break in algorithm-caption while maintaining indentation

algorithmscaptionsline-breaking

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
enter image description here

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

Best Answer

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

Sample output

Longer sample

\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}