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?

Jonas Stein
  • 8,909
  • 5
    Welcome to [tex.se]! Have you seen the show case https://www.ctan.org/pkg/memoirchapterstyles?lang=en ? – Andrew Swann Aug 31 '17 at 07:55
  • 4
    Which class do you intend to use? Please provide at least some code! This site is not a we-do-it-for-you-service! Show what you got so far (even if it's not much) and we'll most likely be glad to help. I won't touch the question as it is now! – Skillmon Aug 31 '17 at 08:20
  • what template (.cls) file you are using? – MadyYuvi Aug 31 '17 at 08:32
  • 1
    Fancy chapter package does not really help me, as it does not have the desired layout. – LatexNoob Aug 31 '17 at 10:52
  • 2
    @LatexNoob but you could create the desired layout with it (or without it; or with another package -- who knows, you don't tell us which class you use nor which other packages). – Skillmon Aug 31 '17 at 11:19
  • 1
    You also need to check the requirements for your university. They may even provide/require a LaTeX cls file. – John Kormylo Aug 31 '17 at 11:49
  • @LatexNoob you should edit your question to include this code. – Skillmon Aug 31 '17 at 12:31
  • 3
    A few examples how to modify scrbook chapters: https://tex.stackexchange.com/questions/150923/customizing-chapter-style-in-scrbook https://tex.stackexchange.com/questions/230635/formatting-and-styling-of-headers-using-titlesec-in-scrbook-class – samcarter_is_at_topanswers.xyz Aug 31 '17 at 13:24
  • 3
    Or more recent: https://tex.stackexchange.com/q/388585, https://tex.stackexchange.com/q/387988, https://tex.stackexchange.com/q/246411, https://tex.stackexchange.com/a/376737, https://tex.stackexchange.com/a/375401 – Schweinebacke Aug 31 '17 at 16:06
  • If you have a question to an already given answer please leave a comment below the answer or ask a following-up question instead of modify your question. However I've added information on how to use \includegraphics to my answer. – Schweinebacke Apr 02 '19 at 07:32

1 Answers1

10

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.

Schweinebacke
  • 26,336