代码
\documentclass{book}
\usepackage{lipsum,xcolor}
\makeatletter
\def\section{\@ifstar\unnumberedsection\numberedsection}
\def\numberedsection{\@ifnextchar[%]
\numberedsectionwithtwoarguments\numberedsectionwithoneargument}
\def\unnumberedsection{\@ifnextchar[%]
\unnumberedsectionwithtwoarguments\unnumberedsectionwithoneargument}
\def\numberedsectionwithoneargument#1{\numberedsectionwithtwoarguments[#1]{#1}}
\def\unnumberedsectionwithoneargument#1{\unnumberedsectionwithtwoarguments[#1]{#1}}
\def\numberedsectionwithtwoarguments[#1]#2{%
\setlength{\fboxsep}{10pt}
\ifhmode\par\fi
%\removelastskip
\vskip 3ex\goodbreak
\refstepcounter{section}%
\hbox to \hsize{%
\colorbox{yellow}{%
\hbox to 1cm{\hss\bfseries\Large\thesection \ \ }%
\vtop{%
\advance \hsize by 8cm
\advance \hsize by -2\fboxrule
\advance \hsize by 2\fboxsep
\parindent=0pt
\leavevmode\raggedright\bfseries\Large
\strut\strut \linespread{1.4}\selectfont#2
\noindent
}%
}
}\nobreak
\vskip 5mm\nobreak
\addcontentsline{toc}{section}{%
\hspace*{1mm}\protect\numberline{\thesection}%
#1}%
\noindent
\sectionmark{#1}%
\ignorespaces%
}
\makeatother
\begin{document}
\chapter{A Test}
\section{A Test}
\lipsum[1-4]
\end{document}
给出了这个输出:
但我希望框架像下面这样全宽。我该怎么做?