我一直在为我们研讨会的摘要书创建乳胶模板。我定义了新命令,例如titleoftalk
,,,,...speaker
speakeaddress
email
\newcommand{\titleoftalk}[1]{\begin{center}{\large \bf #1}\\\end{center}}
\newcommand{\speaker}[1]{\begin{center}{\large #1}\end{center}}
\newcommand{\speakeraddress}[1]{\vspace{-0.75cm}\begin{center}{\it #1}\\ \vspace{1cm} ABSTRACT \end{center}}
\newcommand{\email}[1]{\textit{email:} \url{#1}}
并使用这些新命令为每位演讲者撰写摘要。我需要帮助来编写\addtocontents{toc}
命令。
假设我们有 2 篇摘要:
\speaker{Speaker 1}
\titleoftalk{Title 1}
%abstract of the first speaker is here
\speaker{Speaker 2}
\titleoftalk{Title 2}
%abstract of the second speaker is here
我想重新创建目录页
Title of Talks
1. Speaker 1 Title 1 ................................... the page number
2. Speaker 2 Title 2 ................................... the page number
我应该在哪里以及如何写下我的\addtocontents{toc}
命令?
答案1
有一种可能性是:
\documentclass{article}
\usepackage{lipsum}
\newcounter{speaker}
\newcommand{\speaker}[1]{%
\stepcounter{speaker}%
\csname phantomsection\endcsname
\begin{center}{\large #1}\end{center}
\addcontentsline{toc}{section}{\numberline{\thespeaker.}#1}
}
\newcommand{\titleoftalk}[1]{%
\begin{center}{\large\bfseries #1}\end{center}
\addcontentsline{toc}{subsection}{#1}
}
\makeatletter
\renewcommand*\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{1.8em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\hfil \nobreak\par%\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\renewcommand*\l@subsection{\@dottedtocline{2}{1.8em}{2.3em}}
\makeatother
\renewcommand\contentsname{Title of Talks}
\begin{document}
\tableofcontents
\newpage
\speaker{Name of Speaker A}
\titleoftalk{This is the title of the talk by speaker one}
\lipsum[1-10]
\speaker{Name of Speaker B}
\titleoftalk{This is the title of the talk by speaker two}
\lipsum[1-10]
\speaker{Name of Speaker C}
\titleoftalk{This is the title of the talk by speaker three}
\lipsum[1-10]
\speaker{Name of Speaker D}
\titleoftalk{This is the title of the talk by speaker four}
\lipsum[1-10]
\speaker{Name of Speaker E}
\titleoftalk{This is the title of the talk by speaker five}
\lipsum[1-10]
\end{document}
这个想法是在和内使用标准\tableofcontents
命令和,这样修改后的目录中的包含将自动完成。每个演讲者姓名将被格式化为一个部分,相应的标题将被格式化为一个子部分(使用默认和的略微修改版本)。如果使用,锚点将添加到适当的位置以具有功能性超链接。\addcontensline
\speaker
\titleoftalk
\l@section
\l@subsection
hyperref
以下是将演讲者姓名和图块放在同一行的变体:
\documentclass{article}
\usepackage{lipsum}
\newcounter{speaker}
\newcommand{\speaker}[1]{%
\gdef\currspeaker{#1}
\stepcounter{speaker}%
\csname phantomsection\endcsname
\begin{center}{\large #1}\end{center}
}
\newcommand{\titleoftalk}[1]{%
\begin{center}{\large\bfseries #1}\end{center}
\addcontentsline{toc}{section}{\numberline{\thespeaker.}\currspeaker~--~{\itshape#1}}
}
\makeatletter
\renewcommand*\l@section[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{1.8em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode %\bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\renewcommand*\l@subsection{\@dottedtocline{2}{1.8em}{2.3em}}
\makeatother
\renewcommand\contentsname{Title of Talks}
\begin{document}
\tableofcontents
\newpage
\speaker{Name of Speaker A}
\titleoftalk{This is the title of the talk by speaker one spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker B}
\titleoftalk{This is the title of the talk by speaker two}
\lipsum[1-10]
\speaker{Name of Speaker C}
\titleoftalk{This is the title of the talk by speaker three spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker D}
\titleoftalk{This is the title of the talk by speaker four}
\lipsum[1-10]
\speaker{Name of Speaker E}
\titleoftalk{This is the title of the talk by speaker five spanning more than one line for the example}
\lipsum[1-10]
\end{document}
如果不能(滥用)使用标准\tableofcontents
(因为,例如,它必须用于其预期目的),则可以轻松修改上述示例并\listoftalks
在的帮助下生成命令\@starttoc
;这里有一个例子展示了这种方法,使用了上面第二个示例代码中的格式:
\documentclass{article}
\usepackage{lipsum}
\newcounter{speaker}
\newcommand{\speaker}[1]{%
\gdef\currspeaker{#1}
\stepcounter{speaker}%
\csname phantomsection\endcsname
\begin{center}{\large #1}\end{center}
}
\newcommand{\titleoftalk}[1]{%
\begin{center}{\large\bfseries #1}\end{center}
\addcontentsline{tot}{speaker}{\numberline{\thespeaker.}\currspeaker~--~{\itshape#1}}
}
\makeatletter
\newcommand\listtalksname{Title of Talks}
\newcommand\listoftalks{\section*{\listtalksname}\@starttoc{tot}}
\newcommand*\l@speaker[2]{%
\ifnum \c@tocdepth >\z@
\addpenalty\@secpenalty
\addvspace{1.0em \@plus\p@}%
\setlength\@tempdima{1.8em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode %\bfseries
\advance\leftskip\@tempdima
\hskip -\leftskip
#1\nobreak\leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\endgroup
\fi}
\makeatother
\begin{document}
\listoftalks
\newpage
\speaker{Name of Speaker A}
\titleoftalk{This is the title of the talk by speaker one spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker B}
\titleoftalk{This is the title of the talk by speaker two}
\lipsum[1-10]
\speaker{Name of Speaker C}
\titleoftalk{This is the title of the talk by speaker three spanning more than one line for the example}
\lipsum[1-10]
\speaker{Name of Speaker D}
\titleoftalk{This is the title of the talk by speaker four}
\lipsum[1-10]
\speaker{Name of Speaker E}
\titleoftalk{This is the title of the talk by speaker five spanning more than one line for the example}
\lipsum[1-10]
\end{document}