1

So I wanted to customise my chapter style and remove the space before it. I've already used \titlespacing from titlesec package, but there still is space before the title.

mycls.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mycls}[2015/11/18 My class]

\LoadClass{book}

\RequirePackage[showframe]{geometry}

\RequirePackage{titlesec}

\titleformat{\chapter}[display]
  {\center}
  {\thechapter}
  {0.1875in}
  {}
\titlespacing*{\chapter}
  {0in}
  {0in}
  {0.4375in}

example.tex:

\documentclass{mycls}

\usepackage{lipsum}

\title{Tex StackExchange Example}
\author{Pedro}

\begin{document}

\maketitle

\chapter{Chapter}

\lipsum[1]

\lipsum[2]

\end{document}

Generated document with space between the top of the frame and the chapter number:

Generated document.

Any hint on what I'm not doing right/what I should be doing?

pluton
  • 16,421
  • @PaulGaborit I already tried the suggestions on that answer, and they actually reduce the size of the spacing, but they still leave some space left. I wanted to peg the 1 right below the top frame line. – pedrosanta Nov 19 '15 at 15:16

1 Answers1

3

\center is the command underlying the center environment and it adds vertical space. You intended I think \centering

\documentclass{book}

\RequirePackage[showframe]{geometry}

\RequirePackage{titlesec}

\titleformat{\chapter}[display]
  {\centering}
  {\thechapter}
  {0.1875in}
  {}
\titlespacing*{\chapter}
  {0in}
  {0in}
  {0.4375in}


\usepackage{lipsum}

\title{Tex StackExchange Example}
\author{Pedro}

\begin{document}

\maketitle

\chapter{Chapter}

\lipsum[1]

\lipsum[2]

\end{document}

raises the title from the position in the question.

The remaining space is \topskip and the \baselineskip for the line with the chapter number.

....\glue(\topskip) 10.0
....\rule(0.0+0.0)x*
....\penalty 10000
....\glue 0.0
....\glue 0.0
....\glue(\parskip) 0.0 plus 1.0
....\glue(\baselineskip) 3.60004
....\hbox(8.39996+3.60004)x430.00462, glue set 212.5023fil
.....\glue(\leftskip) 0.0 plus 1.0fil
.....\rule(8.39996+3.60004)x0.0
.....\OT1/cmr/m/n/10 1

essentially it's the rule that is stopping the space being discarded at top of page, normally you would not get the full topskip, it would be reduced by the height of the first line, but here the first line is a zero height rule.

David Carlisle
  • 757,742