子小节(段落)未显示在目录中

子小节(段落)未显示在目录中

要添加子子子部分(又名paragraph),我按照此处的说明进行操作:

现在,效果很好,但是我注意到它paragraph不会显示在目录中。我该如何将其添加到目录中?

更复杂的是,尽管我不希望对paragraph进行编号,因此我写了\paragprah*{},但我仍然希望它显示在目录中。为此,我尝试遵循:

有什么办法可以让我 paragraph 未编号 + 仍显示在目录中?

这是我的代码,它是上面两个链接的组合:

\documentclass[a4,12pt]{article}

\setcounter{secnumdepth}{4}

\usepackage{titlesec}

\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\begin{document}

\tableofcontents

\newpage
\section{Section}
\subsection{Sub section}
\subsubsection{Sub sub section}
\paragraph{Sub sub sub section}

\end{document}

答案1

方法 1:

\documentclass{article}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{4}

\begin{document}

\tableofcontents

\section{Section}
\subsection{Sub section}
\subsubsection{Sub sub section}

%\phantomsection % recommended if you're gonna use titlesec + hyperref, see https://tex.stackexchange.com/questions/364010/hyperref-and-titlesec-conflict-and-warning
\paragraph{Paragraph 1}
\paragraph*{Paragraph 2}

\end{document}

截图1

方法 2:

\documentclass{article}

\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

\begin{document}

\tableofcontents

\section{Section}
\subsection{Sub section}
\subsubsection{Sub sub section}

%\phantomsection % recommended if you're gonna use titlesec + hyperref, see https://tex.stackexchange.com/questions/364010/hyperref-and-titlesec-conflict-and-warning
% https://tex.stackexchange.com/a/210688/170958
\paragraph*{Paragraph 1}
%\label{par:paragraph}
\addcontentsline{toc}{paragraph}{Paragraph 1}

\paragraph{Paragraph 2}

\paragraph*{Paragraph 3}

\end{document}

截图2

相关内容