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}
  • Did you try wrapping your algorithm in a minipage environment? – ig0774 Apr 5 '16 at 8:41
  • Yes, I tried but nothing. – aaragon Apr 5 '16 at 8:42
  • I have added a MWE that produces a footnote that's placed at the end of the page. – aaragon Apr 5 '16 at 8:50
  • Your MWE is using the savenotes environment which has the explicit goal of ensuring footnotes are typeset at the bottom of the page. Otherwise Harish Kumar's answer seems to get the desired effect (albeit at the cost of making the float fixed), i.e., wrap the entire algorithm environment in a minipage and set \footnoterule to {} – ig0774 Apr 5 '16 at 9:19
  • His approach doesn't have numbers associated with the footnote though. – aaragon Apr 5 '16 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.