4

I want to have a hanging indent on every paragraph, but not on the section headers. I can achieve this with titlesec and \leftskip, but this solution feels dirty/hackish, and I'm sure there must be a better way.

MWE:

\documentclass[12pt]{article}
\usepackage{parskip}
\usepackage{titlesec}
\titleformat{\section}[runin]{\bfseries\normalsize}{}{0pt}{\hspace*{-2em}\thesection }[\\]
\titleformat{\subsection}[runin]{\normalsize}{}{0pt}{}[:\\]
\leftskip=2em

\begin{document}
\section{Section Headings Not Indented}
Every line of this section should be indented the exact same amount. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean adipiscing lacus ut nibh laoreet malesuada. Nulla vehicula mauris eu imperdiet varius. Etiam pellentesque eros a urna pulvinar, nec condimentum lectus gravida. Suspendisse vehicula, mauris id fermentum iaculis, massa neque convallis neque, in vestibulum quam felis in enim.

Sed dapibus, nisl vitae consectetur sodales, augue sem laoreet urna, ut eleifend velit augue vel leo. Nulla facilisi. Suspendisse potenti. Phasellus scelerisque porta risus ut luctus. Ut lobortis magna purus, at rhoncus quam interdum quis. Sed vestibulum, leo non rhoncus sollicitudin, erat enim dignissim dolor, quis commodo nunc elit at arcu.

\subsection{also indented same as a paragraph}
Phasellus vitae ultricies augue. Vivamus non ipsum odio. Etiam id lectus non sapien hendrerit consectetur. Suspendisse porta magna at metus dignissim pharetra. Nulla bibendum mauris sit amet feugiat interdum. Nulla porta sollicitudin lorem eget pharetra. Etiam dictum, dolor vitae vulputate ultricies, quam nibh consectetur leo, nec ultricies felis tortor eget leo. In pulvinar felis nec diam fringilla rhoncus a at lacus. 

\end{document}

I came across the hanging package and the hangparas environment, but that does not seem to work across multiple sections. I also considered simply adding a \hangindent and \hangafter=0 to every paragraph, but that would be tedious and I would prefer a more global solution.

If possible, I would also like to be able to undo these settings for a given section(s) (My appendices, specifically. Currently, I do this by preceding them with \leftskip=0). However, if that is impossible (or requires substantial additional effort), it's not a deal-breaker.

1
  • 1
    Using \leftskip is not compatible with list environments; you want to have a negative indentation of the section titles, rather than a positive indentation of the text.
    – egreg
    Nov 27, 2013 at 9:12

1 Answer 1

1

Here is a solution (you can set the value "3em" to what you want) :

\makeatletter
 \newenvironment{exemple}
 {\list{}{%
     \leftmargin 3em}
   \item\relax}
     {\endlist}
\makeatother

MWE :

documentclass[12pt]{article}

\makeatletter
 \newenvironment{exemple}
 {\list{}{%
     \leftmargin 3em}
   \item\relax}
     {\endlist}
\makeatother

\begin{document}
\section{Section Headings Not Indented}
\begin{exemple}
  Every line of this section should be indented the exact same
  amount. Lorem ipsum dolor sit amet, consectetur adipiscing
  elit. Aenean adipiscing lacus ut nibh laoreet malesuada. Nulla
  vehicula mauris eu imperdiet varius. Etiam pellentesque eros a urna
  pulvinar, nec condimentum lectus gravida. Suspendisse vehicula,
  mauris id fermentum iaculis, massa neque convallis neque, in
  vestibulum quam felis in enim.

  Sed dapibus, nisl vitae consectetur sodales, augue sem laoreet urna,
  ut eleifend velit augue vel leo. Nulla facilisi. Suspendisse
  potenti. Phasellus scelerisque porta risus ut luctus. Ut lobortis
  magna purus, at rhoncus quam interdum quis. Sed vestibulum, leo non
  rhoncus sollicitudin, erat enim dignissim dolor, quis commodo nunc
  elit at arcu.
\end{exemple}


\subsection{also indented same as a paragraph}
Phasellus vitae ultricies augue. Vivamus non ipsum odio. Etiam id lectus non sapien hendrerit consectetur. Suspendisse porta magna at metus dignissim pharetra. Nulla bibendum mauris sit amet feugiat interdum. Nulla porta sollicitudin lorem eget pharetra. Etiam dictum, dolor vitae vulputate ultricies, quam nibh consectetur leo, nec ultricies felis tortor eget leo. In pulvinar felis nec diam fringilla rhoncus a at lacus. 

\end{document}

enter image description here

If you don't want to create a environment inside each title, there should be a way to redefine the paragraphs in LaTeX (I don't know how to achieve that) but you say you want to have no-indent paragraphs and it will be more difficult this way.

2
  • Creating an environment inside each title is no more helpful than using \hangindent and \hangafter inside each title. Nov 27, 2013 at 9:41
  • @SnoringFrog Not exactly because (at least) my solution is a "proper" and clean way of doing what you want. After, if you don't want to have to create a environment after each title, there is probably a mean to automatically do it. I have just no idea how but, very likely, someone will.
    – ppr
    Nov 27, 2013 at 9:59

You must log in to answer this question.

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