0

I want to color background of chapter title like this picture.

enter image description here

The color is:

enter image description here

MWE (xelatex):

\documentclass{book}

\usepackage{titlesec} \usepackage{tikz} % or maybe with tcolorbox package

\usepackage{xepersian} % Last package \settextfont{Amiri} % This font has been installed with TeX Live

\titleformat{\chapter}[display] {\normalfont\fontsize{16}{19.2}\selectfont\bfseries}% {\filleft\chaptertitlename\ \tartibi{chapter}}{1ex}% {\filright\fontsize{16}{19.2}\selectfont} \titlespacing*{\chapter}{0pt}{50pt}{2\baselineskip}

\begin{document}

\chapter{آزمایش}

\end{document}

The output of MWE:

enter image description here

1 Answers1

0

Like this?

(3rd version)

%XeTeX
\documentclass[draft]{book}
\usepackage[showframe]{geometry}
\usepackage{changepage}
\usepackage{xcolor}
% \definecolor{fgcol}{rgb}{51,51,255}
\definecolor{fgcol}{HTML}{3333ff}
%\definecolor{fgcol}{rgb}{0,0,1}
%\usepackage{titlesec}
\usepackage[explicit]{titlesec}
%\usepackage{tikz} % or maybe with tcolorbox package
\usepackage{xepersian} % Last package
\settextfont{Amiri} % This font has been installed with TeX Live

% https://tex.stackexchange.com/a/18578/112708 \newlength{\myl} \setlength{\myl}{\textwidth} \addtolength{\myl}{-\marginparsep} % \the\myl \makeatletter \newlength{\lmargin} \setlength{\lmargin}{\dimexpr\Gm@lmargin} \newlength{\rmargin} \setlength{\rmargin}{\dimexpr\Gm@rmargin} \newlength{\loffset} \setlength{\loffset}{\lmargin} \newlength{\roffset} \setlength{\roffset}{\rmargin} \makeatletter

\titleformat{\chapter}[display] {\normalfont\fontsize{16}{19.2}\selectfont\bfseries}% {\filleft% \hspace{\loffset} \chaptertitlename\ \tartibi{chapter}}{1ex}% {\begin{adjustwidth}{-\lmargin}{-\rmargin} \colorbox{fgcol}{\begin{minipage}{\paperwidth} %{\myl} % only across body \vspace{2em} \color{white} \filright\fontsize{16}{19.2}\selectfont #1 \hspace{\roffset} \vspace{2em} \end{minipage}}\end{adjustwidth}}

\titlespacing*{\chapter}{0pt}{50pt}{2\baselineskip}

\begin{document} %\newgeometry{margin=0in} \chapter{آزمایش} %\restoregeometry

\end{document}

enter image description here

Erwann
  • 2,100
  • Thank you. Can you change the width of color box to paperwidth? and also a little shadow at above and below it? – Bahman Mirzakhani Mar 24 '21 at 03:52
  • @BahmanMirzakhani. Yes. You're going to have to play with the l/r offsets to get the title and label where you want them to be. – Erwann Mar 24 '21 at 03:57
  • @BahmanMirzakhani for the shadows, I recommend you post another question for that only (MWE). – Erwann Mar 24 '21 at 04:00