扩展的类似目录的环境

扩展的类似目录的环境

我正在排版一本书。这本书的每一章开头都有一段特殊的目录式文本。

我想要做的是:在每个部分之后使用一个环境(比如摘要)并在每章开头获取结果。

\documentclass{book}

\usepackage[inline]{enumitem}

\begin{document}
\chapter{First Chapter}
    \begin{abstract}
        \begin{itemize*}
            \item First this abstract talks about....
            \item Second we have ...
        \end{itemize*}
    \end{abstract}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{First Section}
    \begin{abstract}
        \begin{itemize*}
            \item this section talks about ....
            \item it also tals about
        \end{\itemize*}
    \end{abstract}

bla bla bla
\end{document}

结果:

First Chapter
-- First this abstract talks about.... -- Second we have ...
1. First Section: -- this section talks about .... -- it also talks about

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

*First Section*
bla bla bla

这可能吗?

请注意,这不仅仅是 minitoc,因为每个部分在目录中都会有一个摘要。

编辑:该描述实际上是包itemize*提供的环境enumitem

答案1

以下是如何使用埃托克。除了章节摘要目录外,我还添加了章节摘要的“minitoc”,每个章节一个。

更新添加了第二个代码示例以响应评论:如何使用带有未编号章节的方法(\chapter*)以及如何使用enumerate*而不是enumerate在每个(现在未编号的)章节开始时收集部分章节。

第 1 页

摘要 1

第 3 页

摘要 2

第 5 页

摘要 3

\documentclass{book}

\usepackage[inline]{enumitem}
\usepackage{etoc}
\usepackage{hyperref}% checking compatibility (also for pdf bookmarks)

\etocsetlevel{chapterabstract}{6}% invisible in TOCs unless level changed
\etocsetlevel{sectionabstract}{6}% invisible in TOCs unless level changed

\usepackage{environ}

%%%%

\NewEnviron {sectionabstract}{%
   \expandafter\SaveSectionAbstract\expandafter {\BODY}%
}%

\newcommand\SaveSectionAbstract [1]{%
   \etoctoccontentsline{sectionabstract}{\unexpanded{\unexpanded{#1}}}}

\NewEnviron {chapterabstract}{%
   \expandafter\SaveChapterAbstract\expandafter {\BODY}%
}%

\newcommand\SaveChapterAbstract [1]{%
   \etoctoccontentsline{chapterabstract}{\unexpanded{\unexpanded{#1}}}}

%%%%

\newcommand\PrintSectionAbstracts {%
    \begingroup
% level must be set *before* use of \etocsetstyle
       \etocsetlevel {sectionabstract}{2}
       \etocsetnexttocdepth {sectionabstract}
       \etocsetlevel {subsection}{3}   
       \etocsetstyle {section}
          {\begin{enumerate}}
          {}
          {\item \etocname:~}
          {\end{enumerate}}
       \etocsetstyle {sectionabstract}
          {}
          {}
          {\etocthename\par}
          {}
       \etocsettocstyle{\subsection*{Section abstracts}}{}
       \localtableofcontents
    \endgroup
}   

\newcommand\PrintChapterAbstracts {%
    \begingroup
       \etocsetlevel {chapterabstract}{1}
       \etocsetnexttocdepth {chapterabstract}
       \etocsetlevel {section}{2}   
       \etocsetstyle {chapter}
          {\begin{enumerate}}
          {}
          {\item \etocname:~}
          {\end{enumerate}}
       \etocsetstyle {chapterabstract}
          {}
          {}
          {\etocthename\par}
          {}
       \etocsettocstyle{\subsection*{Chapter abstracts}}{}
       %\localtableofcontents 
       % better not local, as the main TOC itself, a priori printed before,
       % could have been configured to create a chapter entry in the toc file
       \tableofcontents
    \endgroup
}   

\begin{document}

\tableofcontents % standard table of contents

\PrintChapterAbstracts % chapter abstracts

\chapter{First Chapter}
   \begin{chapterabstract}
        \begin{itemize*}
            \item First this chapter talks about....
            \item Second we have ...
        \end{itemize*}
   \end{chapterabstract}

\PrintSectionAbstracts % section abstracts

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{First Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this first section talks about Lorem ipsum dolor sit amet,
              consetetur sadipscing elitr \dots
            \item it also talks about \dots
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Second Section}

    \begin{sectionabstract}
        \begin{itemize*}
        \item this second section talks about ipsum dolor sit amet, consetetur
          sadipscing elitr,
        \item it also talks about sed diam voluptua. At vero eos et accusam et
          justo duo dolores et ea rebum.
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Third  Section}

    \begin{sectionabstract}
        \begin{itemize*}
        \item this third section talks about ipsum dolor sit amet, consetetur
          sadipscing elitr,
        \item it also talks about sed diam voluptua.
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\chapter{Second Chapter}
   \begin{chapterabstract}
        \begin{itemize*}
        \item First this second chapter talks about ipsum dolor sit amet,
          consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
          labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos
          et accusam et justo duo dolores et ea rebum.
        \item Second we have clita kasd gubergren, no sea takimata sanctus est
          Lorem ipsum dolor sit amet.
        \end{itemize*}
   \end{chapterabstract}

\PrintSectionAbstracts % section abstracts

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{First Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this first section of the second chapter talks about \dots
            \item it also talks about \dots
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Second Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this section talks about \dots
            \item it also talks about \dots
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Third  Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this third section talks about ipsum dolor sit amet, consetetur sadipscing elitr,
            \item it also talks about sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\end{document}

评论:这是我的进一步阐述回答制作第二个“目录”,其中包含每个部分的简短摘要. 新的东西是使用包环境允许使用环境而不是命令语法。除此之外,这本质上是相同的技术。


更新

主目录的页面(请注意,它使用类默认的保留空间来编号章节,这里的编号太大,因为章节没有编号;您可以更etoc充分地使用,请参阅手册中的示例,或使用例如tocloft自定义打印在兼容模式)。

章节摘要是使用description环境打印的。

章节摘要 II 1

第一章页数

章节摘要 II 2

第二章页数

章节摘要 II 3

\documentclass{book}

\usepackage[inline]{enumitem}
\usepackage{etoc}
\usepackage{hyperref}% checking compatibility (also for pdf bookmarks)

\etocsetlevel{chapterabstract}{6}% invisible in TOCs unless level changed
\etocsetlevel{sectionabstract}{6}% invisible in TOCs unless level changed

\usepackage{environ}

%%%%

\NewEnviron {sectionabstract}{%
   \expandafter\SaveSectionAbstract\expandafter {\BODY}%
}%

\newcommand\SaveSectionAbstract [1]{%
   \etoctoccontentsline{sectionabstract}{\unexpanded{\unexpanded{#1}}}}

\NewEnviron {chapterabstract}{%
   \expandafter\SaveChapterAbstract\expandafter {\BODY}%
}%

\newcommand\SaveChapterAbstract [1]{%
   \etoctoccontentsline{chapterabstract}{\unexpanded{\unexpanded{#1}}}}

%%%%

\newcommand\PrintSectionAbstracts {%
    \begingroup
% level must be set *before* use of \etocsetstyle
       \etocsetlevel {sectionabstract}{2}
       \etocsetnexttocdepth {sectionabstract}
       \etocsetlevel {subsection}{3}  
% enumitem redefinition of \item causes the closing of groups
% hence either some \expandafter, or like here \global saving
% of number and name 
       \etocsetstyle {section}
          {\begin{enumerate*}}
          {\global\let\EtocNumber\etocthenumber
           \global\let\EtocName\etocthelinkedname}
          {\item [{\bfseries\EtocNumber.}~]\EtocName: }
          {\end{enumerate*}}
       \etocsetstyle {sectionabstract}
          {}
          {}
          {\etocthename\par}
          {}
       \etocsettocstyle{\subsection*{Section abstracts}}{\medskip}
       \localtableofcontents
    \endgroup
}   

\newcommand\PrintChapterAbstracts {%
    \begingroup
       \etocsetlevel {chapterabstract}{1}
       \etocsetnexttocdepth {chapterabstract}
       \etocsetlevel {section}{2}   
       \etocsetstyle {chapter}
          {\begin{description}}
          {}
          {\item[\etocname] }
          {\end{description}}
       \etocsetstyle {chapterabstract}
          {}
          {}
          {\etocthename\par}
          {}
       \etocsettocstyle{\subsection*{Chapter abstracts}}{}
       \tableofcontents
    \endgroup
}   

\begin{document}

\renewcommand{\thesection}{\arabic{section}}

\tableofcontents % standard table of contents

\PrintChapterAbstracts % chapter abstracts

\chapter*{First Chapter}
\addcontentsline{toc}{chapter}{First Chapter}

   \begin{chapterabstract}
        \begin{itemize*}
            \item First this chapter talks about....
            \item Second we have ...
        \end{itemize*}
   \end{chapterabstract}

\PrintSectionAbstracts % section abstracts

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{First Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this first section talks about Lorem ipsum dolor sit amet,
              consetetur sadipscing elitr \dots
            \item it also talks about \dots
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\subsection{this subsection should not create problems}

\section{Second Section}

    \begin{sectionabstract}
        \begin{itemize*}
        \item this second section talks about ipsum dolor sit amet, consetetur
          sadipscing elitr,
        \item it also talks about sed diam voluptua. At vero eos et accusam et
          justo duo dolores et ea rebum.
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Third  Section}

    \begin{sectionabstract}
        \begin{itemize*}
        \item this third section talks about ipsum dolor sit amet, consetetur
          sadipscing elitr,
        \item it also talks about sed diam voluptua.
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\chapter*{Second Chapter}
\addcontentsline{toc}{chapter}{Second Chapter}

   \begin{chapterabstract}
        \begin{itemize*}
        \item First this second chapter talks about ipsum dolor sit amet,
          consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
          labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos
          et accusam et justo duo dolores et ea rebum.
        \item Second we have clita kasd gubergren, no sea takimata sanctus est
          Lorem ipsum dolor sit amet.
        \end{itemize*}
   \end{chapterabstract}

\PrintSectionAbstracts % section abstracts

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{First Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this first section of the second chapter talks about \dots
            \item it also talks about \dots
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Second Section}

    \begin{sectionabstract}
        \begin{itemize*}
            \item this section talks about \dots
            \item it also talks about \dots
        \end{itemize*}
    \end{sectionabstract}

bla bla bla

\section{Third  Section}

    \begin{sectionabstract}
    \begin{itemize*}
    \item this third section talks about ipsum dolor sit amet, consetetur
      sadipscing elitr,
    \item it also talks about sed diam voluptua.
    \end{itemize*}
    \end{sectionabstract}

bla bla bla

\end{document}

答案2

以下是使用titletoc包生成部分 ToC 和变体Martin Sharrer 的回答带有条目附加说明的目录在部分目录中包含附加部分描述:

\documentclass{book}
\usepackage{titletoc}
\usepackage{environ}
\usepackage[inline]{enumitem}
\usepackage{lipsum}

\makeatletter
\def\@nodottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{\,}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor }%
     \par}%
  \fi}
\newcommand*\l@sectioninfo{\@nodottedtocline{1}{1.5em}{2.3em}}
\NewEnviron{sectioninfo}{%
    \addcontentsline{ptc}{sectioninfo}{%
    \noexpand\numberline{}\BODY}%
}
\makeatother

\def\PrintContents{%
\startcontents%
\printcontents{}{1}{{\bfseries\Large\contentsname}%
  \par\nobreak\vskip-6pt\noindent\hrulefill}%
  \vskip-6pt\noindent\hrulefill\vskip3\baselineskip%
}

\begin{document}
\tableofcontents

\chapter{First chapter}
\PrintContents

\lipsum[4]

\section{First section of chapter one}
\begin{sectioninfo}
\protect\begin{itemize*}
\protect\item The first important thing about this section.
\protect\item The second important thing about this section.
\protect\item The third important thing about this section.
\protect\end{itemize*}%
\end{sectioninfo}
\lipsum[4]
\section{Second section of chapter one}
\begin{sectioninfo}
\protect\begin{itemize*}
\protect\item The first important thing about this section.
\protect\item The second important thing about this section.
\protect\item The third important thing about this section.
\protect\item The fourth important thing about this section.
\protect\end{itemize*}%
\end{sectioninfo}
\lipsum[4]

\chapter{Second chapter}
\PrintContents

\lipsum[4]

\section{First section of chapter two}
\begin{sectioninfo}
\protect\begin{itemize*}
\protect\item The first important thing about this section.
\protect\item The second important thing about this section.
\protect\end{itemize*}%
\end{sectioninfo}
\lipsum[4]
\section{Second section of chapter two}
\begin{sectioninfo}
\protect\begin{itemize*}
\protect\item The first important thing about this section.
\protect\item The second important thing about this section.
\protect\item The third important thing about this section.
\protect\end{itemize*}%
\end{sectioninfo}
\lipsum[4]

\end{document}

通用目录的图片:

在此处输入图片描述

以下是部分目录的一些图片:

在此处输入图片描述

在此处输入图片描述

评论

描述提供了一个sectioninfo环境;在这个环境中,脆弱的注释需要受到保护;由于描述中使用了itemize*(来自) ,所以,需要在前面加上。enumitem\begin{itemize*}\end{itemize*}\item\protect

相关内容