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}
3
  • Are you working one-sided or two-sided? If two-sided, what do you want to do on even pages? Commented Oct 26, 2011 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.) Commented Oct 26, 2011 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
    Commented Oct 26, 2011 at 19:14

2 Answers 2

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

3
  • Thanks. I don’t understand why it works (why can setsecheadstyle take a command that takes an argument?), but it does extend the heading into the margin (if one replaces \textwidth with something larger). However, it also seems to add some space to the left of the heading. Commented Oct 26, 2011 at 20:27
  • @KarlOveHufthammer Yes, I forgot a \noindent
    – egreg
    Commented Oct 26, 2011 at 20:35
  • @egreg OK. Now it’s perfect. :-) Commented Oct 27, 2011 at 14:10
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

4
  • @Karl: Note the use of the explicit package option to titlesec. It allows you to "grab hold of" the sectional title by means of the argument #1 do with it what you want, as in @Gonzalo's answer.
    – Werner
    Commented Oct 26, 2011 at 17:54
  • Thanks. Although this does seem to work, the titlesec documentation explicitly says that it’s not compatible with the ‘Memoir’ class, so I’m worried there may be some hidden issues with this solution. Commented Oct 26, 2011 at 18:38
  • do consider making the multi-line headings ragged right to avoid uneven spacing. Commented Oct 26, 2011 at 22:22
  • @barbara beeton: done. Commented Oct 26, 2011 at 22:25

You must log in to answer this question.

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