节标题格式

节标题格式

我目前正在尝试自定义我的部分的样式,我唯一无法做到的就是用灰色填充数字 1 下方的白色空间和它下面的长灰色规则

例子

这是我在背面的代码

\documentclass[17pt,article]{extarticle}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[table]{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{tabularx}
\usepackage{ctable}
\usepackage[parfill]{parskip}

\titleformat{\section}[block]{\Large\sffamily}%
{}%
{0pt}%
{%
\renewcommand{\arraystretch}{.4}
\begin{tabularx}{\textwidth}{p{60pt}X}
\centering\cellcolor{gray} \vspace{2pt}\bfseries\thesection &\vspace{2pt}\bfseries 
#1\\
\arrayrulecolor{gray}\specialrule{.25em}{-0.1em}{0em}
\end{tabularx}
}
\section[Section Title]{Section 
   Title\\ &\normalsize Lorem ipsum}

谢谢!

答案1

尝试\makecell

\documentclass[17pt,article]{extarticle}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% no more needed since 2018
\usepackage[spanish]{babel}
\usepackage[table]{xcolor}
\usepackage[explicit]{titlesec}
\usepackage{tabularx}
\usepackage{ctable}
\usepackage{makecell}
\usepackage[parfill]{parskip}

\titleformat{\section}[block]{\Large\sffamily}%
{}%
{0pt}%
{%\renewcommand{\arraystretch}{.4}%
\begin{tabularx}{\linewidth}{>{\centering\cellcolor{gray}\bfseries}p{60pt}>{\bfseries}X}
 \rule{0cm}{40pt}\makecell[c]{\thesection\\~} & \makecell[l]{#1}\\[20pt]
\arrayrulecolor{gray}\specialrule{.25em}{-0.1em}{0em}
\end{tabularx}%
}
\begin{document}
\section[Section Title]{Section 
   Title\\{\normalsize Lorem ipsum}}
\end{document}

在此处输入图片描述

相关内容