10

I’m writing a document that uses a rather small text block (\textwidth), with the margin holding footnotes, figures and various other material. Because of the narrow text block, section headings frequently span two lines. However, they can often physically fit on one line – if they are allowed to extend into the marginal area.

So, how do I get the headings to extend into the margins (while still being broken if they extend too much, i.e., more than \marginparsep + \marginparwidth)? I’m using the Memoir class.

Here’s a simple example:

\documentclass[11pt,oneside,article]{memoir}

\setlrmarginsandblock{3cm}{9cm}{*}
\setmarginnotes{1.5em}{5.5cm}{\onelineskip}
\checkandfixthelayout[nearest]

\usepackage{lipsum}

\begin{document}

\chapter{Chapter heading}

\section{This heading is too long to fit on one line}

Foo. \marginpar{\lipsum[4]}\lipsum[1-3]

\end{document}
  • Are you working one-sided or two-sided? If two-sided, what do you want to do on even pages? – Brent.Longborough Oct 26 '11 at 18:48
  • @Brent.Longborough: The document is one-sided, as per my example code. (Well, in my real document I use twoside + some magic to make it mostly act like a one-sided document, but that’s not important here.) – Karl Ove Hufthammer Oct 26 '11 at 18:59
  • Fastest solution might be to use xparse to redefine \section and friends (xparse makes it easy to still have the extra arguments), and then use this to combine it with \makebox construction Gonzalo use in the titlesec solution. (untested) – daleif Oct 26 '11 at 19:14

2 Answers2

12

This is the memoir way:

\newcommand{\extendedsec}[1]{\noindent
  \makebox[0pt][l]{\parbox[t]{\textwidth}{\Large\bfseries\raggedright#1}}}
\setsecheadstyle{\extendedsec}

Change \textwidth into what suits you best. I wouldn't fill the whole line.

If you want to fill the whole line, then

\newcommand{\extendedsec}[1]{\noindent
  \makebox[0pt][l]{\parbox[t]%
    {\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}%
    {\Large\bfseries\raggedright#1}}}

A similar trick is described on page 106 of the manual for memoir

egreg
  • 1,121,712
6

You can use the titlesec package; in the following example I used a \parbox of width \textwidth+\marginparwidth+\marginparsep to format the heading for sections:

\documentclass[11pt,oneside,article]{memoir}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\setlrmarginsandblock{3cm}{9cm}{*}
\setmarginnotes{1.5em}{5.5cm}{\onelineskip}
\checkandfixthelayout[nearest]

\titleformat{\section}
  {\normalfont\Large\bfseries}{}{0pt}
  {\makebox[\dimexpr\linewidth][l]{%
      \parbox{\dimexpr\textwidth+\marginparwidth+\marginparsep\relax}
{\raggedright\thesection\hspace{1em}#1}}}


\begin{document}

\chapter{Chapter heading}

\section{This heading fits now on one single line}

Foo. \marginpar{\lipsum[4]}\lipsum[1]

\section{This heading is too long to fit on one line and will span two lines}

Foo. \marginpar{\lipsum[4]}\lipsum[1]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128