
Resolvi o problema, mas não sei por que funciona. Por favor, veja o comentário no final para perguntas de acompanhamento.
Encontrei várias perguntas semelhantes, mas nenhuma que se alinhe (ou pareça funcionar). No entanto, se isso for uma falha do meu Google-fu, basta vincular a pergunta relevante.
Estou tentando escrever um guia que inclua um FAQ no final. A maneira mais natural que pensei de fazer um FAQ foi usar o pacote hyperref e um minitoc para permitir que as pessoas lessem a pergunta e clicassem na resposta. Infelizmente, isso sobrecarrega o índice superior do guia com todas as perguntas frequentes. Deve haver uma maneira de suprimir as perguntas do FAQ no índice, mas ainda mostrá-las no minitoc. Tentei o \addstarredsection
comando na documentação do pacote minitoc, mas não consigo nem compilar direito, muito menos fazer o que quero. Alguma sugestão?
Um MWE (incluindo todos os pacotes que pretendo usar a partir de agora):
\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}
Como nota de rodapé, eu queria usar os pacotes titletoc e titlesec por outros motivos, e vi alguns posts sobre como usar o titletoc para obter um minitoc sem usar o pacote minitoc. Também tentei essas sugestões, mas não consegui compilar nenhuma das respostas sugeridas; até mesmo copiar/colar as respostas nos tópicos como um teste decisivo. Para ser justo, essas postagens pareciam muito antigas, então imagino que seja um problema com atualizações do LaTeX e/ou do pacote titletoc. Também abandonei as tentativas mais cedo, pois sabia que o minitoc já fazia mais ou menos o que eu queria e, de qualquer maneira, queria aprender como usá-lo melhor.
Editar:
Resolvi o problema inserindo \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
logo após a \part{FAQ}
linha. Eu sei que isso está definindo a profundidade do toc para não contrariar mais a seção (ou inferior) do índice analítico, portanto, eu esperaria (e é verdade) que o índice superior não tivesse nada depois da FAQ
parte.
O que não tenho certeza é por que o minitoc ainda está preenchendo todas as seções corretamente, quando essas seções não aparecem no índice superior. Se o tocprofundidade não afeta o minitoc, o que acontece? Achei que o minitoc analisasse o .toc
arquivo para obter seu conteúdo, portanto, qualquer coisa que não estivesse no toc teria problemas para estar no minitoc... mas aparentemente isso não é verdade. Alguém capaz de fornecer informações sobre o que está acontecendo aqui?
Responder1
Aqui está um caminho baseado na postagem:
Como adicionar um TOC personalizado ("Section Breakdown" automatizado) após cada comando \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}
Índice:
PARTE 3: