0

I have a problem with documentclass{book} concerning the behavior of the titles, in particular for chapters.

The following is a piece of code, I modified from Bernard's answer to the question ''Chapter styling'', that partly answer my problem.

Still I have some problems:

  1. The chapter's number is not in line with the left margin;

  2. The first word of the first line and the first word of the second line do not start on the same point;

  3. I would like this setting not to act for the table of contents (right now it does, and I get "Content" not left-aligned), or for arbitrary chapters I would like to have unnumbered;

  4. I would like to get the title at the top of the page,

  5. I would like to change the size of the font of the chapter's number and of the chapter's title without problems.
    (I just don't get how fontsize actually works... I change the numbers, and nothing happens!)

    \documentclass[11pt,a4paper]{book}
    
    \usepackage{microtype}
    
    \usepackage{framed}
    %
    \renewenvironment{leftbar}{%
    \def\FrameCommand{\hspace{25pt}}%
    \MakeFramed %
    {\advance\hsize-\width \FrameRestore}}%
    {\endMakeFramed}
    %
    \usepackage[explicit,newlinetospace,clearempty]{titlesec}%
    
    \titleformat{\chapter}[hang]%
    { \Large \bfseries}%
    { \parbox[t] {\dimexpr0\linewidth-1cm\relax}%
    { \fontsize{4cm}{1} \bfseries%
    \raisebox{-1.25\height} {\thechapter} } }%
    {1em}%
    %
    {%
    \begin{minipage}[t]{0.9\linewidth}%
    \begin{leftbar}%
    {\bfseries \LARGE \selectfont %
    \rule{0pt}{0ex} \strut#1 \hfil \vskip2ex\break}%
    \end{leftbar}%
    \end{minipage}%
    }
    %
    \titlespacing{\chapter}{0pt}{2\baselineskip}{6\baselineskip}
    
    \usepackage{blindtext}
    
    \begin{document}
    
    \tableofcontents
    
    \chapter[Lorem Ipsum Dolor Sit Amet Consectetuer]{Lorem Ipsum Dolor Sit Amet \\Consectetuer}
    
    \blindtext
    
    \section{Lorem Ipsum}
    
    \blindtext
    
    
    \end{document} 
    

    How could I fix these problems?

    Any feedback is greatly appreciated.
    Thanks a lot in advance for your time.

  • 1
    Would this answer of mine help? – Bernard Sep 25 '16 at 13:28
  • Thanks a lot! From the output, I would definitely say yes! Still, I am taking a look at the code (which for my newbie eye is kinda heavy) to see what I really need out of it. It seems to me that most of it deals with giving the possibility to the OP to add abstracts (which I don't need), with various colors. – Kolmin Sep 25 '16 at 13:41
  • I think the only line of code I need from your previous answer is: \titleformat{\chapter}[hang]{\usefont{T1}{phv}{m}{n}}{% \parbox[t]{\dimexpr0.12\linewidth-20pt\relax}{\fontsize{48}{48}\selectfont\raisebox{-1.25\height}{\color{TFFrameColor}\thechapter}}}{1em}. Am I right? However, honestly, I am a bit at loss at how to modify it to get what I was looking for. I tried, but it does not compile. – Kolmin Sep 25 '16 at 14:11
  • @Bernard: I edited the question after some time spent trying to get how to modify your piece of code to my basic needs. Still there are some things that do not work properly (or, simply, I don't know how to make them work). :) – Kolmin Sep 25 '16 at 15:09
  • I'm going to look at your code. There's a small problem with the font size. Do I understand well: you want the chapter numbers to be 4cm high? – Bernard Sep 25 '16 at 15:25
2

Here is what I propose. If you want vertical rules between chapter numbers and titles, leftbar (hence framed) are useless. You can make the number the size you want by scaling it (\resizebox{…}). I changed the style to block which is more sensible here.

The numbers were not quite at the margin because of the side bearings. I added a frame around the chapter number to show it is really at the left margin. B.t.w., in my opinion, if you can afford some colour, it looks nicer.

\documentclass[11pt,a4paper]{book}
\usepackage[showframe]{geometry}%
\usepackage[x11names]{xcolor}
\usepackage{fourier}
 \usepackage{microtype}
\usepackage{graphicx}
\usepackage[explicit,newlinetospace,clearempty]{titlesec}%

\titleformat{\chapter}[block]%
{ \Large}%
{\raisebox{-0.9\height}{\setlength\fboxrule{1pt}\fcolorbox{IndianRed3}{white}{\resizebox{!}{4cm}{\thechapter}}}}
{10pt}%
{%
\begin{minipage}[t]{0.8\linewidth}%
\bfseries \LARGE%
#1%
\end{minipage}%
}
%
\titlespacing*{\chapter}{0pt}{-3.5ex}{6\baselineskip}

\usepackage{blindtext}

\begin{document}
\setcounter{chapter}{4}
\chapter[Lorem Ipsum Dolor Sit Amet Consectetuer]{Lorem Ipsum Dolor Sit Amet \\Consectetuer}

\blindtext

\section{Lorem Ipsum}

\blindtext


\end{document} 

enter image description here

  • First of all, thanks a lot for the answer and for the time you spent on it, as I previously wrote, I really appreciate that! However, in some sense the code I derived from your answer is actually closer to what I was looking for. Thus, for example, here, if I change the size of the chapter number, things get sort of messy. Also, I see that the number box is left-aligned, but I assume the number inside (here the "5") is centered in the box, isn't it? Finally, given your previous code, why the font size command does not react to my modification? Anywya, again thanks! – Kolmin Sep 25 '16 at 18:30
  • Is it actually possible that what I am looking for is easily obtained through memoir? – Kolmin Sep 25 '16 at 18:32
  • Unfortunately, I couldn't tell you: I never used memoir. For the problem of your code, as far as I know, you have to give the arguments as numbers. The units are points, but the height of a glyph is generally less than the given size , and depends on the font design. Roughly 4 cm corresponds to 112 pt, but to have an effective height of 4cm, you need to write \fontsize{180}{180}\selectfont. That said, it doesn't work with the default ComputerModern (it seems to display the predefined sizes). However, it works with Latin Modern. – Bernard Sep 25 '16 at 20:57
  • Thus, indeed also you noticed that the font size command doesn't behave well with computer modern, didn't you? That's kinda weird. Anyway, again thanks a lot. Most probably I will put a bounty in the next days. – Kolmin Sep 26 '16 at 7:38
  • Latin Modern is very close. It's the standard font for languages with accented letters. – Bernard Sep 26 '16 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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