Algorithm2e 中帶有小寫字母的過程名稱

Algorithm2e 中帶有小寫字母的過程名稱

我知道procedurealgorithm2e允許使用像\caption{ProcedureName()}.

但是,我希望我的程式以小寫字母顯示:

\documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[algosection, boxruled, linesnumbered]{algorithm2e}

\begin{document}
\begin{procedure}

    \SetKwInOut{Input}{input}
    \SetKwInOut{Output}{output}
    \Input{Graph $G = (V,E)$}
    \Output{}
    \ForEach{node $v \in V$}
    {
        \lIf{$v$ is marked}{remove $v$}
    }

    \caption{\textsc{removemarked()}}
    \label{alg:removemarked}

\end{procedure}
\end{document}

這當然會給出錯誤

Paragraph ended before \algocf@captname was complete

如果我使用 ,而不是過程\begin{algorithm} ... \end{algorithm},那麼它會很好地分叉。有沒有辦法讓它procedure也能運作?

答案1

手冊中並沒有很好的記錄algorithm2e,但是為了實現你想要的,你必須發出命令

\SetProcNameSty{textsc}

\caption使用環境時的參數procedure只能包含類似的內容name(arg)

在下面的 MWE 中我還添加了

\SetProcArgSty{textsc}

以防萬一您使用帶有參數的流程標題:

\documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[algosection, boxruled, linesnumbered]{algorithm2e}

\SetProcNameSty{textsc}
\SetProcArgSty{textsc}

\begin{document}
\begin{procedure}

    \SetKwInOut{Input}{input}
    \SetKwInOut{Output}{output}
    \Input{Graph $G = (V,E)$}
    \Output{}
    \ForEach{node $v \in V$}
    {
        \lIf{$v$ is marked}{remove $v$}
    }

    \caption{removemarked()}
    \label{alg:removemarked}

\end{procedure}
\end{document} 

輸出

在此輸入影像描述

相關內容