Encabezados de sección elegantes

Encabezados de sección elegantes

Quería agregar las líneas desde el borde del margen izquierdo al cuadro coloreado en los encabezados de mi sección para que se vea así:

ingrese la descripción de la imagen aquí

Aquí está el código que tengo hasta ahora:

\documentclass[11pt]{book}
    \usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,letterpaper]{geometry}
    \usepackage[demo]{graphicx}
    \usepackage{lipsum}
    \usepackage{xcolor}
    \definecolor{mybluei}{RGB}{52,177,201}
    \definecolor{myblueii}{RGB}{63,200,244}
    \definecolor{myblueiii}{RGB}{199,234,253}
    \definecolor{ultramarine}{RGB}{0,45,97}
    \usepackage{tikz}
    \usetikzlibrary{shadows.blur}
    \usetikzlibrary{shapes.symbols}
    \usepackage{etoolbox,fancyhdr}
    \usepackage[explicit,calcwidth]{titlesec}

    \makeatletter
    \newcommand{\thechapterimage}{}%
    \newcommand{\chapterimage}[1]{\renewcommand{\thechapterimage}{#1}}%
    \def\@makechapterhead#1{%
    {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
    \fi\fi\par\vspace*{120\p@}\stepcounter{chapshift}}}
    \makeatother

    \newcommand\SectionFont{\usefont{T1}{qhv}{b}{n}\selectfont}
    \titleformat{\section}
      {\normalfont\SectionFont\color{myblueii}}
      {\colorbox{mybluei}{%
        \parbox[c][16pt][c]{40pt}{%
          \centering\textcolor{white}{\SectionFont\Large\thesection}%
          }%
        }%
      }
      {1em}
      {#1}
      [\vspace{-1.2\baselineskip}%
        \color{myblueii}\hspace*{\dimexpr40pt+2\fboxsep\relax}%
        \rule{\dimexpr\textwidth-40pt-2\fboxsep\relax}{1pt}%
      ]

    \usetikzlibrary{calc}
    \pagestyle{plain}
    \newcounter{chapshift}
    \addtocounter{chapshift}{-1}
    \newcommand\BoxColor{%
      ultramarine}

    \def\subsectiontitle{}
    \renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize#1}{}}
    \renewcommand{\subsectionmark}[1]{\def\subsectiontitle{#1}}
    \pagestyle{fancy}
    \renewcommand{\headrule}{{\color{myblueii}%
    \hrule width\headwidth height\headrulewidth depth\headrulewidth}}
    \fancyhf{} \fancyhead[LE,RO]{\normalsize\colorbox{myblueii}{\color{white}\sffamily\bfseries\strut\quad\thepage\quad}}
    \fancyhead[LO]{\textcolor{mybluei} \rightmark%
    \begin{tikzpicture}[overlay,remember picture]
      \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
        text height=4cm,align=center,anchor=north east]
      at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
      {\rotatebox{90}{\parbox{4cm}{%
       \centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
      \end{tikzpicture}}
    \fancyhead[RE]{Testing Book%
      \begin{tikzpicture}[overlay,remember picture]
      \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
        text height=4cm,align=center,anchor=north west]
      at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
      {\rotatebox{90}{\parbox{4cm}{%
        \centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
      \end{tikzpicture}} 

\makeatother

\begin{document}
\chapterimage{bishade}
\chapter{Testing}
\section{Test One}
\lipsum[1-2]
\section{Test Two}
\lipsum[1-2]
\chapter{Testing Three}
\section{Test Four}
\lipsum[1-2]
\section{Test Two}
\lipsum[1]
\newpage
\section{Test Two}
\lipsum[1]
\end{document}

Respuesta1

Es más fácil si reemplazas el comando con un nodo, así puedes usarlo para dibujar todo lo demás. La línea que va sobre el ancho del texto es algo manual por ahora. Lo que significa que abarca el ancho del texto y luego la longitud del nodo, más la separación interna, se elimina de ese valor.

Producción

ingrese la descripción de la imagen aquí

Código

    \documentclass[11pt]{book}
    \usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,letterpaper]{geometry}
    \usepackage[utf8]{inputenc}
    \usepackage[demo]{graphicx}
    \usepackage{lipsum}
    \usepackage{xcolor}
    \definecolor{mybluei}{RGB}{52,177,201}
    \definecolor{myblueii}{RGB}{63,200,244}
    \definecolor{myblueiii}{RGB}{199,234,253}
    \definecolor{ultramarine}{RGB}{0,45,97}
    \usepackage{tikz}
    \usetikzlibrary{shadows.blur}
    \usetikzlibrary{shapes.symbols}
    \usepackage{etoolbox,fancyhdr}
    \usepackage[explicit,calcwidth]{titlesec}

    \makeatletter
    \newcommand{\thechapterimage}{}%
    \newcommand{\chapterimage}[1]{\renewcommand{\thechapterimage}{#1}}%
    \def\@makechapterhead#1{%
    {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
    \fi\fi\par\vspace*{120\p@}\stepcounter{chapshift}}}
    \makeatother

    \newcommand\SectionFont{\usefont{T1}{qhv}{b}{n}\selectfont}
    \titleformat{\section}
      {\normalfont\SectionFont\color{myblueii}}
      {\tikz[baseline=(a.base), overlay]{
            \node[fill=mybluei, anchor=south west, outer sep=0, draw=none, inner sep=.5mm, 
                text=white,font=\Large, text width=1.5cm, align=center, minimum height=8.5mm,
                label={[text=myblueii]right:#1}
            ] (a) {\thesection};
        \foreach \x in {.25,.5,.75}{%
        \draw[mybluei, ultra thick] (a) ($(a.south west)!\x!(a.north west)$) --++ (-4,0);
        }
        \draw[myblueii, ultra thick] ($(a.south east)!.25!(a.north east)$) --++ (\textwidth-1.6cm,0);
        }
      }
      {1em}
      {}

    \usetikzlibrary{calc}
    \pagestyle{plain}
    \newcounter{chapshift}
    \addtocounter{chapshift}{-1}
    \newcommand\BoxColor{%
      ultramarine}

    \def\subsectiontitle{}
    \renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize#1}{}}
    \renewcommand{\subsectionmark}[1]{\def\subsectiontitle{#1}}
    \pagestyle{fancy}
    \renewcommand{\headrule}{{\color{myblueii}%
    \hrule width\headwidth height\headrulewidth depth\headrulewidth}}
    \fancyhf{} \fancyhead[LE,RO]{
        \normalsize\colorbox{myblueii}{\color{white}\sffamily\bfseries\strut\quad\thepage\quad}
        }
    \fancyhead[LO]{\textcolor{mybluei} \rightmark%
    \begin{tikzpicture}[overlay,remember picture]
      \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
        text height=4cm,align=center,anchor=north east]
      at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $)
      {\rotatebox{90}{\parbox{4cm}{%
       \centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};    
      \end{tikzpicture}}
    \fancyhead[RE]{Testing Book%
      \begin{tikzpicture}[overlay,remember picture]
      \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
        text height=4cm,align=center,anchor=north west]
      at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $)
      {\rotatebox{90}{\parbox{4cm}{%
        \centering\textcolor{white}{\bfseries\scshape\rightmark \\ \sffamily\subsectiontitle}}}};
      \end{tikzpicture}} 

\makeatother

\setlength{\headheight}{14pt}

\begin{document}
\chapterimage{bishade}
\chapter{Testing}
\section{Test One}
\lipsum[1-2]
\section{Test Two}
\lipsum[1-2]
\chapter{Testing Three}
\section{Test Four}
\lipsum[1-2]
\section{Test Two}
\lipsum[1]
\newpage
\section{Test Two}
\lipsum[1]
\end{document}

información relacionada