UPDATED ANSWER
Do \usepackage[nostruts]{titlesec}
, which will remove the struts like my answer below did.
The feature was added with version 2.11, released 2019-07-16.
ORIGINAL ANSWER
The package titlesec
adds \strut
in some places. In your case you have to defeat this behavior in three places:
\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{margin=5mm, paper=a6paper, showframe=true}
\usepackage{titlesec}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\ttl@select}{\strut}{}{}{}
\patchcmd{\ttlh@hang}{\strut}{}{}{}
\patchcmd{\ttlh@hang}{\strut}{}{}{}
\makeatother
\titleformat*\section{\Large}
\titleformat*\subsection{\large}
\usepackage{lipsum}
\begin{document}
\section*{Using titlesec}
\subsection*{Lorem Ipsum}
\lipsum[3]
\end{document}
The macros involved are \ttl@select
and \ttlh@hang
(in the second one \strut
appears twice. If other styles are selected it may be necessary to patch \ttlh@display
or \ttlh@runin
.
Here is an example without package titlesec
.
\documentclass[numbers=noenddot]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{charter}
\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}
\addtokomafont{disposition}{\usefont{T1}{qhv}{b}{n}\selectfont\color{myblueii}}
\addtokomafont{chapter}{\fontsize{30pt}{30pt}\selectfont}
\newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}}
\newkomafont{chaptername}{\itshape\rmfamily\small\color{white}}
\addtokomafont{section}{\fontsize{14pt}{14pt}\selectfont}
\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}
\addtokomafont{subsection}{\fontsize{12pt}{12pt}\selectfont}
\newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}
\renewcommand\chapterformat{%
\raisebox{-6pt}{\colorbox{mybluei}{%
\parbox[b][60pt]{45pt}{\centering%
{\usekomafont{chaptername}{\chapapp}}%
\vfill{\usekomafont{chapternumber}{\thechapter\autodot}}%
\vspace{6pt}%
}}}\enskip}
\renewcommand\sectionformat{%
\setlength\fboxsep{5pt}%
\raisebox{-4pt}{\colorbox{mybluei}{%
\enskip\usekomafont{sectionnumber}{\thesection\autodot}\enskip}%
\quad%
}}
\renewcommand\subsectionformat{%
\setlength\fboxsep{5pt}%
\raisebox{-4pt}{\colorbox{mybluei}{%
\enskip\usekomafont{subsectionnumber}{\thesubsection\autodot}\enskip}%
\quad%
}}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\makebox[0pt][l]{\rule[-5pt]{\textwidth}{1pt}}%
\@hangfrom{#3}{#4}%
}
\makeatother
\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\chapter{Chapter Title}
\section{Section Title}
\blindtext
\addsec{Unnumbered Section Title}
\blindtext
\subsection{Subsection Title}
\blindtext
\subsubsection{Subsubsection Title}
\blindtext
\blinddocument
\end{document}
Update because of updates in the question:
To get black chapter entries in the table of contents use
\addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue
If all subsections should be unnumbered use
\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered
And here is an example with lower rules:
\documentclass[numbers=noenddot]{scrbook}[2015/10/03]
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{charter}
\definecolor{mybluei}{RGB}{28,138,207}
\definecolor{myblueii}{RGB}{131,197,231}
\addtokomafont{disposition}{\usefont{T1}{qhv}{b}{n}\selectfont\color{myblueii}}
\addtokomafont{chapter}{\fontsize{30pt}{30pt}\selectfont}
\newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}}
\newkomafont{chaptername}{\itshape\rmfamily\small\color{white}}
\addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue
\addtokomafont{section}{\fontsize{14pt}{14pt}\selectfont}
\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}
\addtokomafont{subsection}{\fontsize{12pt}{12pt}\selectfont}
\newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}
\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered
\renewcommand\chapterformat{%
\raisebox{-6pt}{\colorbox{mybluei}{%
\parbox[b][60pt]{45pt}{\centering%
{\usekomafont{chaptername}{\chapapp}}%
\vfill{\usekomafont{chapternumber}{\thechapter\autodot}}%
\vspace{6pt}%
}}}\enskip}
\renewcommand\sectionformat{%
\setlength\fboxsep{5pt}%
\colorbox{mybluei}{%
\parbox{40pt}{\centering\usekomafont{sectionnumber}{\thesection\autodot}}}%
\quad%
}
\renewcommand\subsectionformat{%
\setlength\fboxsep{5pt}%
\colorbox{mybluei}{%
\parbox{60pt}{\centering\usekomafont{subsectionnumber}{\thesubsection\autodot}}}%
\quad%
}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{50pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}%
}{}%
\ifstr{#1}{subsection}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{70pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}%
}{}%
}
\makeatother
\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\chapter{Chapter Title}
\section{Section Title}
\blindtext
\addsec{Unnumbered Section Title}
\blindtext
\subsection{Subsection Title}
\blindtext
\subsubsection{Subsubsection Title}
\blindtext
\blinddocument
\end{document}
Update 2 because of a second update in the question
You are using a \parskip
so \par
inserts vertically space that must be removed:
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\parskip\z@% <- added, deactivates the parskip locally
\par\nobreak
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{50pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}%
}{}%
\ifstr{#1}{subsection}{%
\parskip\z@% <- added, deactivates the parskip locally
\par\nobreak
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{70pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}%
}{}%
}
\makeatother
Some additional remarks:
Do not set \parskip
manually! Use the KOMA-Script option parskip=half-
instead. There are other values for this option like half
, half+
, half*
and the same with full
. For further explanations see the scrguien.pdf (KOMA-Script documentation).
I would suggest to use package geometry
to set the page margins.
To get an entry for the lists and the bibliography in the table of contents use the KOMA-Script options listof=totoc
and bibilography=totoc
instead of \addcontentsline{toc}{chapter}{...}
.
You redefine \chapterformat
twice. Decide which one you want to use and remove the other.
The header of your new defined mychapterpagestyle
is outside the paper.
Best Answer
Use the epigraph package.
Edit:
To remove unwanted space use
\beforeepigraphskip=0pt
. Here is a minimal:% \tt % \meaning\epigraph \newpage abc \end{document}
Uncomment the
\meaning\epigraph
to see the macro for\epigraph
. This method of debugging is normally quicker than reading through manuals for obvious situations like this.