[根据评论进行编辑以简化和更新问题]
我想在文档开头创建内容列表,其中包含章节标题和关键字列表,符合特定格式。以下是迄今为止的最小示例:
\documentclass[11pt,a4paper,onecolumn,oneside]{memoir}
\usepackage[marginparwidth=2cm,textwidth=18.5cm,textheight=26cm]{geometry} % X
\usepackage[danish]{babel}
\usepackage[danish]{isodate}
\usepackage[utf8x]{inputenc}
\usepackage{titlesec}
\usepackage{multicol}
\makechapterstyle{Minimal}{%
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapternamenum}{}
\renewcommand*{\chapnumfont}{}
\renewcommand*{\printchapternum}{}
\renewcommand*{\afterchapternum}{}
\setlength{\beforechapskip}{0pt}
\setlength{\midchapskip}{0pt}
\setlength{\afterchapskip}{20pt}
}
\titleformat{\section}[runin]{\bfseries}{}{0pt}{}[~~]
\titlespacing{\section}{0pt}{0pt}{0pt}
\cftpagenumbersoff{section}
\titleformat{\subsection}[runin]{\bfseries}{}{0pt}{}[~~]
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\cftpagenumbersoff{subsection}
\newcommand{\bigpar}{\vspace{1em}}
\newcommand{\Word}[1]{%
{{\bfseries#1}\addcontentsline{toc}{subsection}{#1}}
}
\setsecnumdepth{chapter}
\newcommand*{\setupparasubsecs}{%
\let\oldnumberline\numberline
\renewcommand*{\cftsubsectionfont}{\itshape}
\renewcommand*{\cftsubsectionpagefont}{\itshape}
\renewcommand{\l@subsection}[2]{%
\def\numberline####1{\textit{####1}~}%
\leftskip=\cftsubsectionindent
\rightskip=\@tocrmarg
%% \advance\rightskip 0pt plus \hsize % uncomment this for raggedright
%% \advance\rightskip 0pt plus 2em % uncomment this for semi-raggedright
\parfillskip=\fill
\ifhmode ,\ \else\noindent\fi
\ignorespaces{\cftsubsectionfont ##1}~{\cftsubsectionpagefont##2}%
\let\numberline\oldnumberline\ignorespaces}
}
%\AtEndDocument{\addtocontents{toc}{\par}
\newcommand*{\setupmaintoc}{%
\renewcommand{\contentsname}{\vspace{-1.2cm}}
\let\changetocdepth\oldchangetocdepth
\let\precistoctext\oldprecistoctext
\let\cftchapterfillnum\oldcftchapterfillnum\addtodef{\cftchapterbreak}{\par}{}
\renewcommand*{\cftchapterfont}{\normalfont\sffamily}
\renewcommand*{\cftchapterleader}{%
\sffamily\cftdotfill{\cftchapterdotsep}}
\renewcommand*{\cftchapterafterpnum}{}
\renewcommand{\cftchapterbreak}{\par\addpenalty{-\@highpenalty}}
\setpnumwidth{2.55em}
\setrmarg{3.55em}\setcounter{tocdepth}{2}}
\let\cftpartformatpnum\oldcftpartformatpnum
\addtodef{\cftpartbreak}{\par}{}
\let\cftbookformatpnum\oldcftbookformatpnum\addtodef{\cftbookbreak}{\par}{}
%\setupparasubsecs
\begin{document}
\mainmatter
\chapterstyle{Minimal}
\chapter*{Title}
\begin{multicols}{2}
\setupmaintoc
\tableofcontents*
\end{multicols}
\section{Section title 1} - Date: 01.01.2011
Lorem ipsum dolor sit \Word{amet}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \Word{voluptate} velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\subsection{Ut enim ad minim veniam:} Ut enim ad minim veniam, quis \Word{nostrud} exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in \Word{reprehenderit} in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \Word{proident}, sunt in culpa qui officia deserunt mollit anim id est laborum.
\section{Section title 2} - Date: 02.01.2011
Lorem ipsum dolor sit \Word{amet}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \Word{voluptate} velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis \Word{nostrud} exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in \Word{reprehenderit} in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \Word{proident}, sunt in culpa qui officia deserunt mollit anim id est laborum.
\section{Section title 3} - Date: 03.01.2011
Lorem ipsum dolor sit \Word{amet}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \Word{voluptate} velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis \Word{nostrud} exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in \Word{reprehenderit} in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \Word{proident}, sunt in culpa qui officia deserunt mollit anim id est laborum.
该列表如下所示:
我希望它看起来像这样:
我尝试遵循回忆录手册第 9.2.5 节。注释掉的两段代码来自那里。
注释掉的部分会出现以下错误:
\setupparasubsecs
“参数必须连续编号。[\setupparasubsecs]” “您不能在水平模式下使用‘宏参数字符 #’。[\setupparasubsecs]”
\AtEndDocument{\addtocontents{toc}{\par}
TeX 已停止:扫描使用 \AddToHook{\addtocontents {toc}{\par } \par \newcommand *{\setupmaintoc }{\renewcommand 时文件结束 TeX 报告错误发生在文件中:minimalexample.tex
答案1
正如我所说,我的 LaTeX 技能正在迅速下降。不过,我已经根据您修改后的 MWE 整理出了一些接近您所追求的东西。
% memwordtocprob.tex SE 603784
%%%%%%%%%%%%%%%%%%%%%% OP's revised MWE and my edits following my first attempt
\documentclass[11pt,a4paper,onecolumn,oneside]{memoir}
\usepackage[marginparwidth=2cm,textwidth=18.5cm,textheight=26cm]{geometry} % X
\usepackage[danish]{babel}
\usepackage[danish]{isodate}
\usepackage[utf8x]{inputenc}
\usepackage{titlesec}
\usepackage{multicol}
\usepackage{comment}
\makechapterstyle{Minimal}{%
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapternamenum}{}
\renewcommand*{\chapnumfont}{}
\renewcommand*{\printchapternum}{}
\renewcommand*{\afterchapternum}{}
\setlength{\beforechapskip}{0pt}
\setlength{\midchapskip}{0pt}
\setlength{\afterchapskip}{20pt}
}
\titleformat{\section}[runin]{\bfseries}{}{0pt}{}[~~]
\titlespacing{\section}{0pt}{0pt}{0pt}
\cftpagenumbersoff{section}
\begin{comment}
\titleformat{\subsection}[runin]{\bfseries}{}{0pt}{}[~~]
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\end{comment}
\newcommand{\bigpar}{\vspace{1em}}
\newcommand{\Word}[1]{%
{{\bfseries#1}\addcontentsline{toc}{subsection}{#1}}
}
\setsecnumdepth{chapter}
%%%% PW note the \makeatletter ... \makeatother and changes
\makeatletter
\newcommand*{\setupparasubsecs}{%
\let\oldnumberline\numberline
\renewcommand*{\cftsubsectionfont}{\itshape}
\renewcommand*{\cftsubsectionpagefont}{\itshape}
\renewcommand{\l@subsection}[2]{%
% \def\numberline####1{\textit{####1}~}%
\def\numberline####1{\textit{####1}}%
\leftskip=\cftsubsectionindent
\rightskip=\@tocrmarg
%% \advance\rightskip 0pt plus \hsize % uncomment this for raggedright
%% \advance\rightskip 0pt plus 2em % uncomment this for semi-raggedright
\parfillskip=\fill
% \ifhmode ,\ \else\noindent\fi
\ifhmode,\ \else\noindent\fi
% \ignorespaces{\cftsubsectionfont ##1}~{\cftsubsectionpagefont##2}%
\ignorespaces{\cftsubsectionfont ##1}~%{\cftsubsectionpagefont##2}% no page numbers
\let\numberline\oldnumberline\ignorespaces}
}
%\cftpagenumbersoff{subsection}
\makeatother
\newcommand*{\setupmaintoc}{%
\renewcommand{\contentsname}{\vspace{-1.2cm}}
\let\changetocdepth\oldchangetocdepth
\let\precistoctext\oldprecistoctext
\let\cftchapterfillnum\oldcftchapterfillnum\addtodef{\cftchapterbreak}{\par}{}
\renewcommand*{\cftchapterfont}{\normalfont\sffamily}
\renewcommand*{\cftchapterleader}{%
\sffamily\cftdotfill{\cftchapterdotsep}}
\renewcommand*{\cftchapterafterpnum}{}
\renewcommand{\cftchapterbreak}{\par\addpenalty{-\@highpenalty}}
\setpnumwidth{2.55em}
\setrmarg{3.55em}\setcounter{tocdepth}{2}}
\let\cftpartformatpnum\oldcftpartformatpnum
\addtodef{\cftpartbreak}{\par}{}
\let\cftbookformatpnum\oldcftbookformatpnum\addtodef{\cftbookbreak}{\par}{}
%\setupparasubsecs
\begin{document}
\setupparasubsecs
\mainmatter
\chapterstyle{Minimal}
\chapter*{Title}
\begin{multicols}{2}
\setupmaintoc
\tableofcontents*
\end{multicols}
\section{Section title 1} - Date: 01.01.2011
Lorem ipsum dolor sit \Word{amet}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \Word{voluptate} velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\subsection{Ut enim ad minim veniam:} Ut enim ad minim veniam, quis \Word{nostrud} exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in \Word{reprehenderit} in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \Word{proident}, sunt in culpa qui officia deserunt mollit anim id est laborum.
\section{Section title 2} - Date: 02.01.2011
Lorem ipsum dolor sit \Word{amet}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \Word{voluptate} velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis \Word{nostrud} exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in \Word{reprehenderit} in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \Word{proident}, sunt in culpa qui officia deserunt mollit anim id est laborum.
\section{Section title 3} - Date: 03.01.2011
Lorem ipsum dolor sit \Word{amet}, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \Word{voluptate} velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis \Word{nostrud} exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in \Word{reprehenderit} in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \Word{proident}, sunt in culpa qui officia deserunt mollit anim id est laborum.
\section{PW section} % PW added
\end{document} % PW added
现在我把如何得到你想要的东西交给你了。