# Can I add a custom subtitle to subsection?

I am using titlesec to create custom subsections. I have my declaration:

\titleformat{\subsection}[hang]
{\large\bfseries}
{$\square$\medspace}{0mm}{}


However I frequently want to add a subtitle right below the section title. Which always uses the same formatting

\subsection{The Coastline Theorem}
\vspace{-6px}
\textit{Discussion and proof of the coastline theorem.}
\vspace{4px}\hfill\break


This is somewhat bothersome to write each time and if I want to refactor it it's a pain. It would be super nice if I could pass an additional parameter to \subsection and define the formatting in the \titleformat. Then this might look like:

\subsection{The Coastline Theorem}{Discussion and proof of the coastline theorem.}


I read the docs for titlesec and I didn't see anything like this, but the docs are hard for me to read. Is there some way to do this with titlesec? Is there some way I should be doing this outside of titlesec?

• you could easily define your own two argument command that expanded to that but the definition you have will lose most of latex's control over section headings so it will allow a page break before the text and if you leave a paragraph break before the text the \break will generate underful hbox and a spurious blank line, Jul 3 at 13:32
• This is going to take longer than I first thought. I have to replace \@startsection (as opposed to just \@makechapterhead). Jul 3 at 14:27

titlesec provodes an optional argument to \titleformat for code to go after the heading without allowing a page break between the heading and subheading or after the subheading. You just need to arrange to get a document supplied text in to that place.

\documentclass{article}
\usepackage{amssymb}
\usepackage{titlesec}

\showoutput
\titleformat{\subsection}[hang]
{\large\bfseries}
{$\square$\medspace}{0mm}{}[\mdseries\itshape \subsecsubhead]

\NewDocumentCommand\subsectionB{O{#2}mm}{%
\subsection[#1]{#2}%
}

\begin{document}
\section{Zzzz}

\subsectionB{The Coastline Theorem}{Discussion and proof of the coastline theorem.}

some text

\end{document}


This version does not use titlesec. Actually, I stole most of it from \chapter in report class. I used the default vertical spacing for subsections. Note that \subsection* uses a different macro than \subsection.

\documentclass{article}
\usepackage{amssymb}
\usepackage{showframe}

\makeatletter
\renewcommand\subsection{\secdef\@subsection\s@subsection}
\def\@subsection[#1]#2#3{\ifnum \c@secnumdepth >1
\refstepcounter{subsection}%
{\protect\numberline{\thesubsection}#1}%
\else
\fi
\vspace*{3.25ex\@plus 1ex \@minus .2ex}%
{\parindent=0pt
\interlinepenalty\@M
\normalfont\large\bfseries
\ifnum \c@secnumdepth >1
\@hangfrom{$\square$\medspace}
\fi
#1\par\nobreak% insert \vskip before subtitle
\textit{#2}\par\nobreak
\vskip 1.5ex \@plus .2ex
}}
\vspace*{3.25ex\@plus 1ex \@minus .2ex}%
{\parindent=0pt
\interlinepenalty\@M
\normalfont\large\bfseries
#1\par\nobreak% insert \vskip before subtitle
\textit{#2}\par\nobreak
\vskip 1.5ex \@plus .2ex
}}
\makeatother

\begin{document}
\tableofcontents

\subsection{The Coastline Theorem}{Discussion and proof of the coastline theorem}