
다음 코드가 있습니다.
\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
x $\longleftarrow$ 0\tcc*[r]{initialize x}
\uIf(\tcc*[r]{if comment}){condition 1}{
x $\longleftarrow$ 1\tcc*[r]{set x as 1}
}
\uElseIf(\tcc*[r]{else comment}){condition 2}{
x $\longleftarrow$ 2\;
}
\Else{
x $\longleftarrow$ 3\tcc*[r]{set x as 3}
}
\caption{First algorithm}
\end{algorithm}
\end{document}
이 PDF를 생성합니다.
두 개의 표시된 세미콜론과 표시된 빈 줄은 원하지 않습니다. 코드에서 무엇을 변경해야 하는지 도와주실 수 있나요?
답변1
주석이 줄을 끝내지 않는 경우 대신 f
선택적 인수로 사용해야 합니다 .\tcc*
r
MWE:
\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
x $\longleftarrow$ 0\tcc*[r]{initialize x}
\uIf(\tcc*[f]{if comment}){condition 1}{
x $\longleftarrow$ 1\tcc*[r]{set x as 1}
}
\uElseIf(\tcc*[f]{else comment}){condition 2}{
x $\longleftarrow$ 2\;
}
\Else{
x $\longleftarrow$ 3\tcc*[r]{set x as 3}
}
\caption{First algorithm}
\end{algorithm}
\end{document}
산출:
문서 에서 algorithm2e
:
\tcc*[r]
{오른쪽 정렬된 측면 코멘트,줄을 끝낸다(기본값)}: 주석 “la” C
~하는 동안
\tcc*[f]
{오른쪽으로 정당화된 댓글,엔드라인 없이; 예를 들어 "if-then-else" 매크로에 유용합니다.}: 주석 " la" C