카운터를 공유하는 두 개의 반독립적인 자료 목록을 만듭니다.

카운터를 공유하는 두 개의 반독립적인 자료 목록을 만듭니다.

나는 성공적으로 을 사용하여 \newlistof{listofA}{A}{List of As}내용 \newlistentry{mycounter}{A}{0}이 추가되는 A의 목록을 만들었습니다 \addcontentsline{A}{mycounter}{\protect\numberline{\themycounter}...}. 이제 나는 counter 를 공유하는 B 목록을 갖고 싶습니다 mycounter. 나는 가지고있다 \newlistof{listofB}{B}{List of Bs}. \newlistentry{mycounter}{B}{0}몇 가지로 실패합니다 Command ... already defined. 그것 없이는 \addcontentsline{B}{mycounter}{...}, 둘 다목록이 비어 있는 것으로 나타납니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변1

패키지를 사용하면 xassoccnt여러 카운터를 연결하는 것이 가능합니다. 즉, 카운터 중 하나가 계단형이면 다른 카운터도 계단형이 됩니다.

'임의의' 이름을 사용하여 카운터 그룹을 선언하고 관련 카운터를 할당합니다.

\newlistof존재하지 않는 카운터를 예상 foo하고 카운터 이름에서 여러 명령을 생성하므로 동일한 카운터를 사용하는 것은 불가능합니다 .

\documentclass{article}

\usepackage{tocloft}
\usepackage{xassoccnt}

\usepackage{blindtext}


\newcommand{\listoffooname}{List of foo environments}
\newcommand{\listoffoobarname}{List of foobar environments}

\newlistof[section]{foo}{foo}{\listoffooname}
\newlistof[section]{foobar}{foobar}{\listoffoobarname}

\DeclareCoupledCountersGroup{foofoobar}
\DeclareCoupledCounters[name=foofoobar]{foo,foobar}


% Dummy usage of the counter and generating a 'ToC' entry
\newenvironment{foo}[1]{%
  \refstepcounter{foo}
  \par\noindent\textbf{Foo \thefoo. #1}
  \addcontentsline{foo}{foo}{\protect\numberline{\thefoo} #1}\par%
}{\hrule}

\newenvironment{foobar}[1]{%
  \refstepcounter{foobar}
  \par\noindent\textbf{Foobar \thefoobar. #1}
  \addcontentsline{foobar}{foobar}{\protect\numberline{\thefoobar} #1}\par%
}{\hrule}



\begin{document}
\listoffoo
\listoffoobar


\section{Where foo starts}

\begin{foo}{A nice foo}

\blindtext[2]
\end{foo}

\begin{foobar}{A nice foobar}

\blindtext[2]
\end{foobar}


\begin{foo}{A nice foo again}

\blindtext[2]
\end{foo}

\begin{foo}{A nice foo again}

\blindtext[2]
\end{foo}

\begin{foobar}{A nice foobar again}

\blindtext[2]
\end{foobar}




\section{Where foo ends}

\begin{foo}{Another nice foo too}

\blindtext[1]
\end{foo}

\begin{foobar}{Another nice foobar}

\blindtext[2]
\end{foobar}




\end{document}

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

관련 정보