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} 
6
  • 1
    Forbid old style numbers and letters with descenders… :o)
    – Bernard
    Mar 4, 2016 at 22:24
  • 1
    try always adding a \strut. Mar 4, 2016 at 22:35
  • Are you sure you want to nest a tikzpicture inside a tikzpicture inside a tikzpicture?
    – egreg
    Mar 4, 2016 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, 2016 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".) Mar 5, 2016 at 16:24

1 Answer 1

1

This could help you : I use tcolorbox package

\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}

\usepackage{tcolorbox}
\tcbuselibrary{skins}

\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{ocre}{RGB}{243,102,25}

\titleformat{\chapter}%
{\itshape\rmfamily\Huge\color{white}}%
{}
{1em}
{%
  \begin{tcolorbox}[enhanced, hbox, notitle,%
    colback=mybluei, coltext=white, colframe=mybluei,%
    equal height group=chaptitle,%
    ]
    #1
  \end{tcolorbox}
}

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .