我尝试使用 LateX 做一些我通常在 Word 上很容易完成的布局,因为我想 100% 使用 LaTeX(我目前将自己描述为中级低级 LaTeX 用户)。以下是我打算做的事情:
我已经使用 tikz 包来进行矩形布局(我不知道这是否是最好的解决方案,因为我需要对每一页重复它,但无论如何)。 现在我想自动获取章节标题的颜色框。
我已经检查了与我的问题相关的两个讨论,但是我无法理解如何控制参数例如文本的形状(颜色、大小)和颜色框(颜色、高度、全线或仅限于文本)。
- 为标题提供横跨整个字体区域的背景颜色
- 章节标题的背景颜色
- 标题安全的文档
特别是,我想
- 尽可能接近示例
- 将这些修改限制在章节内,而不修改子章节中的任何内容
- 拥有一些可以自动缩放并“附加”到 \section{} 的东西,这意味着避免使用 tikz(我相信需要为每个部分手动绘制,并且每次修改时都需要移动,并且需要为每个部分指定,就像我对每个页面的矩形布局所做的那样)。
这是我目前尝试使用下面引用的讨论中的解决方案,它看起来更容易理解,但并不完全方便(部分标题的大小发生变化并变得比小节小,框的形状与文本一致,参数无法清楚地控制)。
\documentclass[a4paper,12pt]{article}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amsfonts,amssymb,empheq}
\usepackage{graphicx}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage[explicit,nobottomtitles]{titlesec}
\usepackage[left=1.3cm,right=1.3cm,top=0cm,bottom=2.6cm]{geometry} % Text Margins
\usepackage{lipsum}
\renewcommand{\thesection}{\Roman{section}.}
\pdfinclusioncopyfonts=1
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
% linkcolor=RoyalNavyBlue,
linkcolor=black,
urlcolor=cyan,
citecolor=black}
\setlength\parindent{0pt}
\def\arraystretch{2}
\usepackage{enumitem}
\usepackage{caption}
\usepackage{geometry}
\usepackage{linegoal}
\usepackage{subcaption}
\usepackage{cleveref}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}
\usepackage{fancyhdr}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[NavyBlue, remember picture,overlay] % NavyBlue rectangle layout
\draw[very thick]
([yshift=-24pt,xshift=24pt]current page.north west)--
([yshift=-24pt,xshift=-24pt]current page.north east)--
([yshift=24pt,xshift=-24pt]current page.south east)--
([yshift=24pt,xshift=24pt]current page.south west)--cycle;
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Section1}
\subsection{Subsection1}
\subsubsection{Subsection1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\titleformat{\section} % titlesec modification to get color box
{\color{white}\bf}
{}
{0pt}
{\colorbox{NavyBlue}{\thesection. #1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tableofcontents
\listoftables
\listoffigures
\section{Section2}
\subsection{Subsection2}
\subsubsection{Subsection2}
\end{document}
总结一下:如果您能从引用的链接中选择一个解决方案,并按照字面意思调整/评论它,以便我能够使其适应我的目标,我将不胜感激!