0

I am trying to give my section headings a light grey box around the text. However, for some reason, when I add the titlesec package (which I am using to format chapter titles) it changes the thickness of the fcolorbox I placed around the text.

The Original (with normal thickness):

\documentclass[12pt]{scrbook}

\usepackage{graphicx}
\usepackage[pages=some]{background}

\begin{document}
\fcolorbox{gray!45}{gray!45}{\section*{{\small {\textsf{\bfseries{CHICKADEE IN THE NIGHT}}}}\hspace{1mm} {\small{| \hspace{1mm} 
\scalebox{.8}[1.0]{
\texttt{FEBRUARY 20, 1980~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}}}}}}
\\
\end{document}

The one with titlesec included:

\documentclass[12pt]{scrbook}

\usepackage{graphicx}
\usepackage[pages=some]{background}
\usepackage{titlesec}
\begin{document}
\fcolorbox{gray!45}{gray!45}{\section*{{\small {\textsf{\bfseries{CHICKADEE IN THE NIGHT}}}}\hspace{1mm} {\small{| \hspace{1mm} 
\scalebox{.8}[1.0]{
\texttt{FEBRUARY 20, 1980~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}}}}}}
\\
\end{document}

How can I get it to maintain the original, much narrower, grey box?

4
  • 1
    First of all, remove all the errors, then the answer may be possible.
    – egreg
    Commented Jul 20, 2016 at 23:14
  • And if you want boxed titles, use titlesec to to do the boxing. Don't put the \section command inside a box.
    – Alan Munn
    Commented Jul 21, 2016 at 0:15
  • See How does one change the frame size and colors in the frame option of titlesec as in MWE? (which is probably a duplicate, if you are really asking how to make boxed section titles.)
    – Alan Munn
    Commented Jul 21, 2016 at 0:27
  • And note that using titlesec will break functionality provided by KOMA.
    – cfr
    Commented Jul 21, 2016 at 0:45

1 Answer 1

2

Do not use titlesec with a KOMA-Script class. Here is a suggestion redefining the KOMA-Script command \sectionlinesformat:

\documentclass[12pt]{scrbook}
\usepackage{graphicx}
\usepackage{xcolor}
\colorlet{sectionbgcolor}{gray!45}
\colorlet{sectionbordercolor}{orange}

\addtokomafont{section}{\small}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{section}
    {\fcolorbox{sectionbordercolor}{sectionbgcolor}{%
      \parbox{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}{%
        \raggedsection\@hangfrom{\hskip #2#3}{#4}}}}
    {\@hangfrom{\hskip #2#3}{#4}}%
}
\makeatother

\newcommand\sectionaddition[1]{%
  \scalebox{.8}[1.0]{\texttt{#1}}%
}

\begin{document}
\addsec*{CHICKADEE IN THE NIGHT ~|~\sectionaddition{FEBRUARY 20, 1980}}
\end{document}

enter image description here

3
  • The problem with that is that I am relying on titlesec to make my chapter headings, I just cut all that out to simplify the example.
    – Richard
    Commented Jul 21, 2016 at 16:08
  • I'm also not attached to scrbook in any way (in this project it looks the same as book), but the same problem occurs.
    – Richard
    Commented Jul 21, 2016 at 16:09
  • Alright, I figured it out after you pointed me in the right direction.
    – Richard
    Commented Jul 21, 2016 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .