0

The code

\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}  

gives me this output:

enter image description here

but I want the frame to be fullwidth like the following. How can I do this?

enter image description here

2

This quick change makes the trick:

Just replace

\hbox to \hsize{%
\colorbox{yellow}{%
\hbox to 1cm{\hss\bfseries\Large\thesection \ \ }%

with

\hspace{-4cm}
\hbox to \hsize{%
\colorbox{yellow}{%
\hbox to 5cm{\hss\bfseries\Large\thesection \ \ }%

Probably not the most elegant solution, but it works!

Example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.