为了帮助构建大型文档,我想使用项目符号总结章节(或子章节或章节)开头的关键点,并将其包含在目录页中。如果可能的话,我还想启用/禁用摘要(在章节和目录中)。是否已经有允许这样做的软件包,或者有人可以提供一些命令使用的想法?
最终结果应如下所示:
Table of Content
Introduction..........1
* some text introducing the topic
* more text
Background............5
* Background section blah, blah
Chapter 1............10
* ...
...
Introduction
* some text introducing the topic
* more text
This is the text for the actual introduction. Summary bullet
points are show because "draft" flag is set.
More intro text here...
Background
...
Chapter 1
...
我发现有人问了类似的问题这里但是当我尝试包含一个 itemize 环境(例如在 chapterinfo 中)时,我收到一条错误消息:
第 1 章。) !不完整 \iffalse;第 56 行之后的所有文本都被忽略。\fi
chapterinfo
如果有人可以提供一些提示,说明如何使此部分类型不可知(即不使用)sectioninfo
,以及更重要的是如何使其成为环境,即使用类似以下内容的内容,那就太好了:
\section{Introduction}
\begin{summary}
\item some text introducing the topic
\item more text
\end{summary}
事实上,摘要实际上没有出现在文本中,这对我来说不是什么大问题。
答案1
以下可能是一个起点。您可以调整itemize
环境以使用更小的空间和东西。
\documentclass[draft]{report}
\usepackage{enumitem}
\newif\ifSummaryInToC
\newif\ifSummaryInText
\SummaryInToCtrue
\SummaryInTexttrue
\makeatletter
\long\def\grabsummary#1#2\end{%
\ifSummaryInToC\applysummary{#1}{#2}\fi%
\ifSummaryInText\applydraftsummary{#2}\fi%
\end}
\long\def\applysummary#1#2{%
\addtocontents{toc}{\unexpanded{\unexpanded{%
\bgroup%
\let\BEGIN\begin%
\let\END\end%
\expandafter\ifcase\numexpr#1+1\relax%
\vspace*{1ex}% part needs more distance in ToC than the others
\else%
\vspace*{-1ex}%
\fi%
\expandafter\ifcase\numexpr#1+1\relax%
\@tempdima=1em\relax% indentation for part-level
\or%
\@tempdima=2.3em\relax% indentation for chapter-level
\or%
\@tempdima=3.8em\relax% indentation for section-level
\or%
\@tempdima=7em\relax% indentation for subsection-level
\or%
\@tempdima=11.1em\relax% indentation for subsubsection-level
\else%
\@tempdima=1.7em\relax% fallback indentation
\fi%
\begin{itemize}[leftmargin=\@tempdima]%
\baselineskip=0.5\baselineskip% crude way of changing the space
\parskip=0pt% crude way of changing the space between items
\parsep=0pt% crude way of changing the space between items
\itemsep=2pt% crude way of changing the space between items
#2%
\end{itemize}%
\egroup%
}}}}
\long\def\applydraftsummary#1{%
\hrule width \textwidth\kern4pt%
\textbf{Summary}%
\begin{itemize}#1\end{itemize}%
\hrule width \textwidth\medskip}%
\newenvironment{summary}[1][0]{\let\BEGIN\begin\let\END\end\grabsummary{#1}}{}%
\makeatother
\begin{document}
\tableofcontents
\part{FOO} % summary is not on the same page as heading
\begin{summary}[-1]
\item foo
\item bar
\end{summary}
\chapter{Foo}
\begin{summary}
\item foo
\item bar
\item baz
\item very long bullet point that describes very much and eventually needs a
line break
\BEGIN{itemize}
\item test
\END{itemize}
\item foo
\end{summary}
This is the text for the actual Foo.
Summary bullet points are shown because \verb|\SummaryInTexttrue| is set.
If \verb|\SummaryInToCtrue| is also set, these bullet points show up in the ToC,
too!
\section{Foobar}
\begin{summary}[1]
\item Foo
\BEGIN{itemize}
\item foo
\item bar
\END{itemize}
\item Bar
\end{summary}
\subsection{foobar}
\begin{summary}[2]
\item Foo
\BEGIN{itemize}
\item foo
\item bar
\END{itemize}
\item Bar
\end{summary}
\chapter{Bar}
\begin{summary}
\item foo
\item bar
\item baz
\end{summary}
\section{Foobaz}
\end{document}
编辑:我修改了答案以应对您要求的所有内容(我认为)。如果缺少任何内容,请随时询问。
您不应该在环境中嵌套环境summary
,因为如果遇到停止,\grabsummary
则会扫描和。我进行了另一次编辑,允许使用嵌套环境和(技术上这部分不是必需的,但我认为如果它们匹配会更好)。请注意,和的定义仅在 -environment 内有效。\end
\end
\BEGIN
\END
\BEGIN
\BEGIN
\END
summary
您可以通过将级别作为可选参数来手动更改缩进,其summary
含义如下:
-1:部分
0:章节
1:部分
2:小节
3:小节
默认0
导致章节级别的缩进。
如果和都为真,则结果\ifSummaryInToC
为\ifSummaryInText
: