![生成简单标题](https://linux22.com/image/279368/%E7%94%9F%E6%88%90%E7%AE%80%E5%8D%95%E6%A0%87%E9%A2%98.png)
如何使用固定宽度的右规则和行填充的左规则来获得以下结果?
答案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}