0

I have these commands for my chapter titles, how can I make it go to the top of page?

\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\usepackage{graphicx} 
\usepackage{titlesec}    
\titleformat{\chapter}{\normalfont\huge\bf}{\thechapter}{15pt}{\huge\bf}

It's way down the page: enter image description here

  • Welcome to TeX.se. Instead of posting fragments of code, it's more helpful to create a small self-contained document that shows what you're doing (like the one in my answer). It should begin with \documentclass{...} and end with \end{document}. This way people will be able to help you better. – Alan Munn Mar 18 '23 at 22:26

2 Answers2

2

Once you've set the format of \chapter using the titlesec \titleformat command you can set the spacing for the chapters using the \titlespacing* command. I've adjusted some of your code too. Two-letter font commands like \bf have been deprecated in LaTeX for decades, and you should not use them. Instead use \bfseries or \textbf{} as appropriate. Unless the format of the chapter number is different from the rest of the title, there's no need to add formatting to the last argument of the \titleformat command.

The \titlespacing* command takes four arguments:

\titlespacing*{<command>}{<left-margin>}{<space-before>}{<space-after>}

The book class sets these values to 0pt, 50pt and 40pt. To put the title at the top of the page, we can use a negative value for the space before argument. I've used -\baselineskip. If you want the title aligned flush with the top margin, you can use -1.5\baselineskip or use the code provided in the comment. If you want some space, but not the default 50pt then change this value to something that suits your needs.

\documentclass{book}
\usepackage[margin=2.5cm,showframe]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\Huge\bfseries}{\thechapter}{15pt}{}
\titlespacing*{\chapter}{0pt}{-\baselineskip}{20pt}
\begin{document}
\chapter{A chapter}
This is some text.
\end{document}

output of code

Alan Munn
  • 218,180
  • 1
    Because of a bug (https://github.com/jbezos/titlesec/issues/53) there is a little space remaining at the top. Here is a workaround: https://tex.stackexchange.com/questions/59389/package-titlesec-adds-extra-space-on-top-of-chapter-despite-commands-to-the-co/59392#59392. In short: \usepackage{etoolbox} an then \makeatletter\patchcmd{\ttl@mkchap@i}{\vspace*{\@tempskipa}}{}{}{}\makeatother. – quark67 Mar 18 '23 at 23:07
1

Please provide some more crucial information.

If you are referring to a \mainmatter chapter, you may use \AddToHook{cmd/mainmatter/after}{\setlength{\beforechapskip}{-Xpt}} to reduce the skip by inserting a value in X.