0

I am trying to add footnotes at the end of an algorithm environment (not at the end of the page). I found this post where this is done but there are no numbers to refer to the footnote. So if I want to add several footnotes within an algorithm I need to be able to differentiate them. Is this remotely possible? I've seen people doing this for tables here and here.

UPDATE

Following this answer I managed to do what I wanted. The following code

\documentclass{article}
\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[hang,flushmargin]{footmisc}
\usepackage{caption}
\begin{document}
\noindent\begin{minipage}{\textwidth}
\renewcommand\footnoterule{}                  %% This line should come here.
\begin{algorithmic}
\If {$i\geq maxval$}
    \State $i\gets 0$ \footnote{\label{note1}1\textsuperscript{st} footnote test}
\Else
    \If {$i+k\leq maxval$}
        \State $i\gets i+k$ \footnote{2\textsuperscript{nd} footnote test}
        \State $w\gets i$ 
    \EndIf
\EndIf
\end{algorithmic}
\end{minipage}
\end{document}

Gives me:

result

But I am still not done as I would like to refer to some existing footnote inside the algorithm. I then found this other post that can help me reference another footnote using \footnotemark command. However, I can't manage to get around the error:

./algorithm.tex:19: Missing number, treated as zero.
<to be read again> 
                   \protect 
l.19 ...tate $w\gets i$ \footnotemark[\ref{note1}]

The new code I'm using now is:

\documentclass{article}
\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[hang,flushmargin]{footmisc}
\usepackage{caption}
\begin{document}
\noindent\begin{minipage}{\textwidth}
\renewcommand\footnoterule{}                  %% This line should come here.
\begin{algorithmic}
\If {$i\geq maxval$}
    \State $i\gets 0$ \footnote{\label{note1}1\textsuperscript{st} footnote test}
\Else
    \If {$i+k\leq maxval$}
        \State $i\gets i+k$ \footnote{2\textsuperscript{nd} footnote test}
        \State $w\gets i$ \footnotemark[\ref{note1}]
    \EndIf
\EndIf
\end{algorithmic}
\end{minipage}
\end{document}
aaragon
  • 3,041

0 Answers0