## LaTeX forum ⇒ Page Layout ⇒ Titlesec, part and superfluous space Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
LaTeX_Minimix
Posts: 3
Joined: Wed Nov 02, 2016 5:56 pm

### Titlesec, part and superfluous space

For a custom document type (based on article if this is relevant) I'm trying to redefine the way LaTeX typesets a \part. I want it to look more or less like a section with a larger font. For this I use titlesec. It works fine, except that LaTeX will insert additional space if the part start at the top of a new page. Why is that and how can I avoid it?

MWE:
\documentclass{article}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage{lipsum} \usepackage{titlesec}\titleformat{\part}[hang]{\scshape\Large}{Part~\Alph{part}}{2ex}{}{}\titlespacing{\part}{0pt}{0pt}{*3}\titleformat{\section}[hang]{\bfseries\large}{Section~\arabic{section}}{2ex}{}{}\titlespacing{\section}{0pt}{*2}{0pt} \usepackage{fancyhdr}\pagestyle{fancy}  \begin{document} \part{At the start of a page \ldots{} space above}\lipsum[1]  \pagebreak\lipsum[1] \part{In the middle of a page looks ok}\lipsum[1] \pagebreak{}\section{At the start of a page looks ok}\lipsum[1] \end{document}

Even though I use fancyhdr in my real document as well, it's actually not needed to reproduce the unwanted behavior. It's just convenient to have the header separator because it makes the enlarged space more easily visible.

Johannes_B
Site Moderator
Posts: 4160
Joined: Thu Nov 01, 2012 4:08 pm
For this use case, i wouldn't use package titlesec, i would patch the original command.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

LaTeX_Minimix
Posts: 3
Joined: Wed Nov 02, 2016 5:56 pm
Johannes_B wrote:For this use case, i wouldn't use package titlesec, i would patch the original command.

Thanks a lot for this workaround and also for introducing me to showframe. But isn't this kind of customization exactly what titlesec is meant for? I would really like to understand what's going wrong there.

Johannes_B
Site Moderator
Posts: 4160
Joined: Thu Nov 01, 2012 4:08 pm
There are packages that do stuff, some do it well, some don't. titlesec is certainly one of the packages that do what they do well. Personally, i don't like the package that much, as the documentation is pretty confusing for me.
The package titlesec can do what you want, but you don't have to use it. You can define the layout by yourself or patch the original code, if you want to change small things.

What does titlesec do to introduce that space? No idea at all, and i don't care to check out honestly. The more a package can do, the more complex it is. Compare it to a swiss army knife, you can do a lot of stuff, but sometimes you just need a plain screw driver. I decided to use the screwdriver instead of examining the multi-tool.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Stefan Kottwitz
Posts: 9567
Joined: Mon Mar 10, 2008 9:44 pm
Interesting! You made a very good minimal example that shows the problem. Thanks for that! I tested it and tried things, but could not get rid of that space too. I was only working with the titlesec manual, not yet with the source code. Looks like a bug to me. When I got time, I could take a look at the titlesec source code, just these days I'm very busy.

You are right, using packages is recommendable, I think patching should be used as a last resort. But Johannes is right too, sometimes it's good to patch to simply get things done. But that's not the official future-proof recommendation.

Stefan

LaTeX_Minimix
Posts: 3
Joined: Wed Nov 02, 2016 5:56 pm
Johannes, Stefan, thank you both for your replies and explanations. I don't want to waste your time by going through the package code. If the behavior I see is a bug, that's enough of an explanation for me. I just thought that it's a known/expected thing and these I'd like to understand better. I'm definitely not up to understand complex LaTeX package code yet.

damitr
Posts: 1
Joined: Wed May 06, 2020 10:31 pm
How to color all the entries in the \part{}. I have tried this with your code above


but this doesn't colour the \thepart ""Part" only the number and the part title.

Ijon Tichy
Posts: 266
Joined: Mon Dec 24, 2018 10:12 am
Untested and speculative because of missing minimal working example:
\patchcmd{\@part}{\normalfont}{\normalfont\color{red}}{}{}\patchcmd{\@spart}{\normalfont}{\normalfont\color{red}}{}{}