4

I would like to have a chapter design like

enter image description here

So in the Box of the title, should be an image in the background and above the number of the chapter.

The packages I'm using so far, are:

\documentclass[a4paper,11pt,twoside]{scrbook} %{book}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\usepackage{fancybox}
\usepackage{tikz}
\usepackage{cleveref}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{needspace}
\usepackage{mathabx}
\usepackage{enumerate}
\usepackage{makeidx}  
\usepackage[ruled]{algorithm2e}
\usepackage{mathrsfs}
\usepackage[many]{tcolorbox}

Update: by substituting the ducks through:

\chapternumberbackground{\begin{tikzpicture}\includegraphics[width=.2\linewidth]{logo.pdf}\end{tikzpicture}}

I get an division by 0 error ... why? and how can I fix it?

11

You can do a lot of things with KOMA-Script's chapter headings, if you redefine \chapterformat and \chapterlinesformat or \chapterlineswithprefixformat. If I interpret your question as

How to use ducks in chapter headings of KOMA-Script?

I could, e.g, do:

\documentclass[chapterprefix]{scrbook}
\usepackage{lmodern}% need scalable font
\usepackage{tikzducks}% essential to use ducks
\usepackage{blindtext}

\RedeclareSectionCommand[%
  font=\normalfont\huge\scshape,
  prefixfont=\Large,
  innerskip=0pt
]{chapter}

\let\raggedchapter\raggedleft

\renewcommand*{\chapterlineswithprefixformat}[3]{%
  \IfArgIsEmpty{#2}{#3}{%
    \rule{.333\linewidth}{1pt} #2%
    \parbox[b][\dimexpr .2\linewidth-\dp\strutbox-\baselineskip]{.78\linewidth}{%
      \raggedchapter\strut\ignorespaces #3%
    }\hfill
    \makebox[.2\linewidth][r]{\rule[-\dp\strutbox]{\linewidth}{1pt}}%
  }%
}
\renewcommand*{\chapterformat}{%
  \IfUsePrefixLine{%
    \chapapp\enskip
    \usekomafont{chapter}%
    \raisebox{\dimexpr -.2\linewidth+\baselineskip}[0pt][0pt]{%
%      \frame{%
        \resizebox*{.2\linewidth}{.2\linewidth}{%
          \currentchapternumberbackground
        }%
%      }%
      \makebox[0pt][r]{%
        \parbox{.2\linewidth}{%
          \centering
          \fontsize{.75\linewidth}{\linewidth}\selectfont
          \raisebox{.75\linewidth}{\color{gray!50!red!50}\thechapter}\par
        }%
      }%
    }%
  }{%
    \thechapter\autodot\enskip
  }%
}
\newcommand*{\chapternumberbackground}[1]{%
  \renewcommand*{\currentchapternumberbackground}{#1}%
}
\newcommand*{\currentchapternumberbackground}{%
  {\color{red!50}\rule{1cm}{1cm}}%
}

\begin{document}
\tableofcontents
\chapternumberbackground{\begin{tikzpicture}\duck\end{tikzpicture}}
\chapter{Chapter Name}
\blindtext

\chapternumberbackground{\begin{tikzpicture}\duck[longhair=teal]\end{tikzpicture}}
\chapter{Another Chapter Name}
\blindtext

\chapternumberbackground{\begin{tikzpicture}\duck[crazyhair=green,eyebrow=blue]\end{tikzpicture}}
\chapter{Once more a Longer Chapter Name}
\blindtext

\end{document}

First chapter

Second chapter

Third chapter

For more information about \RedeclareSectionCommand, \chapterformat and \chapterlineswithprefixformat see the KOMA-Script manual also available in German. And don't forget the famous information about using ducks in TikZ.

And yes, instead of the tikzpicture with the \duck commands, you can use a \includegraphics command like:

\chapternumberbackground{\includegraphics[page=54,trim=30 0 30 0,clip]{example-image-duck}}

Note, the \resizebox in the code of the full example would resize such an external image too. So if you want images in another size, you have to change or remove the \resizebox.

  • 1
    tikzducks is not for demo only :) – Skillmon Sep 2 '17 at 11:13
  • 1
    @Skillmon Your absolutely right. Fixed. ;-) – Schweinebacke Sep 2 '17 at 11:24
  • 3
    I WILL USE THIS FOR MY THESIS – Paulo Cereda Sep 2 '17 at 11:45
  • 1
    +1 for the ducks! In the new package version, there will be a graduate duck -> perfect for a phd thesis! i.stack.imgur.com/x0ogv.png (and the bounding box size will also be fixed so the ducks don't get distorted) – user36296 Sep 2 '17 at 13:50
  • 2
    Another one has joined the Duck Side of the Force! <3 <3 <3 – CarLaTeX Sep 2 '17 at 14:38

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.