如何为某些项目制作具有多个(我正好需要两个)页码的目录?而无需创建自定义表格。正确的做法是,我有几个不同的部分,里面有同名的子集,例如理论/任务/答案,但在目录中,它们必须显示为一个项目。
我的例子:
\documentclass{article}
\usepackage[T2A]{fontenc}
% show numeration only for subsections
\renewcommand\thesection{}
\renewcommand\thesubsection{\arabic{subsection}}
\begin{document}
\tableofcontents
\newpage\section{Theory}
\newcommand{\firstTitle}{First Subject}
\subsection{\firstTitle} some theory
\newcommand{\secondTitle}{Second Subject}
\subsection{\secondTitle} some theory
\newpage\section{Tasks}
\subsection{\firstTitle}some tasks
\subsection{\secondTitle}some tasks
\end{document}
答案1
这是一个借助nameref
包的解决方案
\documentclass{article}
\usepackage{nameref}
% show numeration only for subsections
\renewcommand\thesection{}
\renewcommand\thesubsection{\arabic{subsection}}
\makeatletter
\renewcommand\@pnumwidth{4em} % more space for p1 -- p2 in toc
\makeatother
\newcommand{\theory}[1]{%
\renewcommand\addcontentsline[3]{}%
\newcommand{\newsubsection}[1]{%
\subsection{##1}\label{\thesubsection}}%
\newpage\section{#1}%
}
\newcommand{\tasks}[1]{%
\newpage\section{#1}%
\renewcommand\addcontentsline[3]{%
\addtocontents{##1}{\protect\contentsline{##2}{##3}{\pageref{\thesubsection} --- \thepage}}}%
\renewcommand{\newsubsection}{%
\subsection{\nameref{\thesubsection}}}%
}
\begin{document}
\tableofcontents
\theory{Theory}
\newsubsection{First Subject}
some theory
\newsubsection{Second Subject}
some theory
\tasks{Tasks}
\newsubsection
some tasks
\newsubsection
some tasks
\end{document}