将标题放在彩色框中

将标题放在彩色框中

我想知道如何将章节标题放入颜色框中并更改样式和个性化。目前我唯一能做的是...

在此处输入图片描述

我喜欢做的是改变标题的样式,放入框中等等。感谢您的所有想法!

答案1

你可以做一些简单的事情:

% !TeX encoding = UTF-8
% !TeX spellcheck = fr_FR

\documentclass[11pt, frenchb, twoside]{report}

% IMPORTS
\usepackage[usenames,dvipsnames,svgnames,rgb]{xcolor}
\usepackage{adjustbox}
\usepackage{blindtext}
\usepackage{hyperref}
\usepackage{polyglossia}
\usepackage[explicit]{titlesec}

\titleformat{\section}
            [block]
            {\Large}
            {}
            {0in}
            {\adjustbox{margin=1ex,cfbox=blue 1pt}{\textbf{\thesection}~~\underline{\scshape#1}}}

\begin{document}
    \section{The First Section}\blindtext[2]
\end{document}

简单的 MWE

然后变得更加复杂:

% !TeX encoding = UTF-8
% !TeX spellcheck = fr_FR

\documentclass[11pt, frenchb, twoside]{report}

% LENGTH
\newlength{\goldenMargin}
\setlength{\goldenMargin}{1.618in}
\newlength{\imageWidth}
\setlength{\imageWidth}{.5\paperwidth}

% IMPORTS
\usepackage[usenames,dvipsnames,svgnames,rgb]{xcolor}

\usepackage{adjustbox}
\usepackage{blindtext}
\usepackage{ifoddpage}
\usepackage[paperwidth=8.125in,paperheight=10.25in,
            hmargin={.5\goldenMargin,\goldenMargin},vmargin={.5\goldenMargin},
            marginparwidth={\dimexpr \goldenMargin - 2\marginparsep}]{geometry}
\usepackage{hyperref}
\usepackage{letltxmacro}
\usepackage{polyglossia}
\usepackage{shadowtext}
\usepackage[explicit]{titlesec}

\usepackage{tikz}
\usetikzlibrary{backgrounds, calc, patterns, positioning}

\usepackage{xifthen}
\usepackage{xparse}
\usepackage{xstring}

\tikzset{
    nosep/.style={inner sep=0pt,outer sep=0pt},
    solid white/.style={fill=white,fill opacity=.8},
    post hatch/.style={postaction={pattern=north west lines}}}

\titleformat{\section}
            [block]
            {\Large}
            {}
            {0in}
            {\shadowrgb{0,0,0}\shadowoffset{.5pt}\color{white}\adjustbox{margin=1ex,fbox=1pt}{\shadowtext{\textbf{\thesection}~~\ul{\scshape#1}}}}

% % % % % % % % FULLBOX % % % % % % % %
% #1 content
\ProvideDocumentCommand \fullBox{ m }
{%
    \makebox[\textwidth]{
        \checkoddpage%
        \ifoddpage%
            \hspace*{\dimexpr\evensidemargin-\oddsidemargin-.1cm}%
        \else%
            \hspace*{-\dimexpr\evensidemargin-\oddsidemargin+.1cm}%
        \fi%
        \noindent#1}
}

% % % % % % % % SECTION % % % % % % % %
% #1 star version -> insert toc
% #2 label parameter (also image name)
% #3 section content
% #4 section insight
\LetLtxMacro\oldSection \section
\RenewDocumentCommand \section{ s o m m }
{%
    \cleardoublepage\thispagestyle{empty}%
    \fullBox{
        \tikz[remember picture,overlay,nosep,blend mode=multiply]
        \node[anchor=north,post hatch,minimum height=.5\paperheight,minimum width=\paperwidth] (bg) at (current page.north)
        {\IfValueTF{#2}{\includegraphics[width=\paperwidth,height=.5\paperheight,keepaspectratio]{#2}}{}};}
    \IfBooleanTF{#1}
        {\oldSection*{#3}}
        {\oldSection{#3}}
    \IfValueTF{#2}{\label{sec:#2}}{}
    \tikz[remember picture,pattern=crosshatch dots,overlay,nosep]
    \node[solid white,post dots,anchor=north west,inner sep=\parindent,xshift=\goldenMargin,yshift=-5cm,
          text width=\dimexpr\textwidth-\parindent,font=\sffamily\bfseries,align=justify] at (bg.north west) {#4};
    \vspace{.4\textheight}
}

\begin{document}
    \section[example-image]
        {The First Section}
        {A résumé of the content}
\end{document}

复杂多波反射模型

相关内容