0

I am using book class and have made the section numbers appear in the right margin with the titlesec package. Whenever there's a \noindent command, the marginal section number seems to shift to the left. This causes the section numbers look uneven. The MWE is as follows:

\documentclass[draft]{book}
\usepackage{lipsum}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{titlesec}
\titleformat{\section}[rightmargin] 
{} 
{\it\thesection}
{0em}
{}

\titlespacing{\section}
{1em}{1em}{0em}
\begin{document}
\chapter{chapter-name}

\section{}
\lipsum[1][1]\par
\section{}
\noindent\lipsum[1][2]\par
\section{}
\lipsum[1][3]\par
\section{}
\lipsum[1][4-6]\par
\section{}
\lipsum[2-4][12-18]

\end{document}

The resulting output is as follows:

https://i.sstatic.net/bPL3X.png

Note that the 5th section number overlaps with the section content.

How can I make the section numbers appear in a uniform way in the right margin irrespective of the text contained in the respective section?

Regards.

6
  • It's unclear why you'd want \noindent.
    – egreg
    Commented Mar 10, 2022 at 22:22
  • @egreg : My use case is such that I am using \section just to use it as a counter. And the text that is contained in each section shouldn't be indented.
    – vrgovinda
    Commented Mar 11, 2022 at 0:32
  • 1
    Then you're using the wrong tool. However, I'm still asking why some paragraph should be indented and some not.
    – egreg
    Commented Mar 11, 2022 at 8:25
  • Actually the use case is that I am formatting Sanskrit verses and their Roman transliteration. So all the lines should be aligned properly. 1. The verse package by default doesn't satisfy my requirements. 2. And yes, I maybe misusing the \section command, but right now I have to get the work done and cannot spare time to explore other ways, such as using a new counter OR tinkering with verse package etc.. 3. But I want to learn LaTeX in depth in the near future. You are most welcome to share your thoughts/suggestions w.r.t the three points.
    – vrgovinda
    Commented Mar 11, 2022 at 9:58
  • 1
    Instead of \noindent you could use \hspace*{-\parindent}\lipsum[1][3]. This will nullify the indent too but not move the number. Commented Mar 11, 2022 at 13:50

2 Answers 2

1

With indent at each new paragraph, new code:

\documentclass[draft]{book}
\usepackage{lipsum}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{titlesec}
\titleformat{\section}[rightmargin] 
{} 
{\it\thesection}
{0em}
{}

\titlespacing{\section}
{1em}{1em}{1em} % <--- changed
\begin{document}
    \chapter{chapter-name}
    % indent for each new paragrapf/section
    \section{}
    \lipsum[1][1]\par
    \section{}
    \lipsum[1][2]\par
    \section{}
    \lipsum[1][3]\par
    \section{}
    \lipsum[1][4-6]\par
    \section{}
    \lipsum[2-4][12-18]
\end{document}

Output:

enter image description here

EDIT: If you dont want indent for all new paragraph, write this line in the preamble:

\parindent=0mm

The new output in this case is:

enter image description here

2
  • \parindent=0pt affects the whole document. Is there any way to apply it locally only to the particular section? I tried the followings: \noindent in \titleformat{\section}[leftmargin]{}{\noindent\itshape\thesection}{0pt}{}[\noindent] or in \titlespacing{\section}{2em}{1em}{0em}[\noindent] but it doesn't seem to have any effect.
    – Celdor
    Commented Mar 11, 2022 at 10:37
  • apply it locally only to the particular section sorry the wording is not clear here. I meant locally in the section definition, so it would be applied in every \section{}
    – Celdor
    Commented Mar 11, 2022 at 10:49
0

With indent at each new paragraph, new code:

\documentclass[draft]{book}
\usepackage{lipsum}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{titlesec}
\titleformat{\section}[rightmargin] 
{} 
{\it\thesection}
{0em}
{}

\titlespacing{\section}
{1em}{1em}{1em} % <--- changed
\begin{document}
    \chapter{chapter-name}
    % indent for each new paragrapf/section
    \section{}
    \lipsum[1][1]\par
    \section{}
    \lipsum[1][2]\par
    \section{}
    \lipsum[1][3]\par
    \section{}
    \lipsum[1][4-6]\par
    \section{}
    \lipsum[2-4][12-18]
\end{document}

Output:

enter image description here

EDIT: If you dont want paragraph indent everywhere, add in your preamble the line \parindent=0mm. In this case the output is:

enter image description here

1
  • I think you have answered this question twice.
    – vrgovinda
    Commented Mar 12, 2022 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .