嵌套列表 - 仅排版前 n 层

嵌套列表 - 仅排版前 n 层

我正在写大纲,有很多嵌套enumitem列表。有没有办法自动抑制更高列表级别的输出?例如:

\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{enumerate}[label=\alph*.]
  \item First point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...

如何通过仅打印第一级来打印我的大纲的简洁版本\items

答案1

更通用的方法完成所有enumerateitemize和,description并允许指定一个级别N

[暂时存在影响垂直间距的问题,现已修复。最终版本。]

\documentclass{article}
\usepackage{enumitem}

\makeatletter
% GENERAL PURPOSE ENVIRONMENT SWALLOWING
% #1 is the name of the surrounding environment
% we swallow everything until finding the correct \end
% then we reinject \end{#1}
\def\@scoop{\@scoop}

\long\def\scoop  #1#2\end #3{\def\scoop@env{#1}\scoop@i #2\begin\@scoop }

\long\def\scoop@i #1\begin #2{\def\scoop@tmp{#2}%
                        \ifx\scoop@tmp\@scoop
                             \expandafter\scoop@end
                        \else\expandafter\scoop@ii
                        \fi }

\long\def\scoop@ii #1\begin\@scoop #2\end #3{\scoop@i #2\begin\@scoop }

\def\scoop@end {\expandafter\end\expandafter{\scoop@env}}

\makeatother

%% PATCHING THE enumerate, itemize and description ENVIRONMENTS
%%   *** FROM ENUMITEM ***
%% (starred environments enumerate*, etc.. NOT DONE)

\makeatletter
\def\end@concise {\def\endenumerate   {\enit@endenumerate}%
                  \def\enditemize     {\enit@enditemize}%
                  \def\enddescription {\enit@enddescription}}


\newcount\cnt@concise
\cnt@concise\@M

% à cause des \relax dans \renewenvironment? non.
% \def\@MAKECONCISE {%
%        \renewenvironment{enumerate}[1][]
%           {\scoop {enumerate}}{\aftergroup\end@concise\ignorespacesafterend}%
%        \renewenvironment{itemize}[1][]
%           {\scoop {itemize}}{\aftergroup\end@concise\ignorespacesafterend}%
%        \renewenvironment{description}[1][]
%           {\scoop {description}}{\aftergroup\end@concise\ignorespacesafterend}%
% }%

% OK I have solved it. Must be something done by enumitem.sty which didn't
% like the modification to \endenumerate etc..., so we delay. It works.
\def\@MAKECONCISE@i {%
    \def\enumerate   {\@MAKECONCISE@ii \scoop {enumerate}}%
    \def\itemize     {\@MAKECONCISE@ii \scoop {itemize}}%
    \def\description {\@MAKECONCISE@ii \scoop {description}}%
}%

\def\@MAKECONCISE@ii {%
    \def\endenumerate {\aftergroup\end@concise\ignorespacesafterend}%
    \let\enditemize     \endenumerate
    \let\enddescription \endenumerate
}% 

\renewenvironment{enumerate}[1][]
  {\advance\cnt@concise-\@ne\ifnum\cnt@concise<\@ne\@MAKECONCISE@i\fi
   \enit@enumerate\enitdp@enumerate{enum}\thr@@{#1}}
  {\enit@endenumerate}

\renewenvironment{itemize}[1][]
  {\advance\cnt@concise-\@ne\ifnum\cnt@concise<\@ne\@MAKECONCISE@i\fi
   \enit@itemize\enitdp@itemize{item}\thr@@{#1}}
  {\enit@enditemize}

\renewenvironment{description}[1][]
  {\advance\cnt@concise-\@ne\ifnum\cnt@concise<\@ne\@MAKECONCISE@i\fi
   \enit@description\enitdp@description{description}\@M{#1}}
  {\enit@enddescription}

\newcommand{\SetConciseLevelTo}[1]{\cnt@concise #1\relax }

\makeatother

\begin{document}

\hrule
\medskip

\texttt{CONCISE LEVEL = 1}
\SetConciseLevelTo {1}


\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{itemize}
  \item First point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
  \begin{description}
  \item[More elaboration of the First point:] here we explain more things.
    \begin{itemize}
    \item specific details ...
    \item ... and again specific details
    \end{itemize}
  \end{description}
\item Second point concisely.
  \begin{itemize}
  \item Second point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
   \end{itemize}
\item Third point concisely.
  \begin{itemize}
  \item Third point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Fourth point concisely.
  \begin{itemize}
  \item Fourth point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\end{enumerate}

Again:
\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{itemize}
  \item First point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
  \begin{description}
  \item[More elaboration of the First point:] here we explain more things.
    \begin{itemize}
    \item specific details ...
    \item ... and again specific details
    \end{itemize}
  \end{description}
\item Second point concisely.
  \begin{itemize}
  \item Second point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
   \end{itemize}
\item Third point concisely.
  \begin{itemize}
  \item Third point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Fourth point concisely.
  \begin{itemize}
  \item Fourth point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\end{enumerate}

\hrule
\medskip
\texttt{CONCISE LEVEL = 2}

\SetConciseLevelTo {2}

\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{itemize}
  \item First point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
  \begin{description}
  \item[More elaboration of the First point:] here we explain more things.
    \begin{itemize}
    \item specific details ...
    \item ... and again specific details
    \end{itemize}
  \end{description}
\item Second point concisely.
  \begin{itemize}
  \item Second point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Third point concisely.
  \begin{itemize}
  \item Third point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Fourth point concisely.
  \begin{itemize}
  \item Fourth point in elaboration.
    \begin{description}
    \item[Specific details]...
    \end{description}
  \end{itemize}
\end{enumerate}

\hrule
\medskip
\texttt{CONCISE LEVEL = 3}

\SetConciseLevelTo {3}

\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{itemize}
  \item First point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
  \begin{description}
  \item[More elaboration of the First point:] here we explain more things.
    \begin{itemize}
    \item specific details ...
    \item ... and again specific details
    \end{itemize}
  \end{description}
\item Second point concisely.
  \begin{itemize}
  \item Second point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
   \end{itemize}
\item Third point concisely.
  \begin{itemize}
  \item Third point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Fourth point concisely.
  \begin{itemize}
  \item Fourth point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\end{enumerate}

\hrule
\medskip
\texttt{CONCISE LEVEL = 1}

\SetConciseLevelTo {1}

\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{itemize}
  \item First point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
  \begin{description}
  \item[More elaboration of the First point:] here we explain more things.
    \begin{itemize}
    \item specific details ...
    \item ... and again specific details
    \end{itemize}
  \end{description}
\item Second point concisely.
  \begin{itemize}
  \item Second point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Third point concisely.
  \begin{itemize}
  \item Third point in elaboration.
    \begin{description}
    \item[Specific details] ...
    \end{description}
  \end{itemize}
\item Fourth point concisely.
  \begin{itemize}
  \item Fourth point in elaboration.
    \begin{description}
    \item[Specific details]...
    \end{description}
  \end{itemize}
\end{enumerate}

\hrule

\end{document}

简洁列表


第一个版本

(我认为有一个错误,但现在不重要了)

尝试这个

\documentclass{article}
\usepackage{enumitem}

\makeatletter
% GENERAL PURPOSE ENVIRONMENT SWALLOWING
% #1 is the name of the surrounding environment
% we swallow everything until finding the correct \end
% then we reinject \end{#1}
\def\@scoop{\@scoop}

\long\def\scoop  #1#2\end #3%
    {\def\scoop@env{#1}\scoop@i #2\@scoop\begin\@scoop }

\long\def\scoop@i #1\begin #2{\def\scoop@tmp{#2}%
                        \ifx\scoop@tmp\@scoop
                             \expandafter\scoop@end
                        \else\expandafter\scoop@ii
                        \fi }

\long\def\scoop@ii #1\@scoop\begin\@scoop #2\end #3%
     {\scoop@i #2\@scoop\begin\@scoop }

\def\scoop@end {\expandafter\end\expandafter{\scoop@env}}

% 
\def\endscoop {\def\endenumerate{\enit@endenumerate}}
%

\renewenvironment{enumerate}[1][]
  {\ifConcise
       \renewenvironment{enumerate}[1][]{\scoop {enumerate}}{\endscoop \par}%
   \fi
   \enit@enumerate\enitdp@enumerate{enum}\thr@@{#1}}
  {\enit@endenumerate}
\makeatother

\newif\ifConcise


\begin{document}\thispagestyle{empty}

\hrule
\smallskip

\texttt{CONCISE IS TRUE}
\Concisetrue
\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{enumerate}[label=\alph*.]
  \item First point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
  \end{enumerate}
\item Second point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Second point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
   \end{enumerate}
\item Third point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Third point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
  \end{enumerate}
\item Fourth point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Fourth point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
  \end{enumerate}
\end{enumerate}

\bigskip
\texttt{CONCISE IS NOW FALSE}

\Concisefalse
\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{enumerate}[label=\alph*.]
  \item First point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
   \end{enumerate}
\item Second point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Second point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
   \end{enumerate}
\item Third point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Third point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
   \end{enumerate}
\item Fourth point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Fourth point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
  \end{enumerate}
\end{enumerate}

\bigskip
\texttt{CONCISE IS AGAIN TRUE}

\Concisetrue
\begin{enumerate}[label=\Roman*.]
\item First point concisely.
  \begin{enumerate}[label=\alph*.]
  \item First point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
  \end{enumerate}
\item Second point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Second point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
   \end{enumerate}
\item Third point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Third point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
   \end{enumerate}
\item Fourth point concisely.
  \begin{enumerate}[label=\alph*.]
  \item Fourth point in elaboration.
    \begin{enumerate}[label=\arabic*.]
    \item Specific details...
    \end{enumerate}
  \end{enumerate}
\end{enumerate}

\smallskip
\hrule

\end{document}

简明列举

相关内容