outlines 包在 \0 条目之后重新开始项目的编号,这是一个段落类型条目。outlines 包的文档提供了避免重新启动的序言代码。我还用它\usepackage[inline]{enumitem}\setlist{nosep}
来减少大纲项目之间的垂直间距。避免重新启动大纲计数器的序言代码不会根据 \0 命令后项目级别的减小的间距进行排版。较低的项目级别会使用正确的间距进行排版。我的例子说明了这一点。我想删除多余的间距。我刚刚注意到下面的代码还用整数标记了第一和第二级,这并不好。也许对我的特定问题更好的解决方案是避免多余的序言代码并删除命令\renewcommand{\outlinei}{cenumerate}
,然后手动重置 \0 命令后项目的计数器。我无法做到这一点。
\usepackage{outlines}
\usepackage[inline]{enumitem}
\setlist{nosep}
% The following code comes from the outlines package manual
\newcounter{cenum}
\newcounter{cenumsaved}
\setcounter{cenumsaved}{0}
\newcommand{\labelcenum}{\arabic{cenum}.}
\newenvironment{cenumerate}%
{\begin{list}{\labelcenum}{\usecounter{cenum}}%
\setcounter{cenum}{\value{cenumsaved}}}%
{\setcounter{cenumsaved}{\value{cenum}}%
\end{list}}
\begin{document}
\renewcommand{\outlinei}{cenumerate} % Comment this command to see the change in spacing
\begin{outline}[enumerate]
\1 First item - notice the extra spacing after this item
\2 First subitem
\2 Second subitem
\0 Some text
\1 Second item - notice the extra spacing before and after this item
\2 First subitem
\2 Second subitem
\1 Third item - notice the extra spacing before and after this item
\2 First subitem
\2 Second subitem
\end{outline}
\end{document}
答案1
像这样吗?
\documentclass{article}
\usepackage{outlines}
\newcounter{cenumi}
\newcounter{cenumisaved}
\setcounter{cenumisaved}{0}
\newcommand{\labelcenumi}{\arabic{cenumi}.}
\newenvironment{cenumeratei}%
{\begin{list}{\labelcenumi}{\usecounter{cenumi}\partopsep=0pt\topsep=0pt\itemsep=0pt\parsep=0pt}%
\setcounter{cenumi}{\value{cenumisaved}}}%
{\setcounter{cenumisaved}{\value{cenumi}}%
\end{list}}
\newcounter{cenumii}
\setcounter{cenumii}{0}
\newcommand{\labelcenumii}{(\alph{cenumii})}
\newenvironment{cenumerateii}%
{\begin{list}{\labelcenumii}{\usecounter{cenumii}\partopsep=0pt\topsep=0pt\itemsep=0pt\parsep=0pt}%
}%
{%
\end{list}}
\begin{document}
\renewcommand{\outlinei}{cenumeratei}
\renewcommand{\outlineii}{cenumerateii}
\begin{outline}
\1 First item - notice the extra spacing after this item
\2 First subitem
\2 Second subitem
\0 Some text
\1 Second item - notice the extra spacing before and after this item
\2 First subitem
\2 Second subitem
\1 Third item - notice the extra spacing before and after this item
\2 First subitem
\2 Second subitem
\end{outline}
\end{document}
也许代码没有优化。只适用于两级(但可以轻松扩展到三级或四级)。
答案2
我接受了 quark67 上面提出的解决方案,后来意识到对嵌套项的交叉引用仅列出了父项。例如,对项 1(a) 的交叉引用简化为引用项 1。我向 DP Story 发送了有关此问题的个人说明。Don 创建了一个不同的解决方案(发布在下面),它尊重所有交叉引用并增加了更多灵活性。Don 的解决方案允许通过在 \0 命令后跟 \n 命令(其中 n 是要继续的级别)来恢复任何嵌套的上一级项计数器。大纲环境不能以 \0 命令开头,因此大纲之前的文本应在此环境之前输入。
\documentclass{article}
\usepackage{outlines}
\usepackage{enumitem}
\usepackage{calc} % dps
\setlist{noitemsep}
\setlist{nolistsep}
\makeatletter
\newif\if@needsRsm\@needsRsmfalse
\def\resumeToDefault{%
\global\let\resume@ti\@empty
\global\let\resume@tii\@empty
\global\let\resume@tiii\@empty
\global\let\resume@tiv\@empty
}
\resumeToDefault
\def\ol@csarg#1#2{\expandafter#1\csname#2\endcsname}
% Executed at \0
\def\setPrevLevel{\global\@needsRsmtrue % dps
\xdef\@prevLevel{\@curLevel}}
\def\@prevLevel{0}
% Placed within \curLevel, which is expanded at the beginning of \1, \2, \3, \4
\def\resumeIfNeeded#1{\if@needsRsm\def\@next{\expandafter
\resumeAt\expandafter{\csname#1\endcsname}}\else\let\@next\relax\fi\@next}
% Expanded within each level: \1, \2, \3, \4
\def\curLevel#1{\def\@curLevel{#1}\resumeIfNeeded{#1}}
% dps modify outline package: \ol@z (insert \item[] so we can use \0 at any level
\renewcommand{\ol@z}{%
\ol@commands%
{}% 0
{\ol@inci}% 1
{\ol@inci\item[]\ol@incii}% 2
{\ol@inci\item[]\ol@incii\item[]\ol@inciii}% 3
{\ol@inci\item[]\ol@incii\item[]\ol@inciii\item[]\ol@inciiii}}% 4
% dps modify outline package: outline env (add \olsave, \curLevel)
\renewenvironment{outline}[1][]{%
\ifthenelse{\equal{#1}{}}{}{\renewcommand{\ol@type}{#1}}%
\ol@z%
\newcommand{\0}{\olsave\setPrevLevel\ol@toz\ol@z}% dps incorporate \olsave into level \0
\newcommand{\1}{\curLevel{1}\ol@toi\ol@i\resume@ti\item}%
\newcommand{\2}{\curLevel{2}\ol@toii\ol@ii\resume@tii\item}%
\newcommand{\3}{\curLevel{3}\ol@toiii\ol@iii\resume@tiii\item}%
\newcommand{\4}{\curLevel{4}\ol@toiiii\ol@iiii\resume@tiv\item}%
}{%
\ol@toz\ol@exit%
}
\def\UD#1{\noexpand\setcounter{enum#1}{\@nameuse{s@veAt#1}}%
\global\noexpand\ol@csarg\let{resume@t\@roman\@tempcnta}\noexpand\@empty}
\newcommand\resumeAt[1]{\global\@needsRsmfalse\begingroup\resumeToDefault
\edef\r@t{\expandafter\@roman\expandafter\@gobble\string#1}%
\edef\n@t{\expandafter\@gobble\string#1}%
% When we are resuming at a higher level then the previous level,
% we zero all counters out below (new environment starting)
\ifnum\n@t>\@prevLevel\relax
\zeroOutBelow{\@prevLevel}\olsave\fi
\@tempcnta=0\relax\toks@={}%
\@whilenum\@tempcnta<\n@t\relax\do{\advance\@tempcnta\@ne
\edef\x{\UD{\@roman\@tempcnta}}%
\toks2=\expandafter{\x}\edef\y{\the\toks@\the\toks2 }%
\toks@=\expandafter{\y}%
}%
\edef\x{\noexpand\ol@csarg\noexpand
\xdef{resume@t\r@t}{\noexpand\the\noexpand\toks@}}\x
\endgroup\ignorespaces
}
\def\zeroOutBelow#1{\begingroup
\@tempcnta#1\relax
\@whilenum\@tempcnta<4\relax\do{%
\advance\@tempcnta\@ne
\setcounter{enum\@roman\@tempcnta}{0}}%
\endgroup
}
\def\olsave{\@tfor\n:={i}{ii}{iii}{iv}\do{%
\ol@csarg\xdef{s@veAt\n}{\the\value{enum\n}}}% do
}
\makeatother
\begin{document}
We begin the outline here
\begin{outline}[enumerate]
\1 First item
\2 First subitem
\3\label{cr} Item with label
\4 Fourth level
\4 Fourth level, again
\0 This is another comment
\2 Second subitem
\0 Some text here, let's make it long to see what happens when we wrap around to the next line.
\1 Second item
\2 \textbf{See item} \ref{cr}
\3 The above reference reads``See item 1''
\4 Let's not forget level 4
\4 Another level 4
\0 Hello world!
\2 Second subitem
\2 Second subitem
\0 Make my day!
\1 A third top level
\2 Level 2 item
\3 Level 3 item
\0 Let's break the outline here with a comment
\3 Level 3 item
\0 Do we continue as expected ?
\3 Level 3 for testing
% \4 More four to follow
\0 Now test level 4 in the same way
\4 Level 4
\4 Level 4, again
\0 Back to level 1
\1 back to level 1
\2 Another important point
\end{outline}
\end{document}