
문제를 해결했지만 왜 작동하는지 모르겠습니다. 후속 질문은 마지막에 있는 댓글을 참조하세요.
비슷한 질문을 여러 개 찾았지만 일치하는 질문은 없습니다(또는 작동하는 것 같습니다). 그러나 이것이 내 Google-fu의 실패인 경우 관련 질문에 대한 링크를 보내주십시오.
마지막에 FAQ를 포함하는 가이드를 작성하려고 합니다. FAQ를 작성하기 위해 제가 생각한 가장 자연스러운 방법은 사람들이 질문을 읽고 답변을 클릭할 수 있도록 hyperref 패키지와 minitoc을 사용하는 것이었습니다. 불행하게도 이로 인해 모든 FAQ 질문이 포함된 가이드의 상위 목차가 복잡해졌습니다. 목차에서 FAQ 질문을 표시하지 않고 minitoc에는 표시하는 방법이 있어야 합니다. 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}
. 나는 이것이 더 이상 목차의 섹션(또는 그 이하)에 대응하지 않도록 목차 깊이를 설정한다는 것을 알고 있습니다. 따라서 목차의 맨 위 표에는 해당 FAQ
부분 뒤에 아무것도 없을 것이라고 예상할 수 있습니다(사실입니다).
내가 확신할 수 없는 점은 해당 섹션이 목차 상단에 표시되지 않는데도 minitoc이 모든 섹션을 올바르게 채우는 이유입니다. toc뎁스가 minitoc에 영향을 주지 않는다면, 무엇을 합니까? 나는 minitoc이 .toc
파일의 내용을 얻기 위해 파일을 구문 분석했기 때문에 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부: