Crea dos listas de material semiindependientes, que comparten su contador.

Crea dos listas de material semiindependientes, que comparten su contador.

Utilicé con éxito \newlistof{listofA}{A}{List of As}y \newlistentry{mycounter}{A}{0}para crear una lista de A, cuyo contenido se agrega usando \addcontentsline{A}{mycounter}{\protect\numberline{\themycounter}...}. Ahora quiero tener una lista de B que comparten el contador mycounter. Tengo \newlistof{listofB}{B}{List of Bs}. \newlistentry{mycounter}{B}{0}falla con unos pocos Command ... already defined. Sin él, usando \addcontentsline{B}{mycounter}{...}, amboslas listas aparecen vacías. ¿Qué estoy haciendo mal?

Respuesta1

Con el xassoccntpaquete es posible acoplar múltiples contadores, es decir, si uno de los contadores está escalonado, los demás también lo están.

Declare un grupo de contadores con algún nombre "arbitrario" y asígneles los contadores relevantes.

No es posible usar el mismo contador ya que, \newlistofpor ejemplo, espera un contador inexistente fooy genera un montón de comandos a partir del nombre del contador.

\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}

ingrese la descripción de la imagen aquí

información relacionada