2

LaTeX by default indents section titles so that the left edge of the text is in alignment, as follows:Text is indented and aligned on left-hand side

I would like to make it wrap all the way to the left margin, as shown:

Text is wrapped to margin

How could I do that? I thought of the titlesec package, but it does not seem to provide a way to do it. (Yes, I know this formatting is ugly, but I would like to know how to do it.)

Minimum working example that I have so far:

\documentclass{article}

\begin{document}

\section{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}

Lorem ipsum dolor sit amet.

\end{document}

3 Answers 3

3

titleformat from titlesec is usually the way to format sections (link to documentation). In your case, change the default shape from [hang] to [block]. Extra spacing can be adjusted by \titlespacing* define in the same document. There are also some example definitions of the default and more fancy formats, so you may want to have a look at those, as well.

\documentclass{article}
\usepackage{titlesec}

\titleformat{\section}[block]
  {\normalfont\Large\bfseries}{\thesection}{1em}{}


\begin{document}
\section{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}

Lorem ipsum dolor sit amet.
\end{document}

enter image description here

3

The KOMA-Script classes provide their own interface to configure headings. To not use hanging headings, just remove the \@hangfrom from the default definition of \sectionlinesformat (shown in the user manual):

\documentclass[emulatestandardclasses]{scrartcl}

\renewcommand*{\sectionlinesformat}[4]{\hskip#2#3#4}

\begin{document}

\section{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}

Lorem ipsum dolor sit amet.

\end{document}

enter image description here

In the example I've also used option emulatestandardclasses to make the KOMA-Script classes more lookalike to the standard classes.

If you want to distinguish the different levels, you can use the first argument: If you also want justifying (and hyphenation) of the headings, you can redefine \raggedsection:

\documentclass[emulatestandardclasses]{scrartcl}

\makeatletter
\renewcommand*{\sectionlinesformat}[4]{%
  \Ifstr{#1}{section}{\hskip#2#3#4}{\@hangfrom{\hskip#2#3}#4}%
}
\makeatother
\renewcommand\raggedsection{\noindent}

\begin{document}

\section{Lorem ipsum dolor sit amet, consectetur adipiscing elit esse est.}

\subsection{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
Lorem ipsum dolor sit amet.

\end{document}

enter image description here

For the levels \part and \chapter there are different commands \partlineswithprefixformat, \chapterlinesformat, and \chapterlineswithprefixformat. See the user manual for more information.

2

To do the same thing in the memoir class, use the \sethangfrom{} command, as follows:

\documentclass{memoir}

\setsecnumdepth{subsection}
\sethangfrom{\noindent #1}

\begin{document}

\chapter{Lorem ipsum dolor sit amet}
\section{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
Lorem ipsum dolor sit amet.
\subsection{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
Lorem ipsum dolor sit amet.

\end{document}

Note that this macro will affect all the lower-level sectioning commands at once.

Output: All sectioning headings are block text.

If you want to change just one section level (say, subsections but not sections), use the \setNhook{} macro, where N refers to the short name of the sectioning command. Here is a list of commands to use:

Section type Short name Command
section sec \setsechook{\sethangfrom{\noindent ##1}}
subsection subsec \setsubsechook{\sethangfrom{\noindent ##1}}
subsubsection subsubsec \setsubsubsechook{\sethangfrom{\noindent ##1}}
para paragraph \setparahook{\sethangfrom{\noindent ##1}}
subpara subparagraph \setsubparahook{\sethangfrom{\noindent ##1}}

Note that the argument must be preceded with two pound signs (##) instead of one.

The following code formats subsections as block text, but creates the default hanging indent for sections:

\documentclass{memoir}

\setsecnumdepth{subsection}
\setsubsechook{\sethangfrom{\noindent ##1}}

\begin{document}

\chapter{Lorem ipsum dolor sit amet}
\section{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
Lorem ipsum dolor sit amet.
\subsection{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
Lorem ipsum dolor sit amet.

\end{document}

Output: Only subsections are block text.

You must log in to answer this question.

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