我正在尝试设计一个自定义部分。我希望部分将是这样的:
但我无法得到准确的结果。这就是我尝试的:
水平线将连接到节号框的底部。节号框宽度将为 60pt,并且是固定的。您能否帮助我获得我想要的结果。如果您有任何更简单和标准的解决方案,您也可以从头开始。
我的代码片段:
\renewcommand*\thesection{\arabic{section}}
\usepackage[explicit]{titlesec}
\definecolor{myBlue}{HTML}{0088FF}
\titleformat{\section}[block]{\Large\bfseries\sffamily}%
{}%
{0pt}%
{%
\begin{minipage}[c]{60pt}{%
\colorbox{myBlue}{%
\parbox[b][15pt][t]{60pt}{% height, width
\vfill%
\fontfamily{phv}\selectfont\centering\color{white}{\thesection}
\vfill%
}}}%
\end{minipage}%
\hspace{15pt}%
\begin{minipage}[t]{\dimexpr\textwidth-75pt}
\vspace*{-10pt}%
\color{myBlue}{\Large #1}
\end{minipage}\\%
\color{myBlue}{\rule{\textwidth}{1.2pt}}
%
}
\titlespacing*{\section}{0pt}{3mm}{-5mm}
答案1
我会让你弄清楚问题的颜色/尺寸部分,但更简单的解决方案是这样的:
\usepackage[table]{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{tabularx}
\usepackage{ctable}
\titleformat{\section}[block]{\Large\bfseries\sffamily}%
{}%
{0pt}%
{%
\renewcommand{\arraystretch}{1.5}
\begin{tabularx}{\textwidth}{p{60pt}X}
\centering\cellcolor{blue!25} \thesection & #1\\
\arrayrulecolor{blue!25}\specialrule{.25em}{-0.1em}{0em}
\end{tabularx}
%
}
答案2
以下是您需要的更简单的代码:
\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor}
\renewcommand*\thesection{\arabic{section}}
\usepackage[explicit]{titlesec}
\definecolor{myBlue}{HTML}{0088FF}
\titleformat{\section}[hang]{\Large\bfseries\sffamily}%
{\rlap{\color{myBlue}\rule[-6pt]{\textwidth}{1.2pt}}\colorbox{myBlue}{%
\raisebox{0pt}[13pt][3pt]{ \makebox[60pt]{% height, width
\fontfamily{phv}\selectfont\color{white}{\thesection}}
}}}%
{15pt}%
{ \color{myBlue}#1
%
}
\titlespacing*{\section}{0pt}{3mm}{5mm}
\begin{document}
\section{heading on level 1 (section)}
\lipsum[1]
\end{document}