如何将算法块放入小页面中,以便在块之后立即显示脚注

如何将算法块放入小页面中,以便在块之后立即显示脚注

如标题所述。

\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}

答案1

一种选择是使用H位置说明符(由algorithm包通过包提供float),从而允许将环境包含algorithm在内minipage(当然,algorithm不会再浮动);现在,\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}

编辑:最初我明确加载了float包以使用H说明符;这不是必需的,因为algorithm内部使用float

EDIT2:没有必要使用\mpfootnotemark;标准\footnote命令可以在里面使用minipage

相关内容