问题
如何将文本添加到目录中,但又将其范围限制在特定的表中,并且其格式可操作且没有页码?
状况
- 我可以隐藏它
\localtableofcontents
- 我可以在特定位置显示它
\localtableofcontents
并隐藏它\tableofcontents
- 我可以为其添加书签(以及指向以下内容开始的页面的页面引用(在我的情况下,该页面与语句 1 是同一页))
尝试
在尝试满足第一个标准后不久,我意识到自己陷入了停滞状态。下面描述了我的尝试。
\addcontentsline{toc}{part}{Special Documents}
\addtocontents{toc}{\vspace{4ex}\protect\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Special Documents}}\par}
1号允许我利用当前设置使部分仅在全局目录中可见这一事实。这并不理想,因为它消除了灵活性。最重要的是,这会添加一个条目,但该条目未格式化,并且该条目还具有页码。
2号允许我向目录添加美观、格式化、非编号的标题。但是,它会将其添加到每个本地目录中,这并不好。
\documentclass{article}
\usepackage{fontspec}
\usepackage{etoc}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{bookmark}
\newcommand{\inputlanguage}[2]{%
\newpage\pdfbookmark{#1}{bkm#1}%
\etoctoccontentsline{part}{#1}%
#2
}%
\newcommand{\inputotherdoc}[2]{%
\newpage\pdfbookmark{#1}{bkm#1}%
\etoctoccontentsline{part}{#1}%
#2
}%
\begin{document}
\setcounter{tocdepth}{0} % make ToC only contain Parts
\renewcommand{\contentsname}{\protect\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Language Directory}}\par} % In reality formatting is done with tocloft
\tableofcontents
\renewcommand{\contentsname}{Table of Contents}
\setcounter{tocdepth}{4} % reset back to default for local ToCs
\newpage
\inputlanguage{da}{\localtableofcontents\section{At vove er, at miste fodfæstet for en stund ikke at vove er, at miste sig selv}}
\lipsum[1]
\inputlanguage{de}{\localtableofcontents\section{Wer rastet, der rostet.}}
\lipsum[1]
\inputlanguage{en}{\localtableofcontents\section{Education is what remains after one has forgotten what one has learned in school.}}
\lipsum[1]
% Problem is here
\addcontentsline{toc}{part}{Special Documents} % I need to inject text here and be able to: change font, change size, change, add new paragraphs, remove page number (imitate the the Language Directory text (using titlesec in original document)
\addtocontents{toc}{\vspace{4ex}\protect\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Special Documents}}\par} % Second Attempt
\inputotherdoc{Statement 1}{{\Huge Secret Information\par\bigskip}Here is some top-secret, specialized text.}
\inputotherdoc{Statement 2}{{\Huge Specialized Information\par\bigskip}Here is some highly specialized text.}
\end{document}
输出
在下面的例子中,“特殊文件”应该只出现在语言目录中(\tableofcontents
),而不出现在本地目录中。
答案1
.toc
最简单的方法是通过向文件添加命令\addtocontents{toc}{\protect\mycommand}
,然后让其\mycommand
执行某些操作,并重新定义其自身以使其不执行任何操作。这不需要任何包。
但是我用etoc
它来说明\localtableofcontents
不会有额外的标题。(图中未显示,仅显示了主目录)
\documentclass{book}
\usepackage{etoc}
\usepackage{color}
% This will self-erase itself after first use
\newcommand*\SpecialDocumentsTocHeading
{\vspace{4ex}\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Special
Documents}}\par
\global\let\SpecialDocumentsTocHeading\empty }
\begin{document}
% This Main TOC will have the Special Documents Heading.
\etocsettocdepth{section}
\tableofcontents
\part{ONE}
\chapter{Test chapter one}
\etocarticlestyle % resets default to use \section*, not \chapter* for TOC heading
\localtableofcontents
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one two two}
\chapter{Test chapter two}
\localtableofcontents
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two two two}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\part{TWO}
\localtableofcontents
\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\addtocontents{toc}{\protect\SpecialDocumentsTocHeading}
\chapter{Top secret information}
\chapter{Ultra top secret information}
\end{document}
如果需要后续目录中的特殊文档(而不是第一个目录中的特殊文档),则应例如在序言中执行此操作:
\newcommand*{\SpecialDocumentsTocHeadingActive}
{\vspace{4ex}\noindent\parbox[t]{\textwidth}{\Huge\textcolor{red}{Special
Documents}}\par
\global\let\SpecialDocumentsTocHeading\empty }
\newcommand*{\SpecialDocumentsTocHeading}{}
% or rather slightly more efficient \let\SpecialDocumentsTocHeading\empty
然后在想要特殊文档标题出现的目录之前执行以下操作:
\renewcommand*{\SpecialDocumentsTocHeading}{\SpecialDocumentsTocHeadingActive}
% or with a less LaTeX-like but a bit more efficient syntax:
% \let\SpecialDocumentsTocHeading\SpecialDocumentsTocHeadingActive