2

I'm using the algorithmic package to write pseudocode in my homework assignments. I use the exam class to use the question environment it provides. But now I noticed that as soon as I use the algorithmic environment at the beginning of a question the number jumps a bit to the right, instead of nicely aligning with the other question numbers. Of course I'd prefer if all the question numbers would be on one vertical line. Below a MWE and the way that that looks like.

MWE

\documentclass{exam}
\usepackage{algorithmic}

\begin{document}
    \begin{questions}
        \question 

        \question
            \begin{algorithmic}
                insert algorithm pseudocode here
            \end{algorithmic}

        \question
    \end{questions}
\end{document}

enter image description here

By the way, I'm using TexStudio on Windows 8.1.

3

You example is a bit too minimal: The statements in the algorithmic environment should be preceded by a keyword, in the simplest case by \STATE. When you put this in front of your text, the indentations are ok.

\documentclass{exam}
\usepackage{algorithmic}
\begin{document}
\begin{questions}
  \question Question 1
  \question Question 2
    \begin{algorithmic}
    \STATE insert algorithm pseudocode here
    \PRINT something
    \end{algorithmic}
  \question Question 3
\end{questions}
\end{document}

enter image description here

  • Oh wow, how could I forget to add that? Thanks for pointing that out. – Abby Sep 7 '16 at 20:20

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.