Something like that?
In my example code, I made a new environment mybox
which takes tcolorbox
options as optional argument, then the title and subtitle text as normal arguments.
The new length settings are done by
my rule=1pt,
left to separator=3cm,
separator to subtitle=1cm,
where my rule
stores the rule width and the two other options store the distances to the vertical line as you requested.
\documentclass{report}
\usepackage{tcolorbox,lipsum}
\tcbuselibrary{skins,raster,breakable}
\newlength{\normalparindent}
\AtBeginDocument{\setlength{\normalparindent}{\parindent}}
\tcbset{before upper={\setlength{\parindent}{\normalparindent}}}
\tcbset{
my rule/.store in=\myrule,
left to separator/.store in=\mylefttoseparator,
separator to subtitle/.store in=\myseparatortosubtitle,
}
\newtcolorbox{mybox}[3][]{%
my rule=1pt,
left to separator=3cm,
separator to subtitle=1cm,
enhanced,
frame hidden,interior hidden,
sharp corners,
boxrule=\myrule,boxsep=0pt,
left=0pt,right=0pt,top=0.35cm,bottom=0.35cm,
toptitle=0.35cm,bottomtitle=0.35cm,
colframe=black,colback=white,coltitle=black,
borderline north={\myrule}{0pt}{black},
borderline south={\myrule}{0pt}{black},
fonttitle=\bfseries,fontupper=\normalsize,
before skip=0.375cm+2pt,after skip=0.475cm+2pt,
lefttitle=\mylefttoseparator+\myrule+\myseparatortosubtitle,
title={\raggedright\mbox{}#3},
underlay unbroken and first={
\node[right,inner sep=0pt,outer sep=0pt,
font=\large\bfseries,% <-- title font
text width=\mylefttoseparator-5mm] at (title.west) {#2};
\draw[tcbcol@frame,line width=\myrule]
([xshift=-\myrule,yshift=-\myrule/2]title.south west)--([xshift=\myrule,yshift=-\myrule/2]title.south east)
([xshift=\mylefttoseparator+\myrule/2]title.south west)--([xshift=\mylefttoseparator+\myrule/2]title.north west);
},
#1,
}
\begin{document}
\begin{mybox}{TITLE}{SUBTITLE}
\noindent\lipsum[2]
\end{mybox}
\begin{mybox}{TITLE}{Subtitle (If the subtitle is too long, like it is here,
then it should wrap like this, and the title on the left
hand side should be centered relative to the subtitle)}
\noindent\lipsum[3]
\end{mybox}
\end{document}
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}
Best Answer
Copied from
tcolorbox
's documentation: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 ifhyperref
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 sayLibrary 'lipsum'
.