1

I am new to Latex. I need a document structure like this with the numbering in margin.enter image description here

However I am unable to get the \paragraph and \subparagraph working even though the secnumdepth is set to 5 in my code. The code that I have used is based on answer given here in the forum

The code I have used is given below:

\documentclass{article}
\usepackage{lipsum}
\usepackage{titlesec,titletoc}
\usepackage{etoolbox}
\usepackage{lipsum}

\setcounter{secnumdepth}{5}

\renewcommand\thesection{\arabic{section}}

% this length controls tha hanging indent for titles
% change the value according to your needs
\newlength\titleindent
\setlength\titleindent{2cm}

% counters for the new sectional units
\newcounter{subsectionwt}
\newcounter{subsubsectionwt}

% definition of the new sectional units with the representation of the counters
\titleclass{\subsectionwt}{straight}[\subsubsection]
\renewcommand{\thesubsectionwt}{\thesection.\arabic{subsectionwt}}

\titleclass{\subsubsectionwt}{straight}[\subsectionwt]
\renewcommand{\thesubsubsectionwt}{\thesubsection.\arabic{subsubsectionwt}}

% \subsection must increase the subsectionwt counter
% and \subsectionwt must increase the subsection counter
% Analogous treatment for \subsubsection and \subsubsectionwt
\pretocmd{\subsectionwt}{\stepcounter{subsection}}{}{}
\pretocmd{\subsection}{\stepcounter{subsectionwt}}{}{}
\pretocmd{\subsubsectionwt}{\stepcounter{subsubsection}}{}{}
\pretocmd{\subsubsection}{\stepcounter{subsubsectionwt}}{}{}

% format for the sectional units
\titleformat{\chapter}[block]
  {\normalfont\huge\bfseries}{}{0pt}{\hspace*{-\titleindent}}

\titleformat{\section}
  {\normalfont\Large\bfseries}{\llap{\parbox{\titleindent}{\thesection\hfill}}}{0em}{}

\titleformat{\subsection}
  {\normalfont\large}{\llap{\parbox{\titleindent}{\thesubsection\hfill}}}{0em}{\bfseries}

\titleformat{\subsectionwt}[runin]
  {\normalfont\large}{\llap{\parbox{\titleindent}{\thesubsectionwt\hfill}}}{0em}{\bfseries}

\titleformat{\subsubsection}
  {\normalfont\normalsize}{\llap{\parbox{\titleindent}{\thesubsubsection}}}{0em}{\bfseries}

\titleformat{\subsubsectionwt}[runin]
  {\normalfont\normalsize}{\llap{\parbox{\titleindent}{\thesubsubsectionwt}}}{0em}{\bfseries}

\titlespacing*{\chapter}{0pt}{0pt}{20pt}
\titlespacing*{\subsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsectionwt}{0pt}{3.25ex plus 1ex minus .2ex}{0em}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsectionwt}{0pt}{3.25ex plus 1ex minus .2ex}{0em}

% numbered entries without title shouldn't go to the ToC
\titlecontents{subsectionwt}[]{}{}{}{}
\titlecontents{subsubsectionwt}[]{}{}{}{}

\begin{document}
\section{Section One}
Section One Text
\subsection{Sub Section One One}
Sub Section One One Text
\subsectionwt{}
Sub Section One One Text without title

\subsubsection{Sub Sub Section One One One}
Sub Sub Section One One OneText
\subsubsectionwt{}
Sub Sub Section One One OneText without title

\paragraph{} Lorem ipsum dolor sit amet, sed ea nihil clita adolescens, sea tation libris ad, sed an omittam comprehensam.
\subparagraph{}Id summo invenire his. Paulo posidonium honestatis ei cum, per cu aliquid salutatus consequuntur. 

\end{document}

Using the code advised by David Carlisle in his answer I have modified my code and also the sample document text(to make it more meaningful in structure and readability). The modified code is below:

\documentclass{article}

\setcounter{secnumdepth}{5}

\renewcommand\thesection{\arabic{section}}

\makeatletter


\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1sp}%
                                    {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\z@}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1sp}%
                                      {\normalfont\normalsize\bfseries}}

% like section and subsection but inline not display (-sp) and with empty title supplied ({})
\newcommand\subsectionwd{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-1sp}%
                                     {\normalfont\large\bfseries}{}}
\newcommand\subsubsectionwd{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-1sp}%
                                     {\normalfont\normalsize\bfseries}{}}



\def\@seccntformat#1{\makebox[0pt][r]{\csname the#1\endcsname\quad}}
\makeatother

\begin{document}

\tableofcontents 
\newpage

\section{Section 1}
Section 1 Text with title
\section{Section 2}
\subsectionwd
Sub Section 2-1 Text without title
\subsectionwd
Sub Section  2-2 Text without title
\section{Section 3}
\subsection{Sub Section 3-1}
Sub Section 3-1 text with title
\subsection{Sub Section 3-2}
Sub Section 3-2 text with title
\subsubsectionwd
Sub Sub Section 3-2-1 without title
\subsubsectionwd
Sub Sub Section 3-2-2 without title
\subsection{Sub Section 3-3}
Sub Section 3-3 text with title
\subsubsection{Sub Sub Section 3-3-1}
Sub Sub Section 3-3-1 text with title
\paragraph{} Lorem ipsum dolor sit amet, sed ea nihil clita adolescens, sea tation libris ad, sed an omittam comprehensam.
\subparagraph{}Id summo invenire his. Paulo posidonium honestatis ei cum, per cu aliquid salutatus consequuntur. 

\end{document}

The output i now get has untitled sections appearing in the TOC, which is not wanted. The output of the TOC is given below enter image description here

How to remove these from TOC while retaining the numbering in the body text?

2

Your image showed centred numbers (I think) which you could do by changing the \makebox usage but right aligned seems more natural.

This doesn't use any package just makes small adjustments to the definitions copied from article.cls

enter image description here

\documentclass{article}

\setcounter{secnumdepth}{5}

\renewcommand\thesection{\arabic{section}}

\makeatletter


\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                    {3.25ex \@plus1ex \@minus.2ex}%
                                    {-1sp}%
                                    {\normalfont\normalsize\bfseries}}
\renewcommand\subparagraph{\@startsection{subparagraph}{5}{\z@}%
                                       {3.25ex \@plus1ex \@minus .2ex}%
                                       {-1sp}%
                                      {\normalfont\normalsize\bfseries}}

% like section and subsection but inline not display (-sp) and with empty title supplied ({})
\newcommand\subsectionwd{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-1sp}%
                                     {\normalfont\large\bfseries}{}}
\newcommand\subsubsectionwd{\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {-1sp}%
                                     {\normalfont\normalsize\bfseries}{}}




\def\@seccntformat#1{\makebox[0pt][r]{\csname the#1\endcsname\quad}}
\makeatother

\begin{document}
\section{Section One}
Section One Text
\subsection{Sub Section One One}
Sub Section One One Text
\subsectionwd
Sub Section One One Text without title

\subsubsection{Sub Sub Section One One One}
Sub Sub Section One One OneText
\subsubsectionwd
Sub Sub Section One One OneText without title

\paragraph{} Lorem ipsum dolor sit amet, sed ea nihil clita adolescens, sea tation libris ad, sed an omittam comprehensam.
\subparagraph{}Id summo invenire his. Paulo posidonium honestatis ei cum, per cu aliquid salutatus consequuntur. 

\end{document}
  • this was helpful. Originally I wanted all numbers to be leftaligned, but feel it is better the way you suggest. The problem I have in this solution is that untitled subsections (command \subsectionwd ) and untitled subsections (command \subsubsectionwd) appear in the TOC. Is there a way to suppress this as a default for these two items? – Sandeep Raheja Sep 6 '17 at 7:38
  • you could reset \addtocontents to discard its 3 arguments and set it back at the end in the definition of the unnumbered versions but then the table of contents would look really really strange. For example your Sub Sub Section One One One is (despite its name) subsection 1.2.1 a subsubsection of subsection 1.2 and if that appears in the table of contents but you have not put section 1.2 in the table of contents as it has no title the toc will not be understandable. @S.Raheja – David Carlisle Sep 6 '17 at 8:12
  • i found it difficult to remove the unwanted TOC as your answer was too cryptic for a person at my skill level. However, I have now modified the dummy text in my original post to make the TOC readable after the elimination of untitled subsection and subsubsections. Please help I am really stuck – Sandeep Raheja Sep 6 '17 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.