Warning: I am no titlesec
expert, but as far as I understood the 3rd. mandatory argument of a \titleformat
is used for the vertical separation of the title. So use a negative value to shift up the title.
I introduced the \chaptertopspacing
length variable and set it to the value of 130pt
, this value is somewhat 'arbitrary' and should be changed to one's own needs.
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage[many]{tcolorbox}
\usepackage{fancyhdr}
\usepackage{lmodern}
\usepackage{lipsum}
\definecolor{titlebgdark}{RGB}{0,163,243}
\definecolor{titlebglight}{RGB}{191,233,251}
\newlength{\chaptertopspacing}
\setlength{\chaptertopspacing}{130pt}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}
{}
{-\chaptertopspacing}
{%
\begin{tcolorbox}[
enhanced,
colback=titlebgdark,
boxrule=0.25cm,
colframe=titlebglight,
arc=0pt,
outer arc=0pt,
leftrule=0pt,
rightrule=0pt,
fontupper=\color{white}\sffamily\bfseries\huge,
enlarge left by=-1in-\hoffset-\oddsidemargin,
enlarge right by=-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth,
width=\paperwidth,
left=1in+\hoffset+\oddsidemargin,
right=\paperwidth-1in-\hoffset-\oddsidemargin-\textwidth,
top=0.6cm,
bottom=0.6cm,
overlay={
\node[
fill=titlebgdark,
draw=titlebglight,
line width=0.15cm,
inner sep=0pt,
text width=1.7cm,
minimum height=1.7cm,
align=center,
font=\color{white}\sffamily\bfseries\fontsize{30}{36}\selectfont
]
(chapname)
at ([xshift=-4cm]frame.north east)
{\thechapter};
\node[font=\small,anchor=south,inner sep=2pt] at (chapname.north)
{\MakeUppercase\chaptertitlename};
}
]
#1
\end{tcolorbox}%
}
\titleformat{name=\chapter,numberless}[display]
{\normalfont\huge\bfseries}
{}
{-\chaptertopspacing}
{%
\begin{tcolorbox}[
enhanced,
colback=titlebgdark,
boxrule=0.25cm,
colframe=titlebglight,
arc=0pt,
outer arc=0pt,
remember as=title,
leftrule=0pt,
rightrule=0pt,
fontupper=\color{white}\sffamily\bfseries\huge,
enlarge left by=-1in-\hoffset-\oddsidemargin,
enlarge right by=-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth,
width=\paperwidth,
left=1in+\hoffset+\oddsidemargin,
right=\paperwidth-1in-\hoffset-\oddsidemargin-\textwidth,
top=0.6cm,
bottom=0.6cm,
]
#1
\end{tcolorbox}%
}
\titlespacing*{\chapter}
{0pt}{0pt}{40pt}
\makeatother
\begin{document}
\chapter*{A test unnumbered chapter}
\lipsum[4]
\chapter{A test chapter with a long title that will span more than one line}
\lipsum[4]
\end{document}
Here's the version with a special \newtcolorbox
setting:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage[many]{tcolorbox}
\usepackage{fancyhdr}
\usepackage{lmodern}
\usepackage{blindtext}
\definecolor{titlebgdark}{RGB}{0,163,243}
\definecolor{titlebglight}{RGB}{191,233,251}
\newlength{\chaptertopspacing}
\setlength{\chaptertopspacing}{130pt}
% Common settings for unstarred and starred chapters
\newtcolorbox{chaptertitlebox}[1][]{%
enhanced,
colback=titlebgdark,
boxrule=0.25cm,
colframe=titlebglight,
arc=0pt,
outer arc=0pt,
remember as=title,
leftrule=0pt,
rightrule=0pt,
fontupper=\color{white}\sffamily\bfseries\huge,
enlarge left by=-1in-\hoffset-\oddsidemargin,
enlarge right by=-\paperwidth+1in+\hoffset+\oddsidemargin+\textwidth,
width=\paperwidth,
left=1in+\hoffset+\oddsidemargin,
right=\paperwidth-1in-\hoffset-\oddsidemargin-\textwidth,
top=0.6cm,
bottom=0.6cm,
#1
}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}
{}
{-\chaptertopspacing}
{%
\begin{chaptertitlebox}[%
overlay={
\node[
fill=titlebgdark,
draw=titlebglight,
line width=0.15cm,
inner sep=0pt,
text width=1.7cm,
minimum height=1.7cm,
align=center,
font=\color{white}\sffamily\bfseries\fontsize{30}{36}\selectfont
]
(chapname)
at ([xshift=-4cm]frame.north east)
{\thechapter};
\node[font=\small,anchor=south,inner sep=2pt] at (chapname.north)
{\MakeUppercase\chaptertitlename};
}
]
#1
\end{chaptertitlebox}%
}
\titleformat{name=\chapter,numberless}[display]
{\normalfont\huge\bfseries}
{}
{-\chaptertopspacing}
{%
\begin{chaptertitlebox}
#1
\end{chaptertitlebox}%
}
\titlespacing*{\chapter}
{0pt}{0pt}{40pt}
\makeatother
\begin{document}
\chapter*{A test unnumbered chapter}
\blindtext[10]
\chapter{A test chapter with a long title that will span more than one line}
\blindtext[10]
\end{document}
Copied from tcolorbox
's documentation:
\documentclass{article}
\usepackage{lipsum}
\usepackage[skins]{tcolorbox}
\usepackage{hyperref}
\newtcbox{\mylib}{enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=0mm,bottom=0mm,
right=0mm,left=4mm,arc=1pt,boxsep=2pt,before upper={\vphantom{dlg}},
colframe=green!50!black,coltext=green!25!black,colback=green!10!white,
overlay={\begin{tcbclipinterior}\fill[green!75!blue!50!white] (frame.south west)
rectangle node[text=white,font=\sffamily\bfseries\tiny,rotate=90] {LIB} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}
\MakeRobust\mylib
\ifdefined\pdfstringdefDisableCommands
\pdfstringdefDisableCommands{\def\mylib#1{'#1'}}
\fi
\begin{document}
Library \mylib{lipsum}:
\lipsum[1]
\end{document}
The line \MakeRobust\mylib
makes \mylib
robust, so that you can use it in the argument of commands like \section
or \caption
. The line \pdfstringdefDisableCommands
(used only if hyperref
is loaded) makes \mylib
produce a sensible PDF outline entry when used in \section
. If you then do \section{Library \mylib{lipsum}}
it won't break (because of \MakeRobust
), and the PDF outline will say Library 'lipsum'
.
Best Answer
\=
is a macron accent command. In common with most other commands taking a key-value list, you can use braces to hide commas or equals signs in a value, so