我能否以简单的枚举列表的形式获取所有部分的列表?

我能否以简单的枚举列表的形式获取所有部分的列表?

我目前正在创建一个记录模板(我不知道这个词是否正确:如果你有一个(商务)会议,并且你想记录所有重要的内容,那么你就写一份记录。来源是这里

议程项目目前处于简单enumerate环境中和源代码一样\section*。我只想让section*{agenda item}记录员只写记录。所有议程项目的列表应该自动生成。这可能吗?

(只是为了说明一下:我不想插入目录!我想要一个简单的

\begin{enumerate}[leftmargin=1.3em]%
    \setlength{\itemsep}{-2pt}% 
    \item agenda item 1
    \item agenda item 2
    \item agenda item 3
    \item agenda item 4
\end{enumerate}

自动生成)

答案1

一个可能的解决方案:titlesec包用于抑制\section文档主体中 s 的编号;重新定义\l@section\tableofcontents给出所需的列表格式:

\documentclass{scrartcl}
\usepackage{titlesec}
\usepackage{lipsum}

\setcounter{tocdepth}{1}

\makeatletter
\renewcommand\tableofcontents{
\@starttoc{toc}
}
\renewcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{0.5em \@plus\p@}%
    \setlength\@tempdima{1.3em}%
    \begingroup
      \leavevmode
      \advance\leftskip\@tempdima
      #1\hfil\par
    \endgroup
  \fi}
\makeatother

\titleformat{\section}
  {\normalfont\Large\bfseries\sffamily}{}{0em}{}

\begin{document}

\tableofcontents
\section{Agenda item one}
\lipsum[4]
\section{Agenda item two}
\lipsum[4]
\section{Agenda item three}
\lipsum[4]
\section{Agenda item four}
\lipsum[4]

\end{document}

第一页的图片,显示了章节列表:

在此处输入图片描述

答案2

我修改了一些 Gonzalo 的方法,以便不对间距进行硬编码,而是真正使用真实的enumerate环境。(编辑:为了说明,我添加了一个\usepackage{enumerate}。)(编辑 2:我修改了我的原始代码,在将选项传递给枚举环境的情况下,仅当文件toc已存在时才会编译...)


编辑:我提出三种越来越复杂的方法。第一种方法是对 的方法进行修改Gonzalo,以便允许使用真正的枚举环境。为此,egreg从那时起提供了一种更简单的方法。然后我添加了对小节和子小节的支持,以便可以使用软件包的格式化选项来自enumitem定义破解目录的外观(方法 2)。最后(方法 3)我再次修改以添加hyperref支持。所以最后我们重新构建了一个带有可能超链接的模拟目录。链接放在章节和小节的名称中,但也可以插入到项目的标签中(使用enumitem)。只是不使用页码。但如果我理解 OP 的目的更多是在这里使用环境itemize,所以我没有尝试将链接放在项目标签中。

例如,包含章节、小节和小小节的目录可能如下所示:

被黑的目录示例

并且所有名称(或子小节的字母)都是hyperref-link(这些名称是文档主体中用于章节、小节、小小节标题的名称,它们不是由代码生成的)。获取此代码的代码是下面的第三个提案。


第一个建议:

\documentclass{scrartcl}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{enumerate}

\setcounter{tocdepth}{1}

\newtoks\agendatoks
\newif\ifexisttoc

\makeatletter
\renewcommand\tableofcontents{%
\@starttoc{toc}\ifexisttoc
\begin{enumerate}[(A)] % <- customize this, for example if you use the
                  % enumitem package, to specify the spacings etc...
\the\agendatoks
\end{enumerate}
\fi}

\renewcommand*\l@section[2]{%
  \let\ex\expandafter
  \let\numberline\@gobble
  \ifnum \c@tocdepth >\z@
  \toks0=\ex{\ex\item #1}%
  \global\agendatoks=\ex\ex\ex{\ex\the\ex\agendatoks\the\toks0}%
  \global\existtoctrue
 \fi}

\makeatother

\titleformat{\section}
  {\normalfont\Large\bfseries\sffamily}{}{0em}{}

\begin{document}


\tableofcontents

\section{Agenda item one}
\lipsum[4]
\section{Agenda item two}
\lipsum[4]
\section{Agenda item three}
\lipsum[4]
\section{Agenda item four}
\lipsum[4]

\end{document}

警告:我并没有随意查看.toc文件的内容,因此该方法仅在OP 的Gonzalo 示例中进行了测试!

dvi 文件的 png 图像


第二项建议:

% Time-stamp: <30-10-2012 21:26:48 CET jfb>
% http://tex.stackexchange.com/questions/79682/can-i-get-a-list-of-all-sections-as-a-simple-enumerate-list

\documentclass{article}
\usepackage{enumitem}  % to use its formatting options for enumerate, itemize, description
\usepackage{titlesec}  % to generate unnumbered sections and subsections in the body

%------------ macros to format the table of contents to one's arbitrary wishes
%------------ use is self-explanatory: customize \headeri, \headerii, \headeriii
%------------ none of the above two packages is necessary for the working of the macros

\newtoks\agendatoks
\newif\ifexisti
\newif\ifexistii
\newif\ifexistiii
\makeatletter

%------------ here we use options made available by package enumitem
\newcommand\headeri{\begin{enumerate}[font=\LARGE,label=\fbox{\arabic*}, itemsep=24pt]}
\newcommand\footeri{\end{enumerate}} % keep it in sync with \headeri!

\newcommand\headerii{\begin{enumerate}[font=\ttfamily\bfseries, leftmargin=1.5cm,%
 itemsep=18pt]}
\newcommand\footerii{\end{enumerate}}

\newcommand\headeriii{\begin{itemize}[itemsep=12pt]}
\newcommand\footeriii{\end{itemize}} 

%------------ our beautiful macros
\renewcommand\tableofcontents{%
\@starttoc{toc}%
\ifexisti
\the\agendatoks
\ifexistiii\footeriii\fi
\ifexistii\footerii\fi
\footeri
\fi}

\renewcommand\l@section[2]{%
  \let\ex\expandafter
  \let\numberline\@gobble
  \ifexistiii\toks0=\ex{\footeriii}\else\toks0={}\fi
  \global\existiiifalse
  \ifexistii\toks0=\ex{\the\toks0\noexpand\footerii}\fi
  \global\existiifalse
  \ifexisti\else\toks0=\ex{\headeri}\fi
  \global\existitrue
  \toks0=\ex{\the\toks0\noexpand\item}%
  \toks0=\ex\ex\ex{\ex\the\ex\toks0#1}%
  \global\agendatoks=\ex\ex\ex{\ex\the\ex\agendatoks\the\toks0}%
  % \showthe\agendatoks % for debugging
}

\renewcommand\l@subsection[2]{%
  \let\ex\expandafter
  \let\numberline\@gobble
  \ifexistiii\toks0=\ex{\footeriii}\else\toks0={}\fi
  \global\existiiifalse
  \ifexistii\else\toks0=\ex{\headerii}\fi
  \global\existiitrue
  \toks0=\ex{\the\toks0\noexpand\item}%
  \toks0=\ex\ex\ex{\ex\the\ex\toks0#1}%
  \global\agendatoks=\ex\ex\ex{\ex\the\ex\agendatoks\the\toks0}%
  % \showthe\agendatoks
}

\renewcommand\l@subsubsection[2]{%
  \let\ex\expandafter
  \let\numberline\@gobble
  \ifexistiii\toks0={}\else\toks0=\ex{\headeriii}\fi
  \global\existiiitrue
  \toks0=\ex{\the\toks0\noexpand\item}%
  \toks0=\ex\ex\ex{\ex\the\ex\toks0#1}%
  \global\agendatoks=\ex\ex\ex{\ex\the\ex\agendatoks\the\toks0}%
  % \showthe\agendatoks
}

\makeatother

% the following (from package titlesec) only influences the look of the body,
% not the table of contents
\titleformat{\section}
  {\normalfont\LARGE\bfseries\sffamily}{}{0em}{}
\titleformat{\subsection}
  {\normalfont\Large\sffamily}{}{1em}{}
\titleformat{\subsubsection}
  {\normalfont\large\ttfamily}{}{2em}{}

\begin{document}\thispagestyle{empty}

\centerline{\bfseries THIS IS THE TABLE OF CONTENTS}

\tableofcontents

\section{First}
\subsection{primo}
\subsection{secondo}
\subsubsection{i}
\subsubsection{ii}
\subsection{tertio}
\subsubsection{i}
\subsubsection{ii}
\subsubsection{iii}
\section{Second}
\subsection{primo}
\subsubsection{i}
\subsubsection{ii}
\subsubsection{iii}
\subsection{secondo}
\section{Third}
\subsection{tertio}
\section{Fourth}
\subsection{quarto}
\subsubsection{i}
\subsubsection{ii}
\subsubsection{iii}

\end{document}

这是第一页:

在此处输入图片描述


第三个建议:提供hyperref支持(如果hyperref没有支持也可以)

% Time-stamp: <31-10-2012 10:56:36 CET jfb>
% http://tex.stackexchange.com/questions/79682/can-i-get-a-list-of-all-sections-as-a-simple-enumerate-list

% Third version: now compatible with hyperref.

\documentclass{article}
\usepackage{enumitem}  % to use its formatting options for enumerate, itemize, description
\usepackage{titlesec}  % to generate unnumbered sections and subsections in the body
\usepackage{kantlipsum}

\usepackage{hyperref}

\newtoks\agendatoks
\newif\ifexisti
\newif\ifexistii
\newif\ifexistiii


%------------ here we use options made available by package enumitem
%------------ for the top level, and redefine \item for the inner levels

\makeatletter

\newcommand\headeri{\begin{enumerate}[font=\LARGE, %
                label=\fbox{\arabic*}, itemsep=18pt]%
                \sffamily\bfseries\Large}
\newcommand\footeri{\end{enumerate}} % keep it in sync with \headeri!

\newcommand\headerii{ \begingroup\normalfont\ttfamily(\def\item{, }\@gobble}
\newcommand\footerii{)\endgroup}

\newcommand\headeriii{\begingroup\scshape
                \let\item-$^\bgroup\hbox\bgroup\scriptsize\@gobble}
\newcommand\footeriii{\egroup\egroup$\endgroup} 

\makeatother


%------------ our beautiful macros
\makeatletter

\renewcommand\tableofcontents{%
\@starttoc{toc}%
\ifexisti
\the\agendatoks
\ifexistiii\footeriii\fi
\ifexistii\footerii\fi
\footeri
\fi}

\renewcommand\l@section[2]{%
  \let\@xp\expandafter
  \let\numberline\@gobble
  \def\hyper@linkstart{\noexpand\hyper@linkstart}%
  \def\hyper@linkend{\noexpand\hyper@linkend}%
  \edef\@jfbutmp{#1}%
  \ifexistiii\toks0={\footeriii}\else\toks0={}\fi
  \global\existiiifalse
  \ifexistii\toks0=\@xp{\the\toks0 \footerii}\fi 
  \global\existiifalse
  \ifexisti\else\toks0={\headeri}\fi  
  \global\existitrue
  \toks0=\@xp{\the\toks0 \item}% 
  \toks0=\@xp{\the\toks0\@jfbutmp}%
  \global\agendatoks=\@xp\@xp\@xp{\@xp\the\@xp\agendatoks\the\toks0}%
}

\renewcommand\l@subsection[2]{%
  \let\@xp\expandafter
  \let\numberline\@gobble
  \def\hyper@linkstart{\noexpand\hyper@linkstart}%
  \def\hyper@linkend{\noexpand\hyper@linkend}%
  \edef\@jfbutmp{#1}%
  \ifexistiii\toks0={\footeriii}\else\toks0={}\fi
  \global\existiiifalse
  \ifexistii\else\toks0={\headerii}\fi
  \global\existiitrue
  \toks0=\@xp{\the\toks0 \item}%
  \toks0=\@xp{\the\toks0\@jfbutmp}
  \global\agendatoks=\@xp\@xp\@xp{\@xp\the\@xp\agendatoks\the\toks0}
}

\renewcommand\l@subsubsection[2]{%
  \let\@xp\expandafter
  \let\numberline\@gobble
  \def\hyper@linkstart{\noexpand\hyper@linkstart}%
  \def\hyper@linkend{\noexpand\hyper@linkend}%
  \edef\@jfbutmp{#1}%
  \ifexistiii\toks0={}\else\toks0={\headeriii}\fi
  \global\existiiitrue
  \toks0=\@xp{\the\toks0 \item}%
  \toks0=\@xp{\the\toks0\@jfbutmp}%
  \global\agendatoks=\@xp\@xp\@xp{\@xp\the\@xp\agendatoks\the\toks0}%
}

\makeatother


% the following (from package titlesec) only influences the look of the body,
% not the table of contents
\titleformat{\section}
  {\normalfont\LARGE\bfseries\sffamily}{}{0em}{}
\titleformat{\subsection}
  {\normalfont\Large\sffamily}{}{1em}{}
\titleformat{\subsubsection}
  {\normalfont\large\ttfamily}{}{2em}{}

\begin{document}\thispagestyle{empty}

\tableofcontents

\section{First}
\kant[1]
\subsection{primo}
\kant[11]
\subsection{secondo}
\kant[12]
\subsubsection{i}
\kant[121]
\subsubsection{ii}
\kant[122]
\subsection{tertio}
\kant[13]
\subsubsection{i}
\kant[131]
\subsubsection{ii}
\kant[132]
\subsubsection{iii}
\kant[133]
\section{Second}
\kant[2]
\subsection{primo}
\kant[21]
\subsubsection{i}
\kant[111]
\subsubsection{ii}
\kant[112]
\subsubsection{iii}
\kant[113]
\subsection{secondo}
\kant[22]
\section{Third}
\kant[3]
\subsection{tertio}
\kant[33]
\section{Fourth}
\kant[4]
\subsection{quarto}
\kant[44]
\subsubsection{i}
\kant[141]
\subsubsection{ii}
\kant[142]
\subsubsection{iii}
\kant[143]

\end{document}

答案3

这是一个使用如何保存字符串的运行列表,然后逐个处理它们 存储所有 的标题\section*{},然后可以在末尾将其打印在枚举列表中。因此,对于以下文档:

\begin{document}
\section{First Non Starred Section}
\section*{First Starred section}
\section*{Second Starred section}

\section{Second Non Starred Section}
\section*{Third Starred section}
\section*{Fourth Starred section}
\end{document}

我们在文档末尾得到以下内容:

在此处输入图片描述

笔记:

  • 我用了包裹xparse区分\section和,\section*因为我更喜欢它的语法,但没有它应该也可以实现相同的功能。

代码:

\documentclass{article}
\usepackage{xparse}

% https://tex.stackexchange.com/questions/14393/how-keep-a-running-list-of-strings-and-then-process-them-one-at-a-time
\def\ListOfSectionTitles{}
\makeatletter
    \newcommand{\AddSectionTitle}[1]{\g@addto@macro\ListOfSectionTitles{{\item #1}}}
\makeatother

\let\OldSection\section
\RenewDocumentCommand{\section}{s m}{%
    \IfBooleanTF{#1}{%
        % This is a starred section, so store it's title
        \AddSectionTitle{#2}%
        \OldSection*{#2}%
    }{%
        \OldSection{#2}%
    }%
}

\AtEndDocument{%
    \textbf{List of Starred Sections:}
    \begin{enumerate}
        \ListOfSectionTitles
    \end{enumerate}
}%

\begin{document}
\section{First Non Starred Section}
\section*{First Starred section}
\section*{Second Starred section}

\section{Second Non Starred Section}
\section*{Third Starred section}
\section*{Fourth Starred section}
\end{document}

答案4

我想这就是你想要的:

\documentclass{scrartcl}
\usepackage{lipsum}

\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{0}

\makeatletter
\renewcommand\tableofcontents{\@starttoc{toc}}
\renewcommand*\l@section[2]{\item #1}
\makeatother
\AtBeginDocument{\addtocontents{toc}{\protect\begin{enumerate}}}
\AtEndDocument{\addtocontents{toc}{\protect\end{enumerate}}}

\begin{document}

\tableofcontents
\section{Agenda item one}
\lipsum[4]
\section{Agenda item two}
\lipsum[4]
\section{Agenda item three}
\lipsum[4]
\section{Agenda item four}
\lipsum[4]

\end{document}

在此处输入图片描述

相关内容