花哨的部分标题

花哨的部分标题

我想将左边距边缘的线条添加到我的部分标题中的彩色框中,使其看起来像这样:

在此处输入图片描述

这是我迄今为止的代码:

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

相关内容