生成简单标题

生成简单标题

如何使用固定宽度的右规则和行填充的左规则来获得以下结果?

未编号章节标题

答案1

在此处输入图片描述

只需从中获取定义article.cls并添加规则:

\documentclass{article}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\xhrulefill \normalfont\Large\bfseries\zz{2cm}}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\xhrulefill\normalfont\large\bfseries\zz{1.5cm}}}


\newcommand\zz[2]{\mbox{ #2 \makebox[#1]{\xhrulefill}}}
\newcommand\xhrulefill{\noindent\leaders\vrule height5pt depth -4pt \hskip 0pt plus 1fill}
\makeatother

\begin{document}

\tableofcontents

\section{oops}
\subsection{ahhh}
hello
\section{hoops}
\subsection{hahhh}
goodbye
\end{document}

相关内容