我正在尝试构建自定义部分标题,其中文本位于指定高度的彩色框顶部,下方是另一个指定高度的彩色框。就像这样:
我所得到最接近的信息如下:
使用此代码
\documentclass[a4paper]{article}
\usepackage{xcolor,lipsum}
\usepackage{titlesec}
\titleformat{name=\section}[block]
{\sffamily\LARGE\color{white}}
{}
{} % distance from left hand side
{\colorsection}
\titlespacing*{\section}
{} % distance from the left
{\baselineskip}
{\baselineskip}
\newcommand{\colorsection}[1]{%
\colorbox{blue!70}
{\parbox
{\dimexpr\textwidth\fboxsep}
{\thesection\ #1}}
\colorbox{blue!50}
{\parbox[][30pt][]
{\pagewidth}
{}}
}
\begin{document}
paragraph text
\section{This is the title}
paragraph text
\end{document}
\parbox[][30pt][]
似乎指定了框的高度,但设置此项会抹去文本,从而消除宽度,我希望宽度为整页。我需要编辑 parbox 还是其他内容?
答案1
不太清楚为什么它会起作用,但确实如此......
\documentclass[a4paper]{article}
\usepackage{xcolor,lipsum}
\usepackage{titlesec}
\titleformat{name=\section}[block]
{\sffamily\LARGE\color{white}}
{}
{} % distance from left hand side
{\colorsection}
\titlespacing*{\section}
{} % distance from the left
{\baselineskip}
{\baselineskip}
\newcommand{\colorsection}[1]{%
\colorbox{rgb:red,6;green,53;blue,50}
{\parbox[][30pt][t]
{\dimexpr\textwidth + 50pt \fboxsep}
{\thesection\ #1}}
\colorbox{rgb:red,00;green,160;blue,110}
{\parbox[][100pt][t]
{\dimexpr\textwidth + 50pt \fboxsep}
{\ #}}
}
\begin{document}
paragraph text
\section{This is the title}
paragraph text
\end{document}