0

To add a sub-sub-sub-section (aka a paragraph), I followed the instructions here:

Now, this works great, however, I noticed that the paragraph will not show in the TOC. How can I add it to the TOC?

To complicate things further, even though I do not want the paragraph to be numbered, and so, I write \paragprah*{}, I still want it to show in the table of content. To do that, I tried to follow:

Is there a way I can have a paragraph that is unnumbered + still shows in the TOC?

Here is the code I have, which is a combination of the two links above:

\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}
albert
  • 1,313
Aziz
  • 159
  • 2
    How about \setcounter{tocdepth}{4} and this? – steve Apr 21 '20 at 10:26
  • 1
    Or of course \renewcommand{\theparagraph}{} – steve Apr 21 '20 at 10:30
  • 2
    Or \setcounter{secnumdepth}{3} plus \setcounter{tocdepth}{4}, that's probably the best fix (since \renewcommand{\theparagraph}{} might well mess with the spacing in the ToC) – steve Apr 21 '20 at 10:36
  • I tried these solutions, and they do not seem to work. I think am getting close because I can see that in the TOC, there is an extra "white space" indicating that the paragraph is there, and I can click on a very small hyperlink box to go to the paragraph, but its not written in the TOC. Do you mind modifying the code above to one that works? – Aziz Apr 21 '20 at 10:44

1 Answers1

4

Approach 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}

screenshot1

Approach 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}

screenshot2

steve
  • 2,154
  • Bless your soul! This works perfectly in my much larger document. Thank you very much. – Aziz Apr 21 '20 at 11:41