0

in the code given below, because of the text that I chose to use, the box around the chapter header changes:

enter image description here

How can I keep the box around all the chapter headers at a fixed height and centered (vertically) in the box? Thanks for your help.

Here is the code:

\documentclass{book}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{calc}
\usepackage[english]{babel}
\usepackage[explicit]{titlesec}
\usepackage{charter}
\usepackage[sc,osf]{mathpazo}
\usepackage{tikz}
\usetikzlibrary{calc,shadows.blur,shapes.symbols}
\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{ocre}{RGB}{243,102,25}
\makeatletter
\renewcommand{\@chapapp}{Problem}
\makeatother

\makeatletter
\def\@makechapterhead#1{%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (.2,0) {}; 
\draw[anchor=west] (\Gm@lmargin+0cm,-4.8cm) node {  %
{\begin{tikzpicture}
    \node[draw=none,shade,
      top color=mybluei,
      bottom color=mybluei,
      rounded corners=6pt,
      blur shadow={shadow blur steps=6}
      ]{\color{white}\fontsize{50}{120}\itshape\rmfamily\chaptertitlename \selectfont\thechapter};
\end{tikzpicture}}
  };
\end{tikzpicture}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (.2,0) {}
\draw[anchor=west] (\Gm@lmargin+1cm,-4.62cm) node {  %
    \parbox[b]{70pt}{\colorbox{mybluei}{%
        \parbox[b][60pt][t]{44pt}{\centering%
          \color{white}%
          {\itshape\rmfamily\small\chaptertitlename}%
          \vfill{\fontsize{50}{120}\selectfont\thechapter}%
        }%
      }%
    }\hspace{15pt}%
    \parbox[b]{\dimexpr\textwidth-150pt}{%
      \raggedright\scshape#1\vskip6pt%
    }%
  };
\end{tikzpicture}};
\end{tikzpicture}
\fi\fi\par\vspace*{270\p@}\stepcounter{chapshift}}}
\makeatother

\pagestyle{plain}

\newcounter{chapshift}
\addtocounter{chapshift}{-1}

\newcommand\BoxColor{ocre!60}

\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}

\usepackage{etoolbox,fancyhdr}

\begin{document}

\chapter{Problem 1}
\section{Paragraphs of Text}\index{Paragraphs of Text}
\lipsum[1]

\chapter{Problem 3}
\section{Paragraphs of Text Two}\index{Paragraphs of Text}
\lipsum[1]

\chapter{Problem 4}
\section{Paragraphs of Text Two}\index{Paragraphs of Text}
\lipsum[1]

\end{document} 
  • 1
    Forbid old style numbers and letters with descenders… :o) – Bernard Mar 4 '16 at 22:24
  • 1
    try always adding a \strut. – barbara beeton Mar 4 '16 at 22:35
  • Are you sure you want to nest a tikzpicture inside a tikzpicture inside a tikzpicture? – egreg Mar 4 '16 at 23:28
  • Hello, is there a less complex solution then? I did it this way because this was easy for me to implement. Please share you thoughts. Thanks. – Joe Mar 4 '16 at 23:35
  • 1
    add \strut either just before or just after \chaptertitlename. that may be a bit large; a slightly smaller alternative is \vphantom{()}. (only one parenthesis is needed for the size, but i put in both to outsmart editors that implement "fence-matching".) – barbara beeton Mar 5 '16 at 16:24

Your Answer

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

Browse other questions tagged or ask your own question.