I am new to Latex. I need a document structure like this with the numbering in margin.
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
How to remove these from TOC while retaining the numbering in the body text?