6

I am formatting a book and I am using LuaLaTex. I am trying to obtain the following formatting for the chapters, reproduction of the chapter number and title

The following code correctly generates the chapter title

\usepackage{titlesec}

%Chapter heading
\newfontfamily\chapterfont[Color=black]{Avenir Light}% set font

\titlespacing{\chapter}% {left}{before}{after}[right]
{50pt}%left
{3ex plus 2ex}%before
{1.7cm}%after

\titleformat{\chapter}% command to be modified
  {\fontsize{24}{27}\bfseries\scshape\chapterfont} %format
  {\thechapter.}% label
  {1em}% sep
  {} % before-code
  [{\color{red}\titlerule[1pt]}] % after-code

but I cannot find a way to make the graphical chapter number, and also to extend the red rule to the right page border. Any help would be much appreciated. Thank you in advance.

6

A solution based on tcolorbox package


% !TeX program = lualatex                                   
% !TeX encoding = utf8
\documentclass[14pt]{book}
\usepackage{fontspec}
\usepackage[svgnames]{xcolor}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usepackage[
    a4paper,
    left=2cm,
    right=2cm,
    top=2.5cm,
    bottom=2cm,
]{geometry}

\newtcbox{\mychapternum}{enhanced,nobeforeafter,tcbox raise base,boxrule=1pt,top=0mm,bottom=0mm,
  colframe=cyan,coltext=cyan,colback=cyan!10!white, halign = right,
    width=50pt,arc=7mm, sharp corners=west, boxsep=4mm,
    overlay={\draw[thick] ([yshift=3ex]frame.north west) -- ([yshift=-3ex]frame.south west);

      }
  }  

%Chapter heading
%\newfontfamily\chapterfont[Color=black]{Avenir Light}% set font
\titlespacing{\chapter}% {left}{before}{after}[right]
{60pt}%left
{1ex plus 2ex}%before
{1.7cm}%after

\titleformat{\chapter}% command to be modified
  {\fontsize{24}{27}\bfseries\scshape} %format
  {\hspace*{-70pt}
    \mychapternum{\thechapter}
    }% label
  {0em}% sep
  {} % before-code
  [{\color{red}
    \begingroup
      \setlength{\titlewidth}{\textwidth}
      \titleline*{\titlerule[1pt]}
    \endgroup  
    }] % after-code

\begin{document}


\chapter{My title}

\lipsum[20-30]

\chapter{My title}

\lipsum[20-30]
\end{document}

enter image description here

A solution based on TikZ package. This solution more flexible for adjustemets.


% !TeX program = lualatex                                   
% !TeX encoding = utf8    
\documentclass[14pt]{book}      
\usepackage{fontspec}      
\usepackage[svgnames]{xcolor}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usetikzlibrary{shapes.misc, positioning}
\usetikzlibrary{calc}   
\usepackage[
    a4paper,
    left=2cm,
    right=2cm,
    top=2.5cm,
    bottom=2cm,
]{geometry}   
%Chapter heading
%\newfontfamily\chapterfont[Color=black]{Avenir Light}% set font
\titlespacing{\chapter}% {left}{before}{after}[right]
{2cm}%left
{2ex}%before
{1.7cm}%after

\titleformat{\chapter}% command to be modified
  {\Huge\bfseries\scshape} %format
  {\hspace*{-1cm}
      \tikz [anchor=base, baseline,remember picture, overlay]{%
        \node[line width = 2pt, draw=cyan, fill =cyan!10, anchor=base, rectangle,  text width=2cm, align=right, rounded rectangle,rounded rectangle west arc=5pt, minimum height=4ex,
           inner sep=11pt] (A)
              {\color{cyan}\thechapter};
    \draw[line width = 2.5pt] ([yshift=3ex]A.north west) -- ([yshift=-3ex]A.south west);
    \draw[line width = 1pt, red] let \p1=(A.south east), \p2=(current page.east) in  ([xshift=2.6ex]A.south east) -- +(\x2,0);
    }%
    }% label
  {\dimexpr2em\relax}% sep
  {} % before-code
  [] % after-code

\begin{document}
\chapter{My title}
\lipsum[20-30]
\addtocounter{chapter}{20}
\chapter{My title}
\lipsum[20-30]
\end{document}

enter image description here

  • Wow! Spectacular! Thanks a whole lot!! – pierocol Dec 1 '18 at 14:52
  • Would you also be able to tell me how I can extend the red rule to the right page margin instead that to the right of \textwidth? – pierocol Dec 1 '18 at 15:03
  • 1
    @pierocol instead {\color{red}\titlerule[1pt]} put {\color{red}\rule{\dimexpr5pt+\textwidth\relax}{0.2pt}} – sergiokapone Dec 1 '18 at 15:16
  • 1
    @pierocol I had changed code. – sergiokapone Dec 1 '18 at 15:52
  • 1
    @pierocol I had added another solution. – sergiokapone Dec 1 '18 at 20:29

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.