Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My university's Ph.D. thesis guidelines specify an exact top-margin on the first pages of chapters. I am trying to use titlesec to set this margin, but it seems to always set it to be more than it should be. The margin from the top of the text area to the word Chapter is more than 0 when the following code is compiled, and as far as I can tell the following code should set it to 0.

\documentclass[12pt]{report}
\usepackage[compact]{titlesec}
\titleformat{\chapter}
    [display]
    {\normalfont\Large\bfseries\centering}
    {\large\chaptertitlename\ \thechapter}
    {0in}
    {}

\titlespacing*{\chapter}{0pt}{*0}{*0}
\begin{document}
\chapter{Hello}
Hello
\end{document}

What I really want is a top-margin of exactly two inches total above the chapter name. I was hoping, given Gonzalo's response, that the following would work, but it still sets the top-margin to 0. What's even more perplexing is that adding the \vspace*{1in} adds MORE than one inch to the top-margin! Why??

\documentclass[12pt]{report}

\usepackage[showframe]{geometry}
\usepackage[compact]{titlesec}

\titleformat{\chapter}
    [display]
    {\normalfont\Large\bfseries\centering}
    {\large\chaptertitlename\ \thechapter}
    {.1in}
    {}

% the following block eliminates the extra space above a chapter heading
\makeatletter
\def\ttl@mkchap@i#1#2#3#4#5#6#7{%
  \ttl@assign\@tempskipa#3\relax\beforetitleunit
  %\vspace*{\@tempskipa}% NEW
  %\vspace*{1in}
  \global\@afterindenttrue
  \ifcase#5 \global\@afterindentfalse\fi
  \ttl@assign\@tempskipb#4\relax\aftertitleunit
  \ttl@topmode{\@tempskipb}{%
  \ttl@select{#6}{#1}{#2}{#7}}%
  \ttl@finmarks  % Outside the box!
  \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}}
\makeatother

\titlespacing*{\chapter}
    {0pt} % left
    {1in} % before
    {.5in} % after

\begin{document}
\chapter{Hello}
Hello
\end{document}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

The internal command \ttl@mkchap@i adds some vertical spacing to the chapter titles, so you need to remove this space; this can be done by commenting out the line responsible for this space (the one I marked with % NEW below):

\documentclass{book}
\usepackage[showframe]{geometry} % just for the example
\usepackage{titlesec}
\usepackage{lipsum}

\makeatletter
\def\ttl@mkchap@i#1#2#3#4#5#6#7{%
  \ttl@assign\@tempskipa#3\relax\beforetitleunit
  %\vspace*{\@tempskipa}% NEW
  \global\@afterindenttrue
  \ifcase#5 \global\@afterindentfalse\fi
  \ttl@assign\@tempskipb#4\relax\aftertitleunit
  \ttl@topmode{\@tempskipb}{%
    \ttl@select{#6}{#1}{#2}{#7}}%
  \ttl@finmarks  % Outside the box!
  \@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}}
\makeatother

\titleformat{\chapter}[display]
    {\normalfont\Large\bfseries\centering}
    {\large\chaptertitlename\ \thechapter}
    {0in}
    {}
\titlespacing*{\chapter}{0pt}{*0}{*0}

\begin{document}

\chapter{Test chapter}

\lipsum[1-12]

\end{document}

enter image description here

I added the geometry package with the showframe option just to illustrate the result.

Now that an edit has been made to the original question, here's the code producing the new requested result:

\documentclass[12pt]{report}
 \usepackage[top=1in, bottom=1in, left=1.5in, right=1in,showframe]{geometry}
\usepackage[compact]{titlesec}
\usepackage{lipsum}

\newlength\mylen
\setlength\mylen{\dimexpr\topskip+\baselineskip-\ht\strutbox-1in\relax}

\titleformat{\chapter}
    [display]
    {\normalfont\Large\bfseries\centering}
    {\large\chaptertitlename\ \thechapter}
    {.1in}
    {}

\titlespacing*{\chapter}
    {0pt} % left
    {-\mylen} % before
    {.5in} % after

\begin{document}
\chapter{Hello}
\lipsum[1-12]
\end{document}

enter image description here

share|improve this answer
    
Thanks, this works perfectly. But I'm wondering, is this the intended behavior of titlesec? From the documentation it seems to me that my code as it was written should achieve what I was asking for without any fiddling. –  Andrey Jun 11 '12 at 17:22
    
@Andrey yes, it is the intended behaviour, unfortunately the documentation doesn't mention it. –  Gonzalo Medina Jun 11 '12 at 17:28
    
what I really want is a top-margin of exactly one inch, see my edit. –  Andrey Jun 11 '12 at 18:51
    
@Andrey are you modifying in some way (by using the geometry package, for example) the default page layout? If so, please add this information to your question. –  Gonzalo Medina Jun 11 '12 at 19:29
    
sorry, I didn't mean to be rude, I wasn't sure whether to start a whole new question thread (which doesn't seem like the right thing to do), and I can't add code to comments. To answer your second question, yes, I have the following line in my code: \usepackage[top=1in, bottom=1in, left=1.5in, right=1in,showframe]{geometry} –  Andrey Jun 11 '12 at 19:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.