Необычные заголовки разделов

Необычные заголовки разделов

Я хотел добавить линии от края левого поля к цветному полю в заголовках разделов, чтобы это выглядело так:

введите описание изображения здесь

Вот код, который у меня есть на данный момент:

\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}

решение1

Будет проще, если вы замените команду на узел, так что вы сможете использовать его для рисования всего остального. Линия, которая проходит по ширине текста, на данный момент является своего рода ручной. Это означает, что она охватывает ширину текста, а затем длина узла плюс внутренний разделитель удаляются из этого значения.

Выход

введите описание изображения здесь

Код

    \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}

Связанный контент