# Titlesec's titleformat with ulem

I have a very large document that can be reduced to the below example to provide custom formatting for subsection headers.

\documentclass[]{article}

\usepackage{ulem}
\usepackage[explicit]{titlesec}  %title control and formatting

\title{Test Paper}
\author{John Dover}

\titleformat{\subsection}{\normalfont}{\uline{\thesubsection}}{0em}{\uline{\hspace{1em}#1}}

\begin{document}

\maketitle

\section{Test}

\subsection{Ooopsie doopsie}

\end{document}



this worked previously but now when I compile I get the ominous error

Extra }, or forgotten \endgroup. \subsection{Ooopsie doopsie}


This can be solved by removing uline from the \titleformat command and replacing this with underline as in

\titleformat{\subsection}{\normalfont}{\underline{\thesubsection}}{0em}{\underline{\hspace{1em}#1}}


but the underlines are uneven. Using the ulem package command \ul gives the original error.

I am using Miktex / TexStudio and recently had to update things. Subsequently, I found these errors and I am not sure why. Is there a recent change or was this never supposed to work?

• Why not using \quad? Jan 13 '21 at 10:20

The \hspace command has been changed. It now supports calc-syntax (if the package calc is used you can do e.g. additions), but this make it fragile for ulem.

You can put the \hspace in a box to protect if from \uline:

\documentclass[]{article}

\usepackage{ulem}
\usepackage[explicit]{titlesec}  %title control and formatting

\title{Test Paper}
\author{John Dover}

\titleformat{\subsection}{\normalfont}{\uline{\thesubsection}}{0em}{\uline{\mbox{\hspace{1em}}#1}}

\begin{document}

\maketitle

\section{Test}

\subsection{Ooopsie doopsie}

\end{document}