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?

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

  • 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 Jul 21 '16 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 Jul 21 '16 at 16:09
  • Alright, I figured it out after you pointed me in the right direction. – Richard Jul 21 '16 at 17:18

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.