
규칙이 마지막 환경만 활성화해야 하는 TeX 매크로를 사용하여 조건을 설정하는 방법은 무엇입니까 test
?
문서에 규칙이 하나만 포함되어 있다고 가정해 보겠습니다 \begin{test}...\end{test}
.
\begin{test}...\end{test}
문서 규칙에 여러 개가 포함된 경우 마지막에만 활성화해야 합니다 \begin{test}...\end{test}
.
내 MWE 파일을 찾으십시오.
\documentclass{book}
\pagestyle{empty}
\makeatletter
\newif\ifruletest\global\ruletestfalse
\newcounter{testcounter}
\setcounter{testcounter}{0}
\newenvironment{test}{\noindent\parindent0pt}
{\par\stepcounter{testcounter}
\ifnum\value{testcounter}>0\rule{\textwidth}{1bp}\global\ruletestfalse\else\fi\bigskip}
\makeatother
\begin{document}
\begin{test}
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
\end{test}
\begin{test}
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
\end{test}
\begin{test}
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
\end{test}
\end{document}
답변1
당신이 사용할 수있는 totcount
; 환경 수가 test
변경되면 LaTeX를 두 번 실행해야 합니다.
\documentclass{book}
\usepackage{totcount}
\newtotcounter{testcounter}
\newenvironment{test}
{\par\setlength{\parindent}{0pt}}
{\par\stepcounter{testcounter}
\ifnum\totvalue{testcounter}=\value{testcounter}%
\nobreak\rule{\textwidth}{1bp}\bigskip
\fi}
\begin{document}
\begin{test}
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
\end{test}
\begin{test}
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
\end{test}
\begin{test}
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
Sample text Sample text Sample text Sample text
\end{test}
\end{document}