패키지 알고리즘의 줄바꿈2e

패키지 알고리즘의 줄바꿈2e

나는알고리즘2e의사코드용 패키지. 포장해야 할 매우 긴 줄이 생겼습니다. 줄 바꿈이 발생했음을 알리기 위해 다음(깨진) 줄을 들여쓰거나 첫 번째 줄에 표시를 하는 방법이 있습니까?목록 패키지 솔루션)

비슷한 것을 찾았어요질문목록 패키지에 대해서는 이전에 답변을 받았지만 명시적으로알고리즘2e해결책.

답변1

다음 최소 예는 다음을 정의합니다.

  • \nosemic: 줄 끝(EOL) 문자 인쇄를 제거합니다(일반적으로 ;).
  • \dosemic: EOL 문자 인쇄를 복원합니다.
  • \pushline: 한 줄씩 들여쓰기 1em(일반적인 들여쓰기); algorithm2e에 의해 제공됨 \Indp;
  • \popline: 들여쓰기를 제거합니다 \pushline(들여쓰기?); algorithm2e에 의해 제공됨\Indm

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{algorithm2e}% http://ctan.org/pkg/algorithm2e
\makeatletter
\newcommand{\nosemic}{\renewcommand{\@endalgocfline}{\relax}}% Drop semi-colon ;
\newcommand{\dosemic}{\renewcommand{\@endalgocfline}{\algocf@endline}}% Reinstate semi-colon ;
\newcommand{\pushline}{\Indp}% Indent
\newcommand{\popline}{\Indm\dosemic}% Undent
\makeatother
\begin{document}
\begin{algorithm}[H]
  \SetAlgoLined
  \KwData{this text}
  \KwResult{how to write algorithm with \LaTeX2e }
    initialization\;
  \While{not at end of this document}{
    read current\;
    \eIf{understand}{
      go to next section\;
      \nosemic this is a very long statement that has to be\;
        \pushline\dosemic wrapped over two lines\;
      \popline current section becomes this one\;
    }{
      go back to the beginning of current section\;
    }
  }
  \caption{How to write algorithms}
\end{algorithm}
\end{document}​

나는 당신이 낯설기 때문에algorithm2e설정, 네 가지 명령을 어떻게 결합하고 싶은지 잘 모르겠습니다. 따라서 최대(아직 수동) 사용을 위해 별도로 보관했습니다.

답변2

실제로 더 간단한 해결책이 있습니다. 즉, 클래식 \hangafter\hangindent. 이것은 algorithm2e.

노트:

  1. \skiptext새 블록에 대한 알고리즘에서 텍스트 들여쓰기의 길이입니다. 그래서 저는 이 들여쓰기의 1/2을 선택합니다.

  2. \algocf@endline에서 거의 모든 매크로를 재정의할 수 있으므로 내부 매크로를 재정의할 필요가 없습니다 algorithm2e. \SetEndCharOfAlgoLine줄 끝을 재정의하는 데 사용

\hangafter및 사용 예는 아래를 참조하세요 \hangindent.

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{algorithm2e}% http://ctan.org/pkg/algorithm2e
%
\newcommand{\nosemic}{\SetEndCharOfAlgoLine{\relax}}% Drop semi-colon ;
\newcommand{\dosemic}{\SetEndCharOfAlgoLine{\string;}}% Reinstate
\newcommand{\pushline}{\Indp}% Indent
\newcommand{\popline}{\Indm\dosemic}% Undent
%
\begin{document}
\begin{algorithm}[H]
  \SetAlgoLined
  \KwData{this text}
  \KwResult{how to write algorithm with \LaTeX2e }
    initialization\;
  \While{not at end of this document}{
    read current\;
    \eIf{understand}{
      go to next section\;
      \nosemic this is a very long statement that has to be\;
        \pushline\dosemic wrapped over two lines\;
      \popline current section becomes this one\;
      \hangindent=.5\skiptext\hangafter=1
      this is a very long statement that should be indented automatically on the next
      lines if this statement is longer than one line\;
      Following lines should be indented normally\;
    }{
      go back to the beginning of current section\;
    }
  }
  \caption{How to write algorithms}
\end{algorithm}
\end{document}​

답변3

\Indp들여쓰기 및 들여쓰기 제거를 위해 \Indm패키지에서 사용할 수 있습니다 . algorithm2e나는 그것을 테스트했다.

관련 정보