Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
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 '13 at 9:12
add comment

1 Answer 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.

share|improve this answer
    
Creating an environment inside each title is no more helpful than using \hangindent and \hangafter inside each title. –  SnoringFrog Nov 27 '13 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 '13 at 9:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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