我使用 tocloft 创建了自定义列表,并成功排版它们以替代目录(它是关于将歌曲分组为歌曲组的乐谱)。我现在想在每个歌曲集的开头有一个歌曲列表,就像 minitoc 为目录提供的那样。有没有一个包可以实现这个目的,还是我必须从头开始编写它。由于我的 TeX 知识非常有限,因此需要大量学习基本的 TeX。
一个最小的例子概括了我的问题课程:
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{songsheets}
[2015/10/01 v0.9h Class for song documentation]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions
\LoadClass{book}
\RequirePackage{tocloft}
%table of songs stuff
\renewcommand{\cftdot}{$\cdot$}
\newlistof[songset]{song}{tos}{Songs}
\newlistentry{songset}{tos}{0}
\providecommand*{\toclevel@songset}{0}%
\providecommand*{\toclevel@song}{1}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sectioning %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%definitions for a songset
\def\songsetname{Set}
\if@twoside
\def\ps@headings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songsetmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\def\ps@headings{%
\let\@oddfoot\@empty
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songsetmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}}}
\fi
\def\ps@myheadings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\@gobbletwo
\let\songsetmark\@gobble
\let\sectionmark\@gobble
}
\newcommand*\songsetmark[1]{}
\renewcommand \thesongset {\@Roman\c@songset}
\newcommand\songset{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@%
\@afterindentfalse%
\secdef\@songset%
\@ssongset%
}
\def\@songset[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{songset}%
\typeout{Defsongset \thesongset.}%
\addcontentsline{tos}{songset}%
{\protect\numberline{\thesongset} #2}%
\else
\addcontentsline{tos}{songset}{#2}%
\fi
\songsetmark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makesongsethead{\songsetname}]%
\else
\@makesongsethead{#1}%
\@afterheading
\fi}
\def\@makesongsethead#1{%
\typeout{Makesongsethead #1} %
% \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}
\def\@ssongset#1{\if@twocolumn
\typeout{Ssongset #1}%
\@topnewpage[\@makessongsethead{#1}]%
\else
\@makessongsethead{#1}%
\@afterheading
\fi}
\def\@makessongsethead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}
%definitions for a song
\def\songname{Title}
\if@twoside
\def\ps@headings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\def\ps@headings{%
\let\@oddfoot\@empty
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}}}
\fi
\def\ps@myheadings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\@gobbletwo
\let\songmark\@gobble
\let\sectionmark\@gobble
}
\newcommand*\songmark[1]{}
\newcommand\song{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@song\@ssong}
\def\@song[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{song}%
\typeout{\songname\space\thesong.}%
\addcontentsline{tos}{song}%
{\protect\numberline{\thesong} #2}%
\else
\addcontentsline{tos}{song}{#2}%
\fi
\songmark{#2}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makesonghead{#1}{#2}]%
\else
\@makesonghead{#1}{#2}%
\@afterheading
\fi}
\def\@makesonghead#1#2{%
% \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
{\Large\bfseries \songname\space\thesong:}
% \par\nobreak
% \vskip 20\p@
\fi
\fi
\interlinepenalty\@M
{\Large \bfseries #2}\hfill
}%
\vskip 10\p@
}
\def\@ssong#1{\if@twocolumn
\@topnewpage[\@makessonghead{#1}]%
\else
\@makessonghead{#1}%
\@afterheading
\fi}
\def\@makessonghead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
该文件:
\documentclass{songlist}
\begin{document}
\listofsong
\songset{}
I would like to have a table here, showing title1 and title2 as hyperlinks
\song[]{title1}content1
\song[]{title2}content2
\songset{}
I would like to have a table here, showing title3 and title4 as hyperlinks
\song[]{title3}content3
\song[]{title4}content4
\end{document}
为了在每个章节开头创建目录,我应该使用 minitoc。但是我发现没有办法将 tocloft 和 minitoc 结合起来,这样在每个歌曲集开头都给出歌曲列表(名为歌曲),只给出该歌曲集中的歌曲。这样问题清楚了吗?如果没有,请随时询问详细信息,因为我不知道您需要哪些详细信息。
答案1
这是一种方法。我添加了包埃托克到类文件。
类文件songsheets.cls
:
% modified by jfbu jeudi 05 novembre 2015 at 15:18:26
% (added etoc use)
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{songsheets}
[2015/10/01 v0.9h Class for song documentation]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions
\LoadClass{book}
\RequirePackage{tocloft}
\RequirePackage{etoc}
\RequirePackage[linktoc=all]{hyperref}
% tocloft table of songs stuff
\renewcommand{\cftdot}{$\cdot$}
\newlistof[songset]{song}{tos}{Songs}
\newlistentry{songset}{tos}{0}
\providecommand*{\toclevel@songset}{0}
\providecommand*{\toclevel@song}{1}
% moved here
\newcommand* \songsetmark [1]{}
\renewcommand*\thesongset {\@Roman\c@songset}
\newcommand* \songmark [1]{}
% etoc table of songs stuff
\newcommand*{\tableofsongs}
{%
\begingroup
\@for\@tempa:=part,chapter,section,subsection,paragraph\do
{\etocsetlevel{\@tempa}{6}}%
\etocsetlevel{songset}{0}%
\etocsetlevel{song}{1}%
\etocsetnexttocdepth{song}%
\renewcommand*\contentsname{Songs}%
\tableofcontents
\endgroup
}%
\newcommand*{\localtableofsongs}
{%
\begingroup
\@for\@tempa:=part,chapter,section,subsection,paragraph\do
{\etocsetlevel{\@tempa}{6}}%
\etocsetlevel{songset}{0}%
\etocsetlevel{song}{1}%
\etocsetnexttocdepth{song}%
\etocsettocstyle{\addvspace{\baselineskip}}{}%
\localtableofcontents
\endgroup
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% sectioning %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%definitions for a songset
\def\songsetname{Set}
\if@twoside
\def\ps@headings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songsetmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\def\ps@headings{%
\let\@oddfoot\@empty
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songsetmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\songsetname \thesongset. \ %
\fi
\fi
##1}}}}
\fi
\def\ps@myheadings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\@gobbletwo
\let\songsetmark\@gobble
\let\sectionmark\@gobble
}
% moved to top of file
% \newcommand*\songsetmark[1]{}
% \renewcommand \thesongset {\@Roman\c@songset}
\newcommand\songset{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@%
\@afterindentfalse%
\secdef\@songset%
\@ssongset%
}
\def\@songset[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{songset}%
\typeout{Defsongset \thesongset.}%
% \addcontentsline{tos}{songset}{\protect\numberline{\thesongset} #2}%
% replaced by etoc use of toc file
\addcontentsline{toc}{songset}{\protect\numberline{\thesongset} #2}%
\else
% \addcontentsline{tos}{songset}{#2}%
% replaced by etoc use of toc file
\addcontentsline{toc}{songset}{#2}%
\fi
\songsetmark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makesongsethead{\songsetname}]%
\else
\@makesongsethead{#1}%
\@afterheading
\fi}
\def\@makesongsethead#1{%
\typeout{Makesongsethead #1} %
% \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}
\def\@ssongset#1{\if@twocolumn
\typeout{Ssongset #1}%
\@topnewpage[\@makessongsethead{#1}]%
\else
\@makessongsethead{#1}%
\@afterheading
\fi}
\def\@makessongsethead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries \songsetname\nobreakspace\thesongset\hfill#1\par\nobreak
\vskip 40\p@
}}
%definitions for a song
\def\songname{Title}
\if@twoside
\def\ps@headings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songmark##1{%
\markboth {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}{}}%
\def\sectionmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\z@
\thesection. \ %
\fi
##1}}}}
\else
\def\ps@headings{%
\let\@oddfoot\@empty
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\markboth
\def\songmark##1{%
\markright {\MakeUppercase{%
\ifnum \c@secnumdepth >\m@ne
\songname\space\thesong. \ %
\fi
##1}}}}
\fi
\def\ps@myheadings{%
\let\@oddfoot\@empty\let\@evenfoot\@empty
\def\@evenhead{\thepage\hfil\slshape\leftmark}%
\def\@oddhead{{\slshape\rightmark}\hfil\thepage}%
\let\@mkboth\@gobbletwo
\let\songmark\@gobble
\let\sectionmark\@gobble
}
% \newcommand*\songmark[1]{}
\newcommand\song{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{plain}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@song\@ssong}
\def\@song[#1]#2{\ifnum \c@secnumdepth >\m@ne
\refstepcounter{song}%
\typeout{\songname\space\thesong.}%
% \addcontentsline{tos}{song}{\protect\numberline{\thesong} #2}%
% use of toc file for etoc
\addcontentsline{toc}{song}{\protect\numberline{\thesong} #2}%
\else
% \addcontentsline{tos}{song}{#2}%
% use of toc file for etoc
\addcontentsline{toc}{song}{#2}%
\fi
\songmark{#2}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makesonghead{#1}{#2}]%
\else
\@makesonghead{#1}{#2}%
\@afterheading
\fi}
\def\@makesonghead#1#2{%
% \vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
{\Large\bfseries \songname\space\thesong:}
% \par\nobreak
% \vskip 20\p@
\fi
\fi
\interlinepenalty\@M
{\Large \bfseries #2}\hfill
}%
\vskip 10\p@
}
\def\@ssong#1{\if@twocolumn
\@topnewpage[\@makessonghead{#1}]%
\else
\@makessonghead{#1}%
\@afterheading
\fi}
\def\@makessonghead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
文档songlist.tex
:
\documentclass{songsheets}
\begin{document}
\tableofsongs
\songset{}
I now have a table here, showing title1 and title2 as hyperlinks.
\localtableofsongs
\song[]{title1}content1
\song[]{title2}content2
\songset{}
I now have a table here, showing title3 and title4 as hyperlinks.
\localtableofsongs
\song[]{title3}content3
\song[]{title4}content4
\end{document}
输出:
第 1 页:
第 3 页:
第 9 页:
再次回到第 1 页,将超链接显示为红色框: