0

I have looked over this question: Package titlesec adds extra space on top of \chapter, despite commands to the contrary

And mine is in a certain sense a duplicate. However, I am wondering if there is any way to do this in a more simpler way? I go completely blank at this code in the solution.

\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

I usually use packages to construct commands and so on, but this part of the code I don't get at all. Sorry, all I really need is an alternative as I usually prefer to understand what my code does.

My chapter heading style is the following: The result And the code is:

\documentclass[11pt]{book}

\usepackage{titlesec, lipsum, xcolor}

\titleformat{\chapter}[display] % shape
    {\bfseries \Huge}
    {\hfill \textcolor{gray!50}{\thechapter}} % Label
    {0pt} % Separation after chapter name.
    {\vspace{70pt}} % Between Chapter no. and name
    [\vspace{-1em}\rule{\textwidth}{0.3pt}\\]

\titlespacing*{\chapter}{0pt}{0pt}{0pt} 

\begin{document}

\chapter{Hi}
\lipsum[1-8]

\end{document}

Basically, I want to eliminate all the space before and after if that's possible, preferable through simpler code than the one provided in solution.

I don't get what things like \def, \ttl, \global, \ifcase, \relax, \fi, \beforetitleunit, \makeatletter, \makeatother, or anything with @ in it stands for.

If there isn't a "simpler" solution, that's fine I guess... I can use things like tikz and other stuff pretty well if that helps. Or if there's a shape other than default that'll give me the same sort of result that would be great to.

  • Do you mean the spacing between chapter number and chapter title, or between top margin and chapter number? – Bernard Jan 10 '17 at 19:14
  • @Bernard The spacing before he chapter number and top margin, as well as below the chapter name. Thanks for correcting. Fixed the title. :) – Osama Kawish Jan 10 '17 at 19:17

1 Answers1

2

Here you are, as simple as I could. It seems you misunderstood some parameters. Note that for the horizontal justification, I used the dedicated tools provided by titlesec (\filleft, \filright, \filcenter); simalarly for rules (\titlerule). Also, your `vspace{70pt} in your 4th mandatory rgument should simply be 70pt in the 3rd argument.

\documentclass[11pt]{book}
\usepackage[showframe]{geometry}%
 \usepackage{titlesec, lipsum, xcolor}

\titleformat{\chapter}[display] % shape
    {\bfseries \Huge}
    {\filleft \textcolor{gray!50}{\thechapter}} % Label
    {70pt} % Separation after chapter label.
    {} % Before chapter title
    [\titlerule]
\titlespacing*{\chapter}{0pt}{-5ex}{1ex}

\begin{document}

\chapter{Hi}
\lipsum[1-8]

\end{document} 

enter image description here

Bernard
  • 271,350