2

I need to have some text place AFTER an algorithm. Here is an MVE:

\documentclass[12pt,addpoints]{exam}
\usepackage[section]{algorithm}
\usepackage{fixltx2e}
\usepackage{algpseudocode}

\begin{document}
Some text before the algortihm.
\begin{algorithm}   
    \caption {An algorithm.}
    \begin{algorithmic}[H]
        \Function{theAlgorithm}{} : 
        \State test
        \EndFunction\\
    \end{algorithmic}
\end{algorithm}
Some more text after the algorithm.
\end{document}

The output is formated this way:

Some text before the algorithm. Some text after the algorithm.
---THE ALGORITHM---

I want to have:

Some text before the algorithm.
---THE ALGORITHM---
Some text after the algorithm.

I have tried to put it in a figure with different placement constraints but so far nothing works.

Eric
  • 105
  • Algorithm is a float environnement. You should see this link: http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat – Romain Picot Dec 15 '15 at 07:16

2 Answers2

4

algorithm loads float which provides the [H] float specifier:

enter image description here

\documentclass{article}
\usepackage[section]{algorithm}
\usepackage{algpseudocode}

\begin{document}

\section{Some section}
Some text before the algortihm.
\begin{algorithm}[H]
  \caption{An algorithm.}
  \begin{algorithmic}
    \Function{theAlgorithm}{} : 
    \State test
    \EndFunction
  \end{algorithmic}
\end{algorithm}
Some more text after the algorithm.

\end{document}

Note that it's used with algorithm, not algorithmic (which is provided by algpseudocode).

In general, let floats do what they do best... float. However, it seems that you're using the exam document class, which might require some restrictions in terms of place. Regardless, considering reading the FAQ How to influence the position of float environments like figure and table in LaTeX?.

Werner
  • 603,163
0

It turns out that in my code I included \usepackage{fixltx2e} and that was prohibiting me to put the [H] options. After I removed the package and the error is gone and the text is displayed correctly.

Eric
  • 105