五级深度列表的后续问题

五级深度列表的后续问题

解决方案五级深度列表实现了一个扩展到 9 层嵌套的枚举列表。但是,对嵌套标签的引用没有列出扩展的嵌套位置。我在下面附上了一个例子。这可以实现吗? 对 myEnumerate 和 enumerate 标签的引用之间的区别。

\documentclass{article}
\usepackage{enumitem}
\setlistdepth{9}

\newlist{myEnumerate}{enumerate}{9}
\setlist[myEnumerate,1]{label=(\arabic*)}
\setlist[myEnumerate,2]{label=(\Roman*)}
\setlist[myEnumerate,3]{label=(\Alph*)}
\setlist[myEnumerate,4]{label=(\roman*)}
\setlist[myEnumerate,5]{label=(\alph*)}
\setlist[myEnumerate,6]{label=(\arabic*)}
\setlist[myEnumerate,7]{label=(\Roman*)}
\setlist[myEnumerate,8]{label=(\Alph*)}
\setlist[myEnumerate,9]{label=(\roman*)}

\begin{document}
\begin{myEnumerate}
\item 1st level
    \begin{myEnumerate}
    \item 2nd level
        \begin{myEnumerate}
        \item 3rd level
            \begin{myEnumerate}
            \item 4th level
                \begin{myEnumerate}
                \item 5th level
                    \begin{myEnumerate}
                    \item 6th level
                        \begin{myEnumerate}
                        \item 7th level
                            \begin{myEnumerate}
                            \item 8th level
                                \begin{myEnumerate}
                                    \item \label{9th level}9th level
                                \end{myEnumerate}
                            \end{myEnumerate}
                        \end{myEnumerate}
                    \end{myEnumerate}
                \end{myEnumerate}
            \end{myEnumerate}
        \end{myEnumerate}
    \end{myEnumerate}
\end{myEnumerate}
9th level is nested at position \ref{9th level}.

\begin{enumerate}
\item Level 1
    \begin{enumerate}
    \item Level 2
        \begin{enumerate}
        \item Level 3
            \begin{enumerate}
            \item\label{level 4} Level 4
            \end{enumerate}
        \end{enumerate}
    \end{enumerate}
\end{enumerate}
Level 4 is nested at \ref{level 4}.

\end{document}

答案1

您可以使用以下ref密钥:

\documentclass{article}
\usepackage{enumitem}
\usepackage{pgffor}
\setlistdepth{9}

\newlist{myEnumerate}{enumerate}{9}
\setlist[myEnumerate,1]{label=(\arabic*)}
\setlist[myEnumerate,2]{label=(\Roman*),
  ref=\themyEnumeratei(\Roman*)}
\setlist[myEnumerate,3]{label=(\Alph*),
  ref=\themyEnumerateii(\Alph*)}
\setlist[myEnumerate,4]{label=(\roman*),
  ref=\themyEnumerateiii(\roman*)}
\setlist[myEnumerate,5]{label=(\alph*),
  ref=\themyEnumerateiv(\alph*)}
\setlist[myEnumerate,6]{label=(\arabic*),
  ref=\themyEnumeratev(\arabic*)}
\setlist[myEnumerate,7]{label=(\Roman*),
  ref=\themyEnumeratevi(\Roman*)}
\setlist[myEnumerate,8]{label=(\Alph*),
  ref=\themyEnumeratevii(\Alph*)}
\setlist[myEnumerate,9]{label=(\roman*),
  ref=\themyEnumerateviii(\roman*)}

\begin{document}

\noindent\foreach \level in {1,...,9}
  {Level number \level\ is nested at position \ref{\level level}\par\noindent}

\begin{myEnumerate}
\item 1st level\label{1level}
    \begin{myEnumerate}
    \item 2nd level\label{2level}
        \begin{myEnumerate}
        \item 3rd level\label{3level}
            \begin{myEnumerate}
            \item 4th level\label{4level}
                \begin{myEnumerate}
                \item 5th level\label{5level}
                    \begin{myEnumerate}
                    \item 6th level\label{6level}
                        \begin{myEnumerate}
                        \item 7th level\label{7level}
                            \begin{myEnumerate}
                            \item 8th level\label{8level}
                                \begin{myEnumerate}
                                    \item \label{9level}9th level
                                \end{myEnumerate}
                            \end{myEnumerate}
                        \end{myEnumerate}
                    \end{myEnumerate}
                \end{myEnumerate}
            \end{myEnumerate}
        \end{myEnumerate}
    \end{myEnumerate}
\end{myEnumerate}
9th level is nested at position \ref{9level}.

\begin{enumerate}
\item Level 1
    \begin{enumerate}
    \item Level 2
        \begin{enumerate}
        \item Level 3
            \begin{enumerate}
            \item\label{level 4} Level 4
            \end{enumerate}
        \end{enumerate}
    \end{enumerate}
\end{enumerate}
Level 4 is nested at \ref{level 4}.

\end{document}

在此处输入图片描述

然而,这确实会让人困惑。你确定要用这么长的字符串进行交叉引用吗?

相关内容