3

I am trying to get write an algorithm in LaTeX for minimal document class. Unfortunately, the indentation is completely missing. Following is my sample code:

\documentclass{minimal}
\usepackage{algorithm2e}
\usepackage{algorithmic}
\usepackage{pslatex}

\special{papersize=36in,24in}
\setlength{\paperwidth}{36in}
\setlength{\paperheight}{24in}
\topskip0pt

\begin{document}

\begin{algorithm}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
 initialization\;
\While{not at end of this document}{
 read current\;
\eIf{understand}{
 go to next section\;
 current section becomes this one\;
 }{
 go back to the beginning of current section\;
 }
}
\end{algorithm}
\end{document}

This is how it currently appears using document class - minimal:

enter image description here

This is how want it to appear:

enter image description here

How do I fix this?

2
  • 2
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. The minimal class misses a lot of definitions that you would take for granted. Do you really have to use that class? If so, why? There may be a workaround using a more complete class, such as article.
    – jub0bs
    Jul 31, 2013 at 22:53
  • 1
    The minimal class is not really meant for real documents; see this answer.
    – jon
    Aug 1, 2013 at 18:31

1 Answer 1

2

The minimal document class is the problem, since two important lengths are not updated properly. They are \skiptext and \skiprule. Setting these to the defaults:

\setlength{\skiptext}{10pt}
\setlength{\skiprule}{5pt}

restores the alignment. Other things may also require updating, which all points to not using minimal in general. article would work just as well.

enter image description here

\documentclass{minimal}
\usepackage{algorithm2e}% http://ctan.org/pkg/algorithm2e
\setlength{\skiptext}{10pt}
\setlength{\skiprule}{5pt}

\begin{document}

\begin{algorithm}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
 initialization\;
\While{not at end of this document}{
 read current\;
\eIf{understand}{
 go to next section\;
 current section becomes this one\;
 }{
 go back to the beginning of current section\;
 }
}
\end{algorithm}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .