我有一个如下列表:
- 第 1 项概述
- 第 1 项的更深入描述第 1 部分
- 第 1 项的更深入描述的第 2 部分
- 第 1 项的更深入描述第 3 部分
- 第 2 项概述
- 第 2 项的更深入描述第 1 部分
- 第 2 项的更深入描述第 2 部分
- 第 2 项的更深入描述第 3 部分
- ETC...
我希望在文档顶部有一个单独的列表,只显示列表中的顶级项目作为概览,而无需复制和粘贴项目。因此,上述列表的概览应如下所示:
- 第 1 项概述
- 第 2 项概述
- ETC...
为了进一步说明,我的文档如下所示:
\documentclass[10pt, letterpaper]{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
\item Overview of item 1
\begin{enumerate}[label = (\Alph*)]
\item Part 1 of more in depth description of item 1
\item Part 2 of more in depth description of item 1
\item Part 3 of more in depth description of item 1
\end{enumerate}
\item Overview of item 2
\begin{enumerate}[label = (\Alph*)]
\item Part 1 of more in depth description of item 2
\item Part 2 of more in depth description of item 2
\item Part 3 of more in depth description of item 2
\end{enumerate}
\item etc...
\end{enumerate}
\end{document}
我想知道实现这一目标的优雅方法是什么。
答案1
这是一个解决方案(一个技巧)
\documentclass[10pt, letterpaper]{article}
\usepackage{enumitem}
\usepackage{etoolbox}
\newcounter{mt}
\BeforeBeginEnvironment{enumerate}{\stepcounter{mt}\setbox\themt\vbox\bgroup}
\AfterEndEnvironment{enumerate}{\egroup\ifnum\value{mt}=1\unvbox1\fi\addtocounter{mt}{-1}}
\begin{document}
\begin{enumerate}
\item Overview of item 1
\begin{enumerate}[label = (\Alph*)]
\item Part 1 of more in depth description of item 1
\item Part 2 of more in depth description of item 1
\item Part 3 of more in depth description of item 1
\end{enumerate}
\item Overview of item 2
\begin{enumerate}[label = (\Alph*)]
\item Part 1 of more in depth description of item 2
\item Part 2 of more in depth description of item 2
\item Part 3 of more in depth description of item 2
\end{enumerate}
\item etc...
\end{enumerate}
bla bla
\begin{enumerate}
\item Overview of item A1
\begin{enumerate}[label = (\Alph*)]
\item Part 1 of more in depth description of item 1
\begin{enumerate}[label = (\alph*)]
\item Part 1 of more in depth description of item 1.A
\item Part 2 of more in depth description of item 1.A
\item Part 3 of more in depth description of item 1.A
\end{enumerate}
\item Part 2 of more in depth description of item 1
\item Part 3 of more in depth description of item 1
\end{enumerate}
\item Overview of item A2
\begin{enumerate}[label = (\Alph*)]
\item Part 1 of more in depth description of item 2
\item Part 2 of more in depth description of item 2
\item Part 3 of more in depth description of item 2
\end{enumerate}
\item etc...A ...
\end{enumerate}
\end{document}
答案2
\item
具有自动使用和命令包装器的中间版本\toplevel*
,然后忽略\sublevel
命令。
\documentclass{article}
\usepackage{environ}
\usepackage{enumitem}
\usepackage{xparse}
\newif\ifsublevels
\sublevelstrue
\ExplSyntaxOn
\NewDocumentCommand{\sublevel}{m}{%
\ifsublevels
\seq_set_from_clist:Nn \l_tmpa_seq {#1}
\begin{enumerate}
\seq_map_inline:Nn \l_tmpa_seq {\item ##1}
\end{enumerate}
\fi
}
\NewDocumentCommand{\toplevel}{sO{}m}{%
\IfBooleanT{#1}{%
\global\sublevelsfalse
}%
\seq_set_from_clist:Nn \l_tmpb_seq {#3}
\begin{enumerate}[#2]
\seq_map_inline:Nn \l_tmpb_seq {\item ##1}
\end{enumerate}
}
\ExplSyntaxOff
\begin{document}
\toplevel{Top item 1 \sublevel{Sub level 1, Sub level 2, Sub level 3}, Top Item 2 \sublevel{Sub level 11, Sub level 21}}
\toplevel*{Top item 1 \sublevel{Sub level 1, Sub level 2, Sub level 3}, Top Item 2 \sublevel{Sub level 11, Sub level 21}}
\end{document}
答案3
我建议为该应用程序定义一个特殊的环境,这样您就可以更自由地选择要显示的内容。
\documentclass[10pt, letterpaper]{article}
\usepackage{enumitem}
\usepackage{environ}
\makeatletter
\newenvironment{overview}[1]
{\begin{enumerate}\relax
\ifnum#1=0
\let\do@suboverview\@gobble
\else
\def\do@suboverview##1{%
\begin{enumerate}[label=(\Alph*)]##1\end{enumerate}%
}%
\fi
}
{\end{enumerate}}
\NewEnviron{suboverview}{\do@suboverview{\BODY}}
\makeatother
\begin{document}
\section{Short overview}
\begin{overview}{0}
\item Overview of item 1
\begin{suboverview}
\item Part 1 of more in depth description of item 1
\item Part 2 of more in depth description of item 1
\item Part 3 of more in depth description of item 1
\end{suboverview}
\item Overview of item 2
\begin{suboverview}
\item Part 1 of more in depth description of item 2
\item Part 2 of more in depth description of item 2
\item Part 3 of more in depth description of item 2
\end{suboverview}
\item etc...
\end{overview}
\section{Long overview}
\begin{overview}{1}
\item Overview of item 1
\begin{suboverview}
\item Part 1 of more in depth description of item 1
\item Part 2 of more in depth description of item 1
\item Part 3 of more in depth description of item 1
\end{suboverview}
\item Overview of item 2
\begin{suboverview}
\item Part 1 of more in depth description of item 2
\item Part 2 of more in depth description of item 2
\item Part 3 of more in depth description of item 2
\end{suboverview}
\item etc...
\end{overview}
\end{document}
如您所见,从简短概述到详细概述只需要将参数更改为overview
。