22

I'm writing a document optimized for mobile usage, and as such I want to conserve my space. The spacing that titlesec adds to sections, subsections, etc. is getting somewhat annoying. Is there a (simple) method to remove this? My desire is to just change the look of the title while retaining all LaTeX default spacing, etc.

The sectsty package doesn't add any spacing and works great, but I'd like to make use of some of titlesec's features.

I've looked at the following questions and they don't seem to fix my problem:

Please close this if I've overlooked something in the solutions above.

MWE result

\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{margin=5mm, paper=a6paper, showframe=true}
\usepackage{titlesec}
\titleformat*\section{\Large}
\titleformat*\subsection{\large}
\usepackage{lipsum}
\begin{document}
\section*{Using titlesec}
\subsection*{Lorem Ipsum}
\lipsum[3]
\end{document}

Note: Remove the three titlesec lines to obtain the LaTeX default result.

1
  • 5
    This is a great question. Sadly enough, titlesec's formatting is not immediately setup for this kind of thing. Instead, and often very typically, you have to specify all of the options in order to change just one thing, without even knowing the defaults of the other. That's the advantage of providing a key-value driven input rather than a full argument-based macro (as titlesec does). What's needed here is something like titleseckv (doesn't exist) that does everything titlesec does, but allows for a `key-value interface with LaTeX defaults otherwise.
    – Werner
    Oct 26, 2012 at 23:16

1 Answer 1

14

UPDATED ANSWER

Do \usepackage[nostruts]{titlesec}, which will remove the struts like my answer below did.

The feature was added with version 2.11, released 2019-07-16.

ORIGINAL ANSWER

The package titlesec adds \strut in some places. In your case you have to defeat this behavior in three places:

\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{margin=5mm, paper=a6paper, showframe=true}

\usepackage{titlesec}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ttl@select}{\strut}{}{}{}
\patchcmd{\ttlh@hang}{\strut}{}{}{}
\patchcmd{\ttlh@hang}{\strut}{}{}{}
\makeatother

\titleformat*\section{\Large}
\titleformat*\subsection{\large}

\usepackage{lipsum}
\begin{document}

\section*{Using titlesec}
\subsection*{Lorem Ipsum}
\lipsum[3]
\end{document}

The macros involved are \ttl@select and \ttlh@hang (in the second one \strut appears twice. If other styles are selected it may be necessary to patch \ttlh@display or \ttlh@runin.

2
  • I believe you can add the option \usepackage[nostruts]{titlesec} to get rid of the struts altogether. Apr 14, 2021 at 20:15
  • @ChristopherCreveling The nostruts option got added in 2019. Thanks for the pointer.
    – egreg
    Apr 14, 2021 at 20:21

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.