1

I have the following code:

\documentclass[12pt,a4paper,twoside]{book}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm*}[t!]
\caption{caption}
\begin{algorithmic}[1]
\Require{require} 
\State {testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt} 
\Return{return a}
\end{algorithmic}
\end{algorithm*}
\end{document}

How can I break a line in a \State and begin new line at the same indent as the previous line?

Kostas
  • 738

1 Answers1

3

It's done automatically:

\documentclass[12pt,a4paper,twoside]{book}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm*}[t!]
\caption{caption}
\begin{algorithmic}[1]
\Require{require}
\State {test tttt tttt tttt tttt tttt tttt tttt tttt tttt tttt
        tttt tttt tttt tttt tttt tttt tttt tttt tttt tttt tttt}
\Return{return a}
\end{algorithmic}
\end{algorithm*}
\end{document}

enter image description here

egreg
  • 1,121,712
  • Thanks! However, this doesn't seem to work in all cases. See this question: https://tex.stackexchange.com/questions/398733/make-algpseudocode-continued-line-have-the-same-indention-as-existing-line – pir Oct 30 '17 at 16:22
  • @pir That's a bug in algpseudocode, as far as I can see. Or the idea is that paragraphs are not allowed in \While – egreg Oct 30 '17 at 16:57
  • 1
    Okay, any idea how to fix that? – pir Oct 30 '17 at 20:05
  • Do you think it would work if I switched to another package similar to algpseudocode? – pir Oct 30 '17 at 20:31
  • This worked for me: https://tex.stackexchange.com/questions/314023/how-to-indent-a-long-sentence-in-an-algorithm – rnoodle May 07 '18 at 16:54