알고리즘과 알고리즘2e의 목차를 함께

알고리즘과 알고리즘2e의 목차를 함께

알고리즘의 내용은 사용하는 알고리즘이 algorithm하나의 알고리즘이고 사용하는 알고리즘이 algorithm2e다른 알고리즘이라고 생각하며, 다른 패키지와 함께 가져온 두 번째 알고리즘이 아니라 다른 엔터티 또는 무언가라고 생각합니다. 제 생각에는 괜찮지 않습니다. .

나는 이것을 원한다:

  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, 논문의 알고리즘은 algorithm및 로 작성됩니다 algorithmic. 내일 아침에 먼저 제출해야 해서 다시 작성할 시간이 없습니다(지금 다른 섹션에서 논문을 편집 중입니다). 그래서 여기 커뮤니티에서 해결책을 듣거나 알고리즘을 그만둘 예정입니다. 내 논문 밖의 논문!

답변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}

관련 정보