동적 카운터 값 저장

동적 카운터 값 저장

다음 항목 구성을 얻고 싶습니다.

  • 섹션 A
    • 카테고리 1
      • 항목 1.1
      • 항목 1.2
    • 카테고리 2
      • 항목 2.1
  • 섹션 B
    • 카테고리 1
      • 항목 1.3
      • 항목 1.4
    • 카테고리 2
      • 항목 2.2
      • 항목 2.3
  • 섹션 C
    • 카테고리 1
      • 항목 1.5
    • 카테고리 2
      • 항목 2.4
      • 항목 2.5
      • 항목 2.6

다음과 같은 코드를 사용합니다.

\section{A}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}

\section{B}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}

\section{C}
\resetcategories
    \nextcategory
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}
        \myitem{}

따라서 각 동적 범주 내에 하나의 동적 항목 카운터가 있지만 해당 값은 저장되며 범주 카운터가 재설정되는 경우에도 다시 시작할 수 있습니다.

사용자 정의 카운터나 변수를 사용하여 이를 달성할 수 있는 깔끔한 방법이 있습니까?

답변1

TeX 레지스터를 사용한 일반적인 조작은 다음과 같습니다.

\newcount\catnum
\expandafter \newcount\csname itemnum1\endcsname
\expandafter \newcount\csname itemnum2\endcsname
\def\inum{itemnum\the\catnum}

\def\bull#1{\noindent\hskip#1\parindent
            \hangindent=#1\parindent
            \llap{$\bullet$\ }\ignorespaces
}
\def\section#1{\par\bull1 \catnum=0 section #1}
\def\nextcategory{\par\advance\catnum by1 \bull2 category \the\catnum}
\def\myitem{\par
   \advance\csname\inum\endcsname by1 \bull3
   item \the\catnum.\expandafter\the\csname\inum\endcsname}
\let\resetcategories=\relax

\section{A}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}

\section{B}
\resetcategories
    \nextcategory
        \myitem{}
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}

\section{C}
\resetcategories
    \nextcategory
        \myitem{}
    \nextcategory
        \myitem{}
        \myitem{}
        \myitem{}

\bye

답변2

아마도 '재개' 목록을 사용하는 것과 같은 것이 있을까요 enumitem?

\documentclass{article}
\usepackage{enumitem}

\newlist{sectionlist}{enumerate}{3}
\setlist[sectionlist,1]{label={\Alph*}}
\setlist[sectionlist,2]{label={\arabic*}}
\setlist[sectionlist,3]{label*={.\arabic*}}


\begin{document}
\begin{sectionlist}
\item Section

  \begin{sectionlist}
  \item Category 
    \begin{sectionlist}[series=first]
    \item Foo
    \item Other Foo
    \end{sectionlist}
  \item Category
    \begin{sectionlist}[series=second]
    \item Foo
    \item Other Foo
    \end{sectionlist}
  \end{sectionlist}

\item Section

  \begin{sectionlist}
  \item Category 

    \begin{sectionlist}[resume=first]
    \item Foo
    \item Other Foo
    \end{sectionlist}

  \item Category 
    \begin{sectionlist}[resume=second]
    \item Foo
    \item Other Foo
    \item Yet another foo
    \end{sectionlist}
  \end{sectionlist}



\item Section

  \begin{sectionlist}
  \item Category 

    \begin{sectionlist}[resume=first]
    \item Foo
    \item Other Foo
    \item Yet another foo
    \end{sectionlist}

  \item Category 
    \begin{sectionlist}[resume=second]
    \item Foo
    \item Other Foo
    \item Yet another foo
    \item Even yet another foo
    \end{sectionlist}
  \end{sectionlist}



\end{sectionlist}


\end{document}

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

관련 정보