0

The question I am asking has been influenced by the partial solutions I have found so far. It could be the wrong question to ask if there is a much easier way. Anyway, I need to put chapter titles inside a gray box. I was able to do this on the book title page using \fcolorbox, but have not been able to get the same effect with the chapters. I tried the titlesec package but found it difficult to understand the documentation. I also looked at the memoir package and was impressed by its length. Unfortunately I can't dedicate a few weeks to studying it and understanding it right now.

Then in the first answer at this link I found a way to dig under the bonnet that seemed promising. Werner provided enough explanation for me to understand the way he used \@makechapterhead and to start customising the code to get what I need. However, I have no idea how to merge that code with the \fcolorbox command to obtain the same effect for the chapters. I realise that these are two different levels of coding, one is package-based, the other is internal. I looked in the color package but the internal code in there is kind of scary so I stopped trying. Here is my test code:

\documentclass[11pt,a4paper]{book}
\usepackage{color}
\definecolor{verylightgray}{rgb}{0.95,0.95,0.95}
\usepackage[left=2cm, top=4cm, right=2cm]{geometry}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\thechapter}{\Alph{chapter}.\ \ }

\makeatletter \def@makechapterhead#1{ \vspace*{50\p@} {\parindent \z@ \centering \normalfont \ifnum \c@secnumdepth >\m@ne \if@mainmatter %\huge\bfseries @chapapp\space \thechapter \huge\bfseries \thechapter %\par\nobreak %\vskip 20\p@ \fi \fi \interlinepenalty@M \Huge \bfseries #1\par\nobreak % \vskip 40\p@ \clearpage } } \makeatother \begin{document} \setlength{\fboxrule}{0.8pt} \fcolorbox{black}{verylightgray}{ \parbox{15cm} {\begin{center} \vspace{0.5cm} \textbf{\huge Book Title} \vspace{0.5cm} \end{center}}} \chapter{Introduction} \section{Objectives and Motivation} \end{document}

As a sub-question which seems too small to ask as a separate question, on the last page you can see that the chapter label shows up right before the section number. Is it possible to change "A. .1 " to simply "1. "? You can ignore the default header and page numbers, they are just showing up in this test code but not in the real document. Many thanks.

pdini
  • 189

1 Answers1

0

Many thanks to Dmitriy who showed exactly what I was looking for, see here.

I did give Memoir a try, but unfortunately I could not get it to work.

Adapting Dmitriy's answer to my problem I got this code to work:

\documentclass[11pt,a4paper]{book}
\usepackage{color}
\definecolor{verylightgray}{rgb}{0.95,0.95,0.95}
\usepackage[left=2cm, top=4cm, right=2cm]{geometry}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\thechapter}{\Alph{chapter}}
\makeatletter
\def\@makechapterhead#1{
\vspace*{5cm}
  {\parindent \z@ \centering \normalfont
    \fcolorbox{black}{verylightgray}{%
    \setlength{\fboxsep}{10mm}%
    \setlength{\fboxrule}{0mm}%
    \framebox[\textwidth][c]{
    \Large\bfseries \thechapter.\quad  #1\par\nobreak
    }}
    \par\nobreak
    \clearpage
}}
\makeatother
\begin{document}
\setlength{\fboxrule}{0.8pt}
\fcolorbox{black}{verylightgray}{
\parbox{15cm}
{\begin{center}
\vspace{0.5cm}
\textbf{\huge Book Title}
\vspace{0.5cm}
\end{center}
}}
\chapter{Introduction}
\section{Objectives and Motivation}
\end{document}
pdini
  • 189