카운터 값에 따라 환경의 카운터가 표시되는 방식이 달라지는 환경이 필요합니다. 카운터가 10보다 작으면 뒤에 서수 표시 "º"가 와야 하며, 그렇지 않으면 서수 표시 없이 인쇄됩니다.
이 작업을 수행하기 위해 amsthm
및 패키지를 사용해 보았습니다 .ifthen
\newtheorem{artigo}{Art.}
\renewcommand{\theartigo}{%
\ifx\artigo<10%
\arabic{artigo}º%
\else%
\arabic{artigo}%
\fi%
}
하지만 작동하지 않습니다. “Art. 1” 대신 “Art. 1º”, 환경을 사용할 때 artigo
.
내가 도대체 뭘 잘못하고있는 겁니까?
답변1
정수 값에 대한 테스트는 다음과 같이 수행됩니다.
\ifnum counter value [relation] number ... \else ... \fi
즉
\ifnum\value{artigo} < 10
true branch
\else
false branch
\fi
또는 다음을 사용할 수 있습니다.
\makeatletter
\renewcommand{\theartigo}{%
\ifnum\c@artigo<10
\arabic{artigo}º%
\else
\arabic{artigo}
\fi
}
\makeatother
매크로를 제거하려면 \value{artigo}
의 가격이 필요하므로 \makeatletter...\makeatother
입력 시 비용이 절약되지 않습니다. ;-) ( \c@artigo
카운터 값을 보유하는 내부 카운터 매크로입니다)
\documentclass{article}
\usepackage[utf8]{inputenc}
\newtheorem{artigo}{Art.}
\renewcommand{\theartigo}{%
\ifnum\value{artigo}<10
\arabic{artigo}º%
\else
\arabic{artigo}%
\fi
}
\begin{document}
\begin{artigo}
Foo
\end{artigo}
\setcounter{artigo}{9}
\begin{artigo}
Foo again
\end{artigo}
\end{document}