[Tex/LaTex] How to manage chapter title position with a background picture

chaptersformattingtitlesec

I wrote the following code in order to design a chapter title but there is two things I did not succeed to do.

\documentclass{book}

\title{Titre de la thèse}
\author{moi}
\date{\today}

\usepackage{lipsum}

\usepackage[top = 2cm, left = 2cm, right = 2cm, bottom = 2cm, head = 14pt, headsep = .5cm]{geometry}
\usepackage{tikz}
\def\docColor{blue}

\usepackage{titlesec}
\titleformat{\chapter}
  {\color{white}\sffamily\Huge\bfseries}
  {}{0pt}
  {\begin{tikzpicture}[overlay, remember picture]
    \fill[\docColor] (current page.north west) -- (current page.north east) 
        -- ++ (0, -6cm) -- ++ (-\paperwidth, -2cm)
        node[pos=.5, fill=black!60, text=white, minimum width=6cm,
                inner sep=3mm]
        {\sffamily\textsc\chaptername~\thechapter}
        -- cycle;
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{0cm}{4cm}

\begin{document}

\maketitle

\chapter{Un premier chapitre, Un premier chapitre, Un premier chapitre}

\lipsum[1-5]

\chapter{Un second chapitre, Un second chapitre, Un second chapitre}

\lipsum[1-5]

\end{document}

enter image description here

1) I would like to remove the indentation. As you can see, if the title span over two lines they are not left justified.

2) I would like to shift on the right the title in order to put a picture on the left side. I would like to do something like

\parbox[c]{.2\textwidth}{a picture}
\parbox[c]{.8\textwidth}{Chapter title}

Best Answer

Here's one possibility:

enter image description here

  1. Simply comment out a spurious blank space after \end{tikzpicture}.

  2. I used the explicit option for titlesec and then used two side-by-syde \nodes of predefined width; one for the image, the other one for #1 (the actual title).

  3. I also defined a variant using numberless for starred chapters (such as the table of contents, the list of figures, etc).

The code (adjust the settings according to your needs):

\documentclass{book}
\usepackage[top = 2cm, left = 2cm, right = 2cm, bottom = 2cm, head = 14pt, headsep = .5cm]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{lipsum}

\def\docColor{blue}

\titleformat{\chapter}
  {\color{white}\sffamily\Huge\bfseries}
  {}{0pt}
  {\begin{tikzpicture}[overlay, remember picture]
    \fill[\docColor] (current page.north west) -- (current page.north east) 
        -- ++ (0, -6cm) -- ++ (-\paperwidth, -2cm)
        node[pos=.5, fill=black!60, text=white, minimum width=6cm,
                inner sep=3mm]
        {\sffamily\textsc\chaptername~\thechapter}
        -- cycle;
    \node[text width=.2\textwidth,anchor=west] 
    (titleimage)
    {\includegraphics[width=\linewidth]{example-image-a}};    
    \node[text width=.8\textwidth,anchor=west] 
    (title) at (titleimage.east)
    {#1};    
   \end{tikzpicture}%
  }
\titleformat{name=\chapter,numberless}
  {\color{white}\sffamily\Huge\bfseries}
  {}{0pt}
  {\begin{tikzpicture}[overlay, remember picture]
    \fill[\docColor] (current page.north west) -- (current page.north east) 
        -- ++ (0, -6cm) -- ++ (-\paperwidth, -2cm)
        -- cycle;
    \node[anchor=west,text width=\linewidth] 
    (title)
    {#1};    
   \end{tikzpicture}%
  }
\titlespacing*{\chapter}{0pt}{0cm}{5cm}

\title{Titre de la thèse}
\author{moi}
\date{\today}

\begin{document}

\tableofcontents

\chapter{Un premier chapitre, Un premier chapitre, Un premier chapitre}

\lipsum[1-5]

\chapter{Un second chapitre, Un second chapitre, Un second chapitre}

\lipsum[1-5]

\end{document}