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?

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

5
  • Thanks! However, this doesn't seem to work in all cases. See this question: tex.stackexchange.com/questions/398733/…
    – 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: tex.stackexchange.com/questions/314023/…
    – rnoodle
    May 7 '18 at 16: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.