2

I have found a code for a nice chapter heading style which I would like to use and if possible modify a little bit. The code uses the tikz package and a \begin{tikzpicture}...\end{tikzpicture}

The code works okay except for the Table of Contents page which is rendered with a more normal heading style. The issue seems to be with me using the memoir class, which I need to be able to use several packages and redefinitions.

The code works okay for the Table of Contents heading using for example the report class. But it does, as expected, show many 'Undefined control sequence' errors.

As I am not that much experienced with such advanced coding, I would like to ask if it's possible to modify the code to be able to include the Table of Contents heading using the memoir class?

Secondly I was also wondering if it's possible to modify the code a little so that the chapter number is to the right and a bit bigger than the chapter title and with a image as background instead of a lightblue color?

Below is a minimal working document including some code that doesn't seem to work with e.g. the report class.

\documentclass[svgnames,,a4paper,11pt,fleqn,fleqn,twoside,openany]{memoir}

\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\usepackage{ragged2e,anyfontsize}

\usepackage{tikz}
\usepackage{verbatim}                       
\usepackage[explicit]{titlesec}
\usepackage[]{kpfonts}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}

\makepagestyle{Uni}                             % Defines page header and footer from here to ...
\makepsmarks{Uni}{%
    \createmark{chapter}{left}{shownumber}{}{. \ }
    \createmark{section}{right}{shownumber}{}{. \ }
    \createplainmark{toc}{both}{\contentsname}
    \createplainmark{lof}{both}{\listfigurename}
    \createplainmark{lot}{both}{\listtablename}
    \createplainmark{bib}{both}{\bibname}
    \createplainmark{index}{both}{\indexname}
    \createplainmark{glossary}{both}{\glossaryname}
}
\nouppercaseheads
\makeevenhead{Uni}{Gruppe Fib10, 1-15}{}{\leftmark}
\makeoddhead{Uni}{\rightmark}{}{Aalborg Universitet}
\makeevenfoot{Uni}{\thepage}{}{}
\makeoddfoot{Uni}{}{}{\thepage}
\makeheadrule{Uni}{\textwidth}{0.5pt}
\makefootrule{Uni}{\textwidth}{0.5pt}{1mm}

\copypagestyle{Unichap}{Uni}
\makeoddhead{Unichap}{}{}{}
\makeevenhead{Unichap}{}{}{}
\makeheadrule{Unichap}{\textwidth}{0pt}
\aliaspagestyle{chapter}{Unichap}
                                                % ... here


\newcommand*\chapterlabel{}                     % Chapter style from here to...
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
     {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}      %  ... here


\begin{document}
\tableofcontents

\chapter{Introduction}
This is some text

\section{section}
This is some text

\chapter{Main}
\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference
\end{thebibliography}
\end{document}
0

The class memoir has a command for typesetting everything, which makes it extremely customizable. The ToC (Table of Contents) is typeset by the \printtoctitle (the LoT and LoF have similar commands: \printlottitle and... you guessed correctly \printloftitle). All these commands take one Argument, which is the macro containing the list name: \contentsname, \listfigurename, \listtablename. From the memoir manual, \tableofcontents, by default, does something like:

\tocheadstart
\printtoctitle{\contentsname}
\tocmark
\thispagestyle{chapter}
\aftertoctitle

So, to implement the new style we just need to \renewcommand{\printtoctitle}[1]{...} using the same definition you used for the chapters.

As for getting the title to the left side, it's a simple tweak: change the anchor=west to east and xshift=.9\paperwidth to .1\paperwidth. And finally, to get bigger chapter numbers, use a \scalebox{<factor>}{\chapterlabel}, instead of just \chapterlabel, I used a 1.25 factor, you can change it for whatever value suits you best.

(Not so M)WE:

\documentclass[svgnames,,a4paper,11pt,fleqn,fleqn,twoside,openany]{memoir}

\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage[T1]{fontenc}
\usepackage{ragged2e,anyfontsize}

\usepackage{tikz}
\usepackage{verbatim}                       
\usepackage[explicit]{titlesec}
\usepackage[]{kpfonts}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}

\makepagestyle{Uni}                             % Defines page header and footer from here to ...
\makepsmarks{Uni}{%
    \createmark{chapter}{left}{shownumber}{}{. \ }
    \createmark{section}{right}{shownumber}{}{. \ }
    \createplainmark{toc}{both}{\contentsname}
    \createplainmark{lof}{both}{\listfigurename}
    \createplainmark{lot}{both}{\listtablename}
    \createplainmark{bib}{both}{\bibname}
    \createplainmark{index}{both}{\indexname}
    \createplainmark{glossary}{both}{\glossaryname}
}
\nouppercaseheads
\makeevenhead{Uni}{Gruppe Fib10, 1-15}{}{\leftmark}
\makeoddhead{Uni}{\rightmark}{}{Aalborg Universitet}
\makeevenfoot{Uni}{\thepage}{}{}
\makeoddfoot{Uni}{}{}{\thepage}
\makeheadrule{Uni}{\textwidth}{0.5pt}
\makefootrule{Uni}{\textwidth}{0.5pt}{1mm}

\copypagestyle{Unichap}{Uni}
\makeoddhead{Unichap}{}{}{}
\makeevenhead{Unichap}{}{}{}
\makeheadrule{Unichap}{\textwidth}{0pt}
\aliaspagestyle{chapter}{Unichap}
                                                % ... here


\newcommand*\chapterlabel{}                     % Chapter style from here to...
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
     {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=west,xshift=.1\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\scalebox{1.25}{\chapterlabel}#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}      %  ... here
\renewcommand{\printtoctitle}[1]{%
\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
          (\paperwidth,3cm);
        \node[anchor=west,xshift=.1\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue, font=\normalfont\sffamily\Huge\bfseries\scshape\color{white}]
              {#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
}

\begin{document}
\tableofcontents

\chapter{Introduction}
This is some text

\section{section}
This is some text

\chapter{Main}
\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference
\end{thebibliography}
\end{document}

enter image description here

Comment: optimally you should use the memoir ways of formatting chapters headings (and all other parts), the mechanism is well thought. The titlesec package is, as far as I understand, for less costumizable classes.

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.