bstex wrote:Unfortunately, this code doesn't work.
It worked in my code when I tried it with that template.
bstex wrote:Is it possible to use the \colorbox code inside these lines?
Code: Select all
\renewcommand{\section}{\@startsection{section}{1}{\z@}
{-4ex \@plus -1ex \@minus -.4ex}
{1ex \@plus.2ex }
{\normalfont\large\sffamily\bfseries}}
I have already tried to insert the \colorbox code inside these lines, but nothing worked. Maybe I don't use it correctly.
This is the exact part of the code which refers to the Sections' names of my book. I know that, because when I change the last line, my Sections' names change.
It's not possible, since
\@startsection
implicitly uses more parameters that are not provided here. You see,
\renewcommand{\section}
is not followed by an argument number, like it commonly has to be. One would expect it like
\renewcommand{\section}[1]{..}
for 1 argument or
\renewcommand{\section}[2]...
for 2 arguments, remember the optional
\section
argument. So, the arguments a picked up by the last macro within
\@startsection
, and that's the internal macro
\@sect
that I patched above. It's like changing this:
Code: Select all
\def\@sect#1#2#3#4#5#6[#7]#8{%
\ifnum #2>\c@secnumdepth
\let\@svsec\@empty
\else
\refstepcounter{#1}%
\protected@edef\@svsec{\@seccntformat{#1}\relax}%
\fi
\@tempskipa #5\relax
\ifdim \@tempskipa>\z@
\begingroup
#6{%
\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M #8\@@par}%
\endgroup
\csname #1mark\endcsname{#7}%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
\else
\def\@svsechd{%
#6{\hskip #3\relax
\@svsec #8}%
\csname #1mark\endcsname{#7}%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}}%
\fi
\@xsect{#5}}
to this:
Code: Select all
\def\@sect#1#2#3#4#5#6[#7]#8{%
\ifnum #2>\c@secnumdepth
\let\@svsec\@empty
\else
\refstepcounter{#1}%
\protected@edef\@svsec{\@seccntformat{#1}\relax}%
\fi
\@tempskipa #5\relax
\ifdim \@tempskipa>\z@
\begingroup
#6{%
\@hangfrom{\hskip #3\relax\@svsec}%
\interlinepenalty \@M \colorbox{red}{#8}\@@par}%
\endgroup
\csname #1mark\endcsname{#7}%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
\else
\def\@svsechd{%
#6{\hskip #3\relax
\@svsec \colorbox{red}{#8}}%
\csname #1mark\endcsname{#7}%
\addcontentsline{toc}{#1}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}}%
\fi
\@xsect{#5}}
My small patch above applied
\colorbox
to the argument
#8
that is the section title. #7 is the optional title that goes to the table of contents.
And now you say it doesn't work.

Well, provide details: error message, warning, output error or does simply nothing happen, perhaps with a minimal example.
Stefan