有吸引力的章节标题和部分样式

有吸引力的章节标题和部分样式

我偶然发现了一个网站,在那里我发现了这个很有吸引力的章节标题和章节设计。

https://webusers.imj-prg.fr/~leonardo.zapponi/leo_divers/Agreg/Matrices_normales.pdf

在此处输入图片描述

以下是我尝试重现的情况

\documentclass[12pt,a4paper]{report}
\usepackage{tikz}
\tikzstyle{a} = [text width=\textwidth-1cm,rectangle,draw=orange,rounded corners=2mm,line width=1pt,fill=orange!5,minimum width=\textwidth,align=left,inner sep=5mm]
\tikzstyle{b} = [rectangle,draw,rounded corners=2mm,line width=.5pt,fill=orange!25,minimum height=0mm,align=left,inner sep=2mm,font=\bfseries]
\def\titlebox#1#2{%
\begin{tikzpicture}
\node[a](a){#2};
\node[b,right=3mm](b) at (a.north west){#1};
\node[b,left=3mm](b) at (a.south east){2015-2016};
\end{tikzpicture}
}
\def\lembox#1#2{%
\begin{tikzpicture}
\node[a](a){#2};
\node[b,right=3mm](b) at (a.north west){#1};
\end{tikzpicture}
}
\parindent=0mm
\begin{document}
\titlebox{title}{
text
}
\lembox{title}{text}
\end{document}

其生产成果为:

在此处输入图片描述

我如何改进我的代码来生成相同的图像

答案1

一些代码开始工作。它混合了tcolorbox引理和章节标题以及tikzpictures章节。采用之前的一些评论。我不知道如何传递参数,titleformat然后标题框添加在章节样式内固定。这些添加与title选项和日期一起制成一个overlayed节点。它们有不同的格式,你应该纠正。我没有调整 tikz 和 tcolorbox 之间的线条,因此,部分的线条和引理和章节框架是不同的。你也应该调整它们。

在此处输入图片描述

\documentclass{report}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage{varwidth}

\tcbset{
    orange/.style={
        enhanced,
        colback=orange!10,
        colframe=orange,
        fonttitle=\bfseries,
        colbacktitle=orange!40,
        coltitle=black,
        attach boxed title to top left={%
            yshift*=-\tcboxedtitleheight/2, 
            xshift=5mm},
        boxed title style={colframe=gray}
    }
}

\newtcbtheorem[auto counter]{mylemma}{Lemma}{%
    orange
    }{lm}

\titleformat{\chapter}[display]
  {\normalfont\Large\bfseries}
  {}
  {}
  {%
    \begin{tcolorbox}[orange, halign=center, valign=center, title=test, overlay={\node[draw=gray, fill=orange!40, rounded corners, anchor=east, font=\small\bfseries] at ([xshift=-5mm]frame.south east){2016-2017};}]%, title=Title]
    #1
   \end{tcolorbox}%
  }

\titleformat{\section}
  {\normalfont\large\bfseries}{}{0em}
  {%
    \setbox0=\hbox{\large\bfseries\thesection}%
    \begin{tikzpicture}
        \draw[orange, ultra thick](0,0) -- ++(0:\linewidth);
        \node[draw=orange,
        rounded corners,
        fill=orange!10,
        ultra thick,
        anchor=west,
        outer sep=0pt
        ] {\thesection\hspace{.5em}\hangindent\wd0\strut#1\strut};
    \end{tikzpicture}%
  }

\titleformat{name=\section,numberless}[display]
  {\normalfont\Large\bfseries}{}{0em}
  {%
    \begin{tikzpicture}
        \draw[orange, line width=1mm](0,0) -- ++(0:\linewidth);
        \node[draw=orange,
        rounded corners,
        fill=orange!10,
        line width=1mm,
        anchor=west,
        outer sep=0pt
        ] {\strut#1\strut};
    \end{tikzpicture}%
  }
\titlespacing*{\section}
  {0pt}{4.5ex plus 1ex minus .2ex}{1ex plus .2ex}

\begin{document}

\chapter*{Diagonalizar matrices}
\section{Test numbered section}
\begin{mylemma}{Test}{a}
\lipsum[3]
\end{mylemma}

\begin{mylemma}{Test}{a}
\lipsum[3]
\end{mylemma}

\section*{Test unnumbered section}
\lipsum[4]
%\section{Test numbered section with a long title; in fact, it spans two lines}
%\lipsum[4]

\end{document}

我从 Gonzalo 的回答中得到了一些想法章节样式与 tcolorbox 有关?标题后面的符号或图像

答案2

像这样吗?

\documentclass[12pt,a4paper]{report}
\usepackage{lipsum}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\tikzstyle{a} = [text width=\textwidth-1cm,rectangle,draw=orange,rounded corners=2mm,line width=1pt,fill=orange!5,minimum width=\textwidth,align=left,inner xsep=5mm, inner ysep=10mm]
\tikzstyle{b} = [rectangle,draw,rounded corners=2mm,line width=.5pt,fill=orange!25,minimum height=0mm,align=left,inner sep=2mm,font=\bfseries]
\tikzstyle{c} = [rectangle,draw,rounded corners=2mm,draw=orange,line width=.5pt,fill=orange!5,minimum height=0mm,align=left,inner sep=2mm,font=\bfseries]
\def\titlebox#1#2{%
\begin{tikzpicture}
\node[a](a){#2};
\node[b,right=3mm](b) at (a.north west){#1};
\node[b,left=3mm](b) at (a.south east){2015-2016};
\end{tikzpicture}
}
\def\lembox#1#2{%
\begin{tikzpicture}
\node[a](a){#2};
\node[b,right=3mm](b) at (a.north west){#1};
\end{tikzpicture}
}
\def\chapbox#1{%
\begin{tikzpicture}
\draw[orange] (0,0) -- (\textwidth,0);
\node[right,c] (0,0){\thechapter{} -- #1};
\end{tikzpicture}
}
\def\secbox#1{%
\begin{tikzpicture}
\draw[orange,line width=.5pt] (0,0) -- (\textwidth,0);
\node[right,c] (0,0){\thesection{} -- #1};
\end{tikzpicture}
}
\parindent=0mm
\titleformat{\section}
{\normalfont}{}{0em}
{\secbox{#1}}
\titleformat{\chapter}
{\normalfont}{}{0em}
{\chapbox{#1}}
\begin{document}
\titlebox{title}{
blablabla
}
\chapter{First chapter}
\lipsum[1]
\section{First section}
\lembox{title}{text}
\lipsum[2]
\section{Second section}
\lipsum[3]
\lembox{title}{text}
\lipsum[4]
\end{document}

您可以通过 titlesec 修改章节和部分,包括默认章节从新页面开始。

相关内容