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}
Probably there's a much more elegant tcolorbox
solution, but you could always 'freelance' the frame as well:
\documentclass{article}
\usepackage{lipsum}
\usepackage[skins,breakable]{tcolorbox}
\begin{document}
% Example taken from Thomas F. Sturm Manual for version 3.93 p. 346
% Problem: After a break, The style of the boxed title is lost
% Christian Hupfer found a solution that keeps the style of the boxed title after a break in a tcolorbox.
% http://tex.stackexchange.com/questions/315091/tcolorbox-same-boxed-title-style-after-break
% The solution works well for frames made of a continuous line.
% Is there a way to make it work for dashed frames ?
\tcbset{%
boxtitlestuff/.style={%
frame empty,
colback=black!2!white,
},
brokentitle/.style={%
geometry nodes=true,
skin=freelance,
extras first={%
overlay={%
\draw [preaction={draw=green!15!white, line width=1pt, rounded corners}, rounded corners, green!50!white, line width=1pt, dashed] ([yshift=1pt, xshift=-1pt]interior.north west) rectangle ([yshift=-1pt, xshift=1pt]interior.south east);
\node[above, rounded corners, draw, green!50!white, line width=1pt, fill=green!15!white, text=green!50!black, font=\bfseries\normalsize] (A) at ([yshift=-.25\baselineskip]interior.north) {#1};
}
},
extras middle and last={%
overlay={%
\draw [preaction={draw=green!15!white, line width=1pt, rounded corners}, rounded corners,green!50!white, line width=1pt, dashed] ([yshift=1pt, xshift=-1pt]interior.north west) rectangle ([yshift=-1pt, xshift=1pt]interior.south east);
\node[above, rounded corners, draw=black, line width=.8pt, fill=black!2!white, text=black, font=\bfseries\normalsize] (A) at ([yshift=-.25\baselineskip]interior.north) {continued boxed title};
}
}
}
}
\begin{tcolorbox}[%
brokentitle=Boxed title,
breakable,
frame empty,
colframe=green!15!white,
]
\tiny
\lipsum
\lipsum
\end{tcolorbox}
\end{document}
Best Answer
This uses a 'tricky' overlay approach, setting explicitly another
tcolorbox
as the box title for the broken parts of the box.The
extras middle and last=
option is meant to add features to the 'middle' and 'last' box parts, i.e. the ones after breaking the box.