1

I want to make section headings in an article-class document both multiline and having lables on thier margins.

I'm using two boxes: one for a label and another one for text to force it to split.

\documentclass[a4paper,11pt]{article}
\usepackage[explicit]{titlesec}
\titleformat{\section}
            {\fontsize{28}{24}\headingfont}%format
            {\makebox[0pt][r]{%
                \headingfontlight\thesection\hskip 9pt}}%
            {0pt}
            {\makebox[\dimexpr\linewidth][l]{%
                  \parbox{\dimexpr\textwidth+\marginparwidth+\marginparsep\relax}
            {\raggedright #1}}}

This code works well but has one loose end: a section label is placed in the center of a heading box instead of its top.

enter image description here

Would appreciate any ideas.

3

Use \parbox[t]. Don't use the explicit option to titlesec, you'll regret it, one day: it's much cleaner to define a separate macro than clobbering the last argument of \titleformat.

\documentclass[a4paper,11pt]{article}
\usepackage{titlesec}

\titleformat{\section}
  {\fontsize{28}{24}\headingfont}%format
  {\makebox[0pt][r]{\headingfontlight\thesection\hskip 9pt}}%
  {0pt}
  {\printsectiontitle}

\newcommand{\printsectiontitle}[1]{%
  \makebox[\dimexpr\linewidth][l]{%
    \parbox[t]{\dimexpr\textwidth+\marginparwidth+\marginparsep\relax}
      {\raggedright #1}%
  }%
}

\let\headingfont\selectfont % just for the example
\let\headingfontlight\relax

\begin{document}

\section{Some long long long long long long long long long long long long heading}

\end{document}

enter image description here

What's the purpose of setting the title at 28pt with a baseline skip of 24pt? Just to get too near lines and uneven spacing?

|improve this answer|||||
  • Thanks! «Just to get too near lines and uneven spacing?» — In my view, a heading with huge font and default spacing looks too wide and difficult to read. For instance, this heading has 28pt font size and 28pt spacing, and this one has 28pt font size and 24pt spacing. In my eyes, the second one is more readable. – kvaleev Nov 10 '15 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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