アルゴリズムとアルゴリズム2eの目次

アルゴリズムとアルゴリズム2eの目次

アルゴリズムの内容は、使用するアルゴリズムがalgorithm1 つのアルゴリズムであり、使用するアルゴリズムがalgorithm2e別のアルゴリズムであると考えられています。これは、他のパッケージでインポートされたものの 2 番目ではなく、異なるエンティティなどであり、私の意見では、問題があります。

私はこれが欲しい:

  1 algo 1..................... page of algo 1
1 algo 2..................... page of algo 2

次のように変更します:

1 algo 1..................... page of algo 1
2 algo 2..................... page of algo 2

上記の配置と番号付けが変更されました。

以下は、最小限の例です。これ質問:

\documentclass{article}
\usepackage{algorithm} 
\usepackage{algorithmic}  
\usepackage[algo2e]{algorithm2e} 
\renewcommand{\listalgorithmname}{List of Algorithms}
\addtocontents{loa}{\protect\thispagestyle{empty}}

\begin{document}
    \listofalgorithms
    \smallskip
    \begin{algorithm}%>- from algorithm package
        test
        \caption{algo 1}
    \end{algorithm}

    \begin{algorithm2e}%>- from algorithm2e package
        test
        \caption{algo 2}
    \end{algorithm2e}
\end{document}

出力: ここに画像の説明を入力してください


クロニクル

論文は準備できていました。しかし、昨夜、論文に基づいた論文を提出しました。私も論文を提出しなければなりませんが、論文に書かれたアルゴリズムのいくつかを論文に含めたいと思っています。いくつかの理由から、誰かが私の問題の解決策を提示するか、論文のアルゴリズムなしで論文を残すかという状況に陥りました。もちろん、これでは論文は悲嘆に暮れることになります。:)

論文のアルゴリズムは で書かれていますalgorithm2eが、学位論文のアルゴリズムは と で書かれていますalgorithmalgorithmic明日の朝一番で提出しなければならないので、書き直す時間がありません (現在、他のセクションで学位論文を編集中です)。そのため、ここでコミュニティから解決策を聞くか、論文のアルゴリズムを学位論文の外に残すことになります。

答え1

簡単な解決策は、\setcounter各アルゴリズム内で を使用することです。さらに、アルゴリズムをアルゴリズムのリストに揃えるには、コマンドを再定義し、必要な水平間隔で設定する\listof必要があります。コードは次のとおりです。\l@algocf\@dottedtocline

\documentclass{article}
\usepackage{algorithm} 
\usepackage{algorithmic}  
\usepackage[algo2e]{algorithm2e} 
\renewcommand{\listalgorithmname}{List of Algorithms}
\addtocontents{loa}{\protect\thispagestyle{empty}}

% add this to align the list of algorithms
\makeatletter
  \renewcommand*{\listof}[2]{%
    \@ifundefined{ext@#1}{\float@error{#1}}{%
      \@namedef{l@#1}{\@dottedtocline{1}{1em}{2.3em}}% line of the list (change from 1em to the desired value)
      \float@listhead{#2}%
      \begingroup\setlength{\parskip}{\z@}%
        \@starttoc{\@nameuse{ext@#1}}%
      \endgroup}}
  \renewcommand*\l@algocf{\@dottedtocline{1}{1em}{2.3em}}% line of the list (change from 1em to the desired value)
\makeatother

\begin{document}
    \listofalgorithms
    \smallskip
    \begin{algorithm}%>- from algorithm package
      \setcounter{algorithm}{0}% set the counter for the 1st algorithm
        test
        \caption{algo 1}
    \end{algorithm}

    \begin{algorithm2e}%>- from algorithm2e package
      \setcounter{algocf}{1}% set the counter for the 2nd algorithm
        test
        \caption{algo 2}
    \end{algorithm2e}

    \begin{algorithm}%>- from algorithm package
      \setcounter{algorithm}{2}% set the counter for the 3rd algorithm
        test
        \caption{algo 3}
    \end{algorithm}

    \begin{algorithm2e}%>- from algorithm2e package
      \setcounter{algocf}{3}% set the counter for the 4th algorithm
        test
        \caption{algo 4}
    \end{algorithm2e}
\end{document}

関連情報