
LaTeX용 의사 코드 패키지가 많이 있습니다. C의 연결된 목록 노드와 같은 것을 설명할 수 있는 것이 있습니까?
struct Node
{
Node* parent;
// other stuff
};
아니면 맞춤 매크로를 만들어야 하나요?
답변1
을 사용한 한 가지 가능한 접근 방식은 다음과 같습니다 algorithm2e
. MyStruct
나는 키워드로 시작하고 Struct
구조 이름을 조판한 다음 키워드를 출력하고 contains
구조의 끝을 키워드로 표시하는 "프로그램과 같은" 블록을 정의했습니다 end
.
\SetKwProg{MyStruct}{Struct}{ contains}{end}
이 모든 것은 원하는 대로 맞춤 설정할 수 있습니다.
알고리즘 내에서의 사용법은 다음과 같습니다.
\MyStruct{Node}{
Node* parent\;
int size\;
\tcp{other stuff}
}
다음은 완전한 간단한 예제와 출력입니다.
\documentclass{article}
\usepackage{algorithm2e}
\SetAlgoLined
\SetKwProg{MyStruct}{Struct}{ contains}{end}
\begin{document}
\begin{algorithm}[H]
\MyStruct{Node}{
Node* parent\;
int size\;
\tcp{other stuff}
}
\end{algorithm}
\end{document}
이 정의는 전역 패키지 옵션과 로컬 스위치를 고려하므로 예를 들어 [noend,noline]
패키지 옵션으로 사용하여 end
키워드의 조판과 블록을 구분하는 수직선을 비활성화할 수 있습니다.
\documentclass{article}
\usepackage[noend,noline]{algorithm2e}
\SetAlgoLined
\SetKwProg{MyStruct}{Struct}{ contains}{end}
\begin{document}
\begin{algorithm}[H]
\MyStruct{Node}{
Node* parent\;
int size\;
\tcp{other stuff}
}
\end{algorithm}
\end{document}