実際の目次に含めずに minitoc にセクションを追加する

実際の目次に含めずに minitoc にセクションを追加する

問題は解決しましたが、なぜ機能するのかわかりません。フォローアップの質問については、最後のコメントを参照してください。

類似の質問をいくつか見つけましたが、どれもぴったり一致するもの(または機能するもの)はありませんでした。ただし、これが私の Google 検索の失敗である場合は、関連する質問にリンクしてください。

私は最後に FAQ を含むガイドを書こうとしています。FAQ を作成する最も自然な方法は、hyperref パッケージと minitoc を使用して、ユーザーが質問を読んで回答をクリックできるようにすることでした。残念ながら、これではガイドの一番上の目次が FAQ の質問でごちゃごちゃしてしまいます。目次で FAQ の質問を抑制しながら、minitoc では FAQ の質問を表示する方法があるはずです。minitoc\addstarredsectionパッケージのドキュメントにあるコマンドを試しましたが、正しくコンパイルすることすらできず、望む動作はできません。何か提案はありますか?

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 パッケージを使用したかったのですが、minitoc パッケージを使用せずに titletoc を使用して minitoc を取得する方法についての投稿をいくつか見ました。これらの提案も試しましたが、提案された回答のいずれもコンパイルできませんでした。スレッド内の回答をコピー/ペーストしてリトマス試験として使用してもです。公平に言えば、これらの投稿は非常に古いようだったので、LaTeX および/または titletoc パッケージの更新に関する問題だと思います。また、minitoc が既に私が望んでいたことをほぼ実行していることはわかっていたので、私は早めに試みを断念しました。いずれにしても、minitoc をより適切に使用する方法を習得したかったのです。

編集:

\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}行の直後に挿入することで問題を修正しました\part{FAQ}。これにより、目次のセクション (またはそれ以下) に対抗しないように toc の深さが設定されることがわかっているため、上部の目次にはその部分の後に何もないことが予想されます (実際その通りです) FAQ

よくわからないのは、トップの目次にセクションが表示されていないのに、minitoc がすべてのセクションを正しく入力しているのはなぜかということです。tocdepth が minitoc に影響しないのなら、何が影響するのでしょうか? minitoc はファイルを解析して.tocその内容を取得するので、toc にないものは minitoc に含まれないと考えていましたが、どうやらそうではないようです。ここで何が起こっているのか、誰か詳しいことを教えてくれませんか?

答え1

投稿に基づいた方法は次のとおりです。

各 \chapter コマンドの後にカスタム TOC (自動化された「セクションの内訳」) を追加するにはどうすればよいでしょうか?

\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:

ここに画像の説明を入力してください

関連情報