Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

as stated in title.

\documentclass{article}

\usepackage{algorithm}
% Need it for floating environment
\usepackage[noend]{algpseudocode} 
% Hide endif .etc
\usepackage{caption}
% Need it for \caption*
\usepackage{xspace}
% Fix macro spacing bug

\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}
\algrenewcommand{\algorithmicensure}{\textbf{Output:}}
\algrenewcommand{\algorithmicforall}{\textbf{for each}}
% \algrenewcommand instead of \renewcommand according to manual
\newcommand{\To}{\textbf{to}\xspace}
% Not stated in manual, \Return and \algorithmicreturn are defined, but no \algorithmicstate, why?
\newcommand{\Dosth}{\State \textbf{Do Something}\xspace}
% Note no space before \xspace
\newcommand{\Please}[1]{\State \textbf{#1}}
\newcommand{\ForEach}{\ForAll}
% Fail to use \algorithmicforall, why?
\begin{document}

\begin{algorithm}
    \caption*{\textbf{Algorithm:} \textsc{Depth First Search}} \label{alg:dfs1}

    \begin{algorithmic}[1]

        \Function{DFS}{$v$}
            \State $count \gets count + 1$
            \Please{mark} $v$ with $count$
            \Dosth with $v$
            \ForEach{vertex $w \in \mathcal{V}$ adjacent to $v$}
                \If{$w$ is marked with $0$} \Comment Only needed to exclude its parent.\footnotemark
                    \State \Call{DFS}{$w$}
                \EndIf
            \EndFor
            \State \Return
        \EndFunction

    \end{algorithmic}
\end{algorithm}
\footnotetext{No sibling is visited before the loop. Each sibling will be visited exactly once due to the nature of the loop.}

\end{document}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

One option would be to use the H placement specifier (provided by the algorithm package through the float package), thus allowing the inclusion of the algorithm environment inside a minipage (of course, algorithm won't float anymore); now, the standard \footnote command can be used to place the footnote.

\documentclass{article}

\usepackage{algorithm}
% Need it for floating environment
\usepackage[noend]{algpseudocode} 
% Hide endif .etc
\usepackage{caption}
% Need it for \caption*
\usepackage{xspace}
% Fix macro spacing bug

\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}
\algrenewcommand{\algorithmicensure}{\textbf{Output:}}
\algrenewcommand{\algorithmicforall}{\textbf{for each}}
% \algrenewcommand instead of \renewcommand according to manual
\newcommand{\To}{\textbf{to}\xspace}
% Not stated in manual, \Return and \algorithmicreturn are defined, but no \algorithmicstate, why?
\newcommand{\Dosth}{\State \textbf{Do Something}\xspace}
% Note no space before \xspace
\newcommand{\Please}[1]{\State \textbf{#1}}
\newcommand{\ForEach}{\ForAll}
% Fail to use \algorithmicforall, why?
\begin{document}


\noindent\begin{minipage}{\textwidth}
\begin{algorithm}[H]
    \caption*{\textbf{Algorithm:} \textsc{Depth First Search}} \label{alg:dfs1}
    \begin{algorithmic}[1]

        \Function{DFS}{$v$}
            \State $count \gets count + 1$
            \Please{mark} $v$ with $count$
            \Dosth with $v$
            \ForEach{vertex $w \in \mathcal{V}$ adjacent to $v$}
                \If{$w$ is marked with $0$} \Comment Only needed to exclude its parent.\footnote{No sibling is visited before the loop. Each sibling will be visited exactly once due to the nature of the loop.}
                    \State \Call{DFS}{$w$}
                \EndIf
            \EndFor
            \State \Return
        \EndFunction

    \end{algorithmic}
\end{algorithm}
\renewcommand\footnoterule{}
\end{minipage}

\end{document}

EDIT: initially I explicitly loaded the float package to use the H specifier; this is not necessary, since algorithm internally uses float.

EDIT2: there's no need to use \mpfootnotemark; the standard \footnote command can be used inside the minipage.

share|improve this answer
    
very helpful –  colinfang May 17 '11 at 18:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.