
我解決了這個問題,但我不知道為什麼它會起作用。後續問題請參閱最後的評論。
我發現了幾個類似的問題,但沒有一個完全一致(或似乎有效)。但是,如果這是我的 Google-fu 的失敗,請簡單連結到相關問題。
我正在嘗試編寫一個指南,最後包含常見問題。我認為做常見問題解答的最自然的方法是使用 hyperref 套件和 minitoc 讓人們閱讀問題並點擊答案。不幸的是,這將指南的頂部目錄與所有常見問題混為一談。必須有一種方法可以抑制目錄中的常見問題解答問題,但仍然在 minitoc 中顯示它們。我嘗試了\addstarredsection
minitoc 套件文件中的命令,但我什至無法正確編譯它,更不用說做我想做的事情了。有什麼建議麼?
一個 MWE(包括我現在打算使用的所有軟體包):
\documentclass{article}
\usepackage{hyperref}
\hypersetup{% % Setup the coloring of the links.
% % Currently the only necessary one is "colorlinks=true" and "linkcolor=blue".
colorlinks = true, % Colours links instead of ugly boxes
urlcolor = blue, % Colour for external hyperlinks
linkcolor = blue, % Colour of internal links
citecolor = blue % Colour of citations, could be ``red''
}
\usepackage[
margin=1in,% All 4 margins need to be one inch.
paperheight=11in,% We want 11in tall paper.
paperwidth=8.5in% And 8.5in wide paper.
]{geometry}% Geometry package is the easiest way to deal with margins.
\usepackage{fancyhdr}
\usepackage{indentfirst}
\pagestyle{fancy}
\usepackage{titlesec}% Use this for the actual header styling
\usepackage{titletoc}% Use this to manipulate Table of Contents styling
\usepackage{minitoc}% To form a miniture table of contents for the FAQ.
\title{A guide to Stuff}
\author{Me}
\date{}
\begin{document}
\maketitle
\newpage
\section*{Introduction}
\newpage
\doparttoc\tableofcontents
\newpage
\part{Part 1}
\newpage
\section{Subsection of Part 1}
\newpage
\section{Second Subsection of Part 1}
\newpage
\part{Part 2}
\newpage
\section{Subsection of Part 2}
\newpage
\section{Second Subsection of Part 2}
\newpage
\part{FAQ}
% Every section (or subsection) below this should appear in the minitoc but NOT the main table of contents. Bonus points for being able to show *only* sections and not subsections, although this should simply be a matter of setting the toc depth in theory.
\parttoc
\section*{Question One}
%\addstarredsection{Question One}
Q1
\section{Question Two}
Q2
\subsection{Subquestion of Question Two}
SubQ1
\subsection{Another subquestion of Question Two}
SubQ2
\section{Question Three}
Q3
\end{document}
作為腳註,我出於其他原因想使用 titletoc 和 titlesec 包,並且我看過一些關於如何使用 titletoc 來獲取 minitoc 而不使用 minitoc 包的帖子。我也嘗試了這些建議,但無法獲得任何建議的答案進行編譯;甚至將答案複製/貼上到線程中作為試金石。公平地說,這些帖子似乎很舊,所以我想這是 LaTeX 和/或 titletoc 包更新的問題。我也很早就放棄了這些嘗試,因為我知道 minitoc 或多或少已經做了我想要的事情,無論如何我都想學習如何更好地使用 minitoc。
編輯:
我通過\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
在該行之後插入來解決這個問題\part{FAQ}
。我知道這將目錄深度設置為不再與目錄的部分(或更低部分)相對應,因此我希望(這是事實)頂部目錄在該FAQ
部分之後沒有任何內容。
我不確定的是,當這些部分沒有顯示在頂部目錄中時,為什麼 minitoc 仍然正確填充所有部分。如果 tocdepth 不影響 minitoc,那麼什麼會影響呢?我認為 minitoc 解析了.toc
文件以獲取其內容,因此目錄中沒有的任何內容在 minitoc 中都會遇到麻煩......但顯然這不是真的。任何人都能夠提供有關這裡發生的事情的見解嗎?
答案1
這是基於帖子的方法:
如何在每個 \chapter 指令後面新增自訂目錄(自動「章節細分」)?
\documentclass{article}
\usepackage{hyperref}
\hypersetup{% % Setup the coloring of the links.
% % Currently the only necessary one is "colorlinks=true" and "linkcolor=blue".
colorlinks = true, % Colours links instead of ugly boxes
urlcolor = blue, % Colour for external hyperlinks
linkcolor = blue, % Colour of internal links
citecolor = blue % Colour of citations, could be ``red''
}
\usepackage[
margin=1in,% All 4 margins need to be one inch.
paperheight=11in,% We want 11in tall paper.
paperwidth=8.5in% And 8.5in wide paper.
]{geometry}% Geometry package is the easiest way to deal with margins.
\usepackage{fancyhdr}
\usepackage{indentfirst}
\pagestyle{fancy}
%\usepackage{titlesec}% Use this for the actual header styling
%\usepackage{titletoc}% Use this to manipulate Table of Contents styling
\usepackage{minitoc}% To form a miniture table of contents for the FAQ.
%koleygr: ADDED CODE
\usepackage{pgffor}
%\newcounter{mychapter}
%\renewcommand\thepart{\Alph{part}}
%\newcommand\thechapter{\thepart.\arabic{mychapter}}
%\renewcommand\thesection{\thechapter.\arabic{section}}
%\renewcommand\thesubsection{\thesection.\arabic{subsection}}
\let\oldpart\part
%\def\part#1{\oldpart{#1}\setcounter{mychapter}{0}\refstepcounter{mychapter}}
\let\oldsection\section
\let\oldsubsection\subsection
%\let\olldchapter\chapter
%\def\oldchapter{\stepcounter{mychapter}\olldchapter}
\makeatletter
\newcounter{mysection}
\newcounter{mysubsection}
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}
\def\@StarredWith[#1]#2{%
\oldsection*{#2}\refstepcounter{mysection}\label{Sec:\arabic{mysection}}%
}
\def\@StarredWithout#1{
\oldsection*{#1}\refstepcounter{mysection}\label{Sec:\arabic{mysection}}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{#2}\refstepcounter{mysection}\label{Sec:\arabic{mysection}}%
}
\def\@nonStarredWithout#1{%
\oldsection{#1}\refstepcounter{mysection}\label{Sec:\arabic{mysection}}%
}
\def\subsection{%
\@ifstar{\@StarredS}{\@nonStarredS}%
}
\def\@StarredS{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredSWith}%
{\@StarredSWithout}%
}
\def\@StarredSWith[#1]#2{%
\oldsubsection*{#2}\refstepcounter{mysubsection}\label{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
\def\@StarredSWithout#1{%
\oldsubsection*{#1}\refstepcounter{mysubsection}\label{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
\def\@nonStarredS{%
\@ifnextchar[%
{\@nonStarredSWith}%
{\@nonStarredSWithout}%
}
\def\@nonStarredSWith[#1]#2{%
\oldsubsection[#1]{#2}\refstepcounter{mysubsection}\label{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
\def\@nonStarredSWithout#1{%
\oldsubsection{#1}\refstepcounter{mysubsection}\label{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
%\MakeRobust{\ref}
\newcommand{\labeltext}[2]{%
\immediate\write\@auxout{%
\string\newlabel{#2}{{1}{\thepage}{\unexpanded{#1}}{#2}{}}%
}%
}
\newcommand\stopTOC{%
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}
\def\@StarredWith[##1]##2{%
\oldsection*{##2}\refstepcounter{mysection}\labeltext{##2}{Sec:\arabic{mysection}}%
}
\def\@StarredWithout##1{
\oldsection*{##1}\refstepcounter{mysection}\labeltext{##1}{Sec:\arabic{mysection}}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[##1]##2{%
\oldsection*{\arabic{section}\hspace{1em}{##2}}\refstepcounter{mysection}\labeltext{\refstepcounter{section}\arabic{section}\hspace{1em}##2}{Sec:\arabic{mysection}}%
}
\def\@nonStarredWithout##1{%
\oldsection*{\arabic{section}\hspace{1em}{##1}}\refstepcounter{mysection}\labeltext{\refstepcounter{section}\arabic{section}\hspace{1em}##1}{Sec:\arabic{mysection}}%
}
\def\subsection{%
\@ifstar{\@StarredS}{\@nonStarredS}%
}
\def\@StarredS{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredSWith}%
{\@StarredSWithout}%
}
\def\@StarredSWith[##1]##2{%
\oldsubsection*{##2}\refstepcounter{mysubsection}\label{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
\def\@StarredSWithout##1{%
\oldsubsection*{##1}\refstepcounter{mysubsection}\label{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
\def\@nonStarredS{%
\@ifnextchar[%
{\@nonStarredSWith}%
{\@nonStarredSWithout}%
}
\def\@nonStarredSWith[##1]##2{%
\oldsubsection*{\arabic{section}.\arabic{subsection}\hspace{1em}##2}\refstepcounter{mysubsection}\labeltext{\refstepcounter{subsection}\arabic{section}.\arabic{subsection}\hspace{1em}##2}{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
\def\@nonStarredSWithout##1{%
\oldsubsection*{\arabic{section}.\arabic{subsection}\hspace{1em}##1}\refstepcounter{mysubsection}\labeltext{\refstepcounter{subsection}\arabic{section}.\arabic{subsection}\hspace{1em}##1}{SubSec:\arabic{mysection}:\arabic{mysubsection}}%
}
}
%SectionBreakDown
\newcounter{secc}
\newcounter{ssecc}
\newcounter{tssecc}
\xdef\OverC{0}
\newcommand\SBD[2][1,-1]{%
\xdef\OverC{0}%
\def\Continued\empty%
\def\ToBeContinued{-1}%
\foreach \opt[count=\ll from 1] in {#1}{%
\ifnum\ll=1
\xdef\Continued{\opt}%
\else
\xdef\ToBeContinued{\opt}%
\fi
}%
\ifx\ToBeContinued\empty
\xdef\ToBeContinued{-1}%
\fi
\ifx\Continued\empty
\xdef\Continued{1}%
\fi
%
%\section{Section breakdown}
\ifnum\Continued>0
\else
\noindent{\large\bfseries Contents}%
\noindent\rule{\textwidth}{2pt}\vspace{0.5cm}
\setcounter{secc}{0}%
\setcounter{ssecc}{0}%
\setcounter{tssecc}{0}%
\fi
%
{\noindent #2}\par
%
%
\ifnum\ToBeContinued<0
\def\ContinueUntil{100}%
\else
\def\ContinueUntil{\ToBeContinued}%
\fi
%
\foreach \mk in {\Continued,...,\ContinueUntil}{%
\@ifundefined{r@Sec:\mk}{%
\breakforeach%
}{%
\setcounter{secc}{\mk}%
\ifnum\mk<0
\breakforeach%
\else
\ifnum\mk>\ContinueUntil
\\\breakforeach%
\else
\noindent{\bfseries{\nameref{Sec:\mk}\dotfill\pageref{Sec:\mk}}\\[1.2ex]}
\foreach \ml in {1,...,100}{%
\@ifundefined{r@SubSec:\mk:\ml}{%
\breakforeach%
}{%
\setcounter{ssecc}{\ml}%
\stepcounter{tssecc}%
\ifnum\mk>0
\hspace{0.3cm}\parbox[t]{\textwidth}{\setlength{\baselineskip}{4pt}\nameref{SubSec:\mk:\ml}\dotfill\pageref{SubSec:\mk:\ml}\\[0.9ex]}\\
\fi
}%
}%
\fi
\fi
}%
}
%\begin{enumerate}[label={\arabic{enumi}.},itemsep=0pt]
%\foreach \i in {#3,...,#4}
%{\item \nameref{\thechapter:\i}}
%\end{enumerate}
\ifnum\ToBeContinued>0
\relax%
\else
\vspace{-0.cm}
\par
\noindent\rule{\textwidth}{2pt}
\fi
}
\makeatother
%koleygr: END ADDED CODE
\title{A guide to Stuff}
\author{Me}
\date{}
\begin{document}
\maketitle
\newpage
\section*{Introduction}
\newpage
\doparttoc\tableofcontents
\newpage
\part{Part 1}
\newpage
\section{Subsection of Part 1}
\newpage
\section{Second Subsection of Part 1}
\newpage
\part{Part 2}
\newpage
\section{Subsection of Part 2}
\newpage
\section{Second Subsection of Part 2}
\newpage
\part{FAQ}
\stopTOC
\SBD[0,1]{}
\SBD[7,-1]{}
%\parttoc
\section*{Question One}
%\addstarredsection{Question One}
Q1
\section{Question Two}
Q2
\subsection{Subquestion of Question Two}
SubQ1
\subsection{Another subquestion of Question Two}
SubQ2
\section{Question Three}
Q3
\end{document}
目錄:
第 3 部分: