4

I am creating a booklet for a conference, using the documentclass scrbook. The document is composed of different chapters: "About", "Timetable", "List of participants", etc. Each of these "chapters" starts on a new page (that can either odd or even).

I want my chapter to render something like this (this is what I've managed so far based on this: http://texample.net/tikz/examples/fancy-chapter-headings/):

enter image description here

enter image description here

This is produced with the following MWE

\documentclass[openany]{scrbook}

\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{blindtext}

%--------------------------------

\titleformat
{\chapter} % command
{\bfseries\Huge} % format
{%
 \thechapter
} % label
{0pt} % sep
{
\ifodd\value{page}{%
    \begin{tikzpicture}[remember picture,overlay]
        \node[yshift=-3cm] at (current page.north west)
        {\begin{tikzpicture}[remember picture, overlay]
             \fill[orange] (0,0) rectangle (0.6\textwidth,1em);
            \node[above, yshift=-0.2em, xshift=\textwidth] {#1};
        \end{tikzpicture}
        };
    \end{tikzpicture}
}\else{%\
    \begin{tikzpicture}[remember picture,overlay]
        \node[yshift=-3cm] at (current page.north east)
         {\begin{tikzpicture}[remember picture, overlay]
            \fill[orange] (0,0) rectangle (-0.5\paperwidth,1em);
            \node[above, yshift=-0.2em, xshift=-\textwidth] (0,0)  {#1};
        \end{tikzpicture}
        };
    \end{tikzpicture}
}\fi%
} % before-code
[
\vspace{-3cm}
] % after-code

%------------------------------------------------
\begin{document}

\chapter*{About}
\blindtext[3]
\chapter*{Timetable}
\blindtext[3]

\end{document}

However, some points to improve:

  • the "Timetable" chapter is flushed left which is what I want, but the "About" is not compeltely flushed right. How can I do this?

  • for now the width of the orange bar is fixed to 0.5\textwidth. How can I make it adaptive, so that it goes from the border of the page up to the chapter name (the width depends on the chapter name)?

1
  • Maybe a hack like \node[yshift=-0.2em, xshift=0.6\textwidth,text width=0.4\textwidth,anchor=south west,draw] {#1\hfill{}};? For the second question you first put the node and then draw the orange bar if there is space left
    – percusse
    Nov 7, 2017 at 15:58

1 Answer 1

6

A solution without titlesec and tikz but with xcolor. Note that KOMA-script comes with the macro \ifthispageodd.

\documentclass[openany]{scrbook}

\usepackage[utf8]{inputenc}

\usepackage{xcolor}
\usepackage{blindtext}

\newlength\mybarpadding
\mybarpadding=1em\relax% change this to alter the space between the rule and the chapter title

\RedeclareSectionCommand[%
    ,afterskip=4em plus 1pt minus 1pt%
    ,beforeskip=-1pt%1.2em plus 1pt minus 1pt%
    ,level=0%
    ,toclevel=0%
]{chapter}%

\setkomafont{chapter}{\normalfont\normalsize\bfseries\Huge}

\renewcommand{\chapterlinesformat}[3]{%
  \ifthispageodd{%
    \hfill%
    \raisebox{-0.2em}{%
      \makebox[0pt][r]{\textcolor{orange}{\rule{\paperwidth}{1em}}}%
    }%
    \hspace{\mybarpadding}%
    #2#3%
  }{%
    \hbox{%
      #2#3%
      \hspace{\mybarpadding}%
      \raisebox{-0.2em}{%
        \makebox[0pt][l]{\textcolor{orange}{\rule{\paperwidth}{1em}}}%
      }%
    }%
  }%
}

\begin{document}

\chapter*{About}
\blindtext[3]
\chapter*{Timetable}
\blindtext[3]

\chapter{foo}
\end{document}

enter image description here enter image description here enter image description here

You must log in to answer this question.

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