[Tex/LaTex] Section title with subtitle

formattingmemoirsectioningtitlesec

I'm using the memoir class, I would like to create a more fancy section title, but I don't have the necessary skills in LaTeX. I found many fancy section titles on this forum, but I don't know how to customize it to make it look the way I want it. Is it possible to modify the section title to look like this (I drew this myself in OmniGraffle):

enter image description here

However, with these options:

  • Date and subtitle are optional, not all sections have them
  • Date is not necessarily today, but some day in the past
  • No section number is shown
  • both section title and subtitle can be longer than single line

Any help greatly appreciated!

Best Answer

Here's one possibility, using the titlesec package; before each \section, some commands can be used: \undefds suppresses previous dates and subtitles; \sectiondate{<text>} assigns <text> as the date for the following \section, and \sectionsubtitle{<text>} assigns <text> as the subtitle for the following \section.

Since titlesec was used, somre restrictions apply (See About memoir and titlesec incompatibility). The code:

\documentclass[article]{memoir}
\usepackage[margin=3cm]{geometry}% just for the example
\usepackage[T1]{fontenc}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{textcase}
\usepackage{lmodern}
\usepackage{lipsum}

\makeatletter
\newcommand*\nameundef[1]{%
  \expandafter\let\csname #1\endcsname\@undefined}
\newcommand\sectiondatefont{\normalfont\sffamily\itshape\bfseries\Large}
\newcommand\sectionsubtitlefont{\normalfont\sffamily\LARGE}
\newcommand\sectiondate[1]{\def\@sectiondate{#1}}
\newcommand\sectionsubtitle[1]{\def\@sectionsubtitle{#1}}
\titleformat{\section}
  {\normalfont\bfseries\huge\sffamily}{}{0em}
  {\colorbox{gray}{%
    \parbox[t]{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}{%
      \vspace*{1ex}%
      \@ifundefined{@sectiondate}
        {}{{\sectiondatefont\@sectiondate}\\*}%
      \raggedright%
      \textcolor{white}{\huge\MakeTextUppercase{#1}}%
      \@ifundefined{@sectionsubtitle}
        {}{\\*{\sectionsubtitlefont\@sectionsubtitle}}%
      \vspace*{1ex}
      }%
    }%
  }
\newcommand\undefds{%
  \nameundef{@sectiondate}\nameundef{@sectionsubtitle}}
\makeatother

\begin{document}

\sectiondate{March 15, 2013}
\sectionsubtitle{Test Subtitle}
\section{Test Section With a Title Spanning Two Lines}
\lipsum[4]

\undefds
\section{Test Section}
\lipsum[4]

\undefds
\sectiondate{April 23, 2009}
\section{Another Test Section}
\lipsum[4]

\undefds
\sectionsubtitle{Another Test Subtitle}
\section{Test Section}
\lipsum[4]

\end{document}

An image of the result:

enter image description here

Related Question