Search code examples
latexindentationpdflatexparagraph

Latex Numbered Hanging \paragraph


I am trying to write a document which uses seperate numbers for sections and paragraphs. I would like each \paragraph to have a hanging indent such that the first word of the second line, aligns with the first word of the first line.

Here is my code:

\documentclass{article}
\usepackage{a4wide}
\usepackage[english]{babel}
\usepackage{titlesec}

% Heading/Subheading counter
\newcounter{subsubsection}[subsubsection]
\newcounter{param} % Paragraph counter
\newcommand{\N}{%
   \noindent\refstepcounter{parnum}%
    \makebox[\parindent][l]{\arabic{parnum}.}}
\newcommand\YUGE{\fontsize{60}{100}\selectfont}

% Paragraph style
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} 
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{5}{\z@}%
    {1em} {-1em} {\normalsize\normalfont}}
\def\toclevel@subsubsubsection{4}
\def\toclevel@paragraph{5}
\def\l@subsubsubsection{\@dottedtocline{4}{7em}{4em}}
\def\l@paragraph{\@dottedtocline{5}{10em}{5em}}
\makeatother
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Scope}  
    \pagestyle{style1}
    \paragraph*{\N} The Scope of this document should number each paragraph sequentially:
    \begin{itemize}
        \item [a.] List item 1,
        \item [b.] List item 2, and
        \item [...] ...
        \item [n.] List item n.
    \end{itemize}
    \paragraph*{\N} Second paragraph with numbering
    
    \subsection{Intro}
    \paragraph*{\N} This is the intro.
    \paragraph*{\N} Intro cont.
    
    \subsubsection{related docs}
    \paragraph*{\N} Here is a list of the related docs
    \begin{itemize}
        \item [a.] ...
    \end{itemize}
\end{document}  

This is a picture of what it looks like currently. What the text looks like currently Here is a quick example in word as to how I want the paragraphs to work (disregard the different numbering and font type. I am only concerned with the hanging indent). What I want the text to look like


Solution

  • I found the answer; You need to use the following packages

    \usepackage{titlesec}
    \usepackage{etoolbox}
    

    Then you need to set the counter depth for the document to 5 and define a new counter. Which means you will be countering every; chapter, section, subsection, subsubsection, paragraph and subparagraph.

    \setcounter{secnumdepth}{5}
    \newcounter{para}
    \newcommand{\N}{\noindent\refstepcounter{para}\makebox[\parindent][l]{\arabic{para}.}}
    

    Now you can set up the format for each of the sections/subsections/paragraphs/etc

    \newlength\titleindent
    \setlength\titleindent{1.25cm}
    \pretocmd{\paragraph}{\stepcounter{subsubsection}}{}{}
    
    \titleformat{\section}{\normalfont\Large\bfseries}{\llap{\parbox{\titleindent}{\thesection\hfill}}}{0em}{}
    \titleformat{\subsection}{\normalfont\large\bfseries}{\llap{\parbox{\titleindent}{\thesubsection\hfill}}}{0em}{}
    \titleformat{\subsubsection}{\normalfont\normalsize\bfseries}{\llap{\parbox{\titleindent}{\thesubsubsection}}}{0em}{}
    \titleformat{\paragraph}[runin]{\normalfont\normalsize}{\llap{\parbox{\titleindent}{\N\hfill}}}{0em}{}
    
    \titlespacing*{\subsubsection}{0pt}{2ex plus 1ex minus 0.2ex}{1.5ex plus .2ex}
    \titlespacing*{\paragraph}{0pt}{2ex plus 1ex minus .2ex}{0ex plus 0ex}
    

    I did not use the subparagraph option to I changed the commands such that the numbering of paragraphs is the same level as subsubsections. This means a subsubsection might be numbered 1.2.1 if you have two paragraphs though the next subsubsection will be 1.2.4 is an issue I have yet to solve. The below is the original commands:

    \pretocmd{\paragraph}{\stepcounter{subsection}}{}{}
    \pretocmd{\subparagraph}{\stepcounter{subsubsection}}{}{}
    

    Importantly when writing your code, you need to use the following syntax at the beginning of each paragraph:

    \paragraph{} Some text
    

    Here is an example

    \begin{document}
    \section{title}
    \subsection{Intro}
        \paragraph{} The Scope of this document should number each paragraph sequentially:
        \begin{itemize}
            \item [a.] List item 1,
            \item [b.] List item 2, and
            \item [...] ...
            \item [n.] List item n.
        \end{itemize}
        \paragraph{} Second paragraph with numbering, this is sample text to explain the 
        hanging indent format, which should align with the second line of this paragraph 
        with the first line.
    
    \subsection{Intro}
        \paragraph{}This is the intro, this is sample text to explain the hanging indent 
        format, which should align with the second line of this paragraph with the first 
        line.
        \paragraph{} Intro cont, this is sample text to explain the hanging indent format, 
        which should align with the second line of this paragraph with the first line.
    
        \subsubsection{related docs}
            \paragraph{} Here is a list of the related docs
            \begin{itemize}
                \item [a.] ...
             \end{itemize}
    \end{document}
    

    This is what it looks like now enter image description here