章节样式与 tcolorbox 有关?

章节样式与 tcolorbox 有关?

是否可以使用 tcolorbox 包自定义如下图所示的章节样式?如果不行,您能告诉我哪个包可以生成这种样式吗?谢谢在此处输入图片描述

答案1

这是一种使用的可能性tcolorboxtitlesec. 未编号章节的图片:

在此处输入图片描述

编号章节的图像:

在此处输入图片描述

代码:

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage[many]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}

\definecolor{titlebgdark}{RGB}{0,163,243}
\definecolor{titlebglight}{RGB}{191,233,251}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}
  {}
  {20pt}
  {%
    \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};  % if using amsbook, this should be \chaptername
      } 
    ]
    #1
    \end{tcolorbox}%
  }
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge\bfseries}
  {}
  {20pt}
  {%
    \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}

相关内容