我试图为章节标题添加一个浅灰色的框来包裹文本。但是,出于某种原因,当我添加 titlesec 包(我用它来格式化章节标题)时,它改变了我放置在文本周围的 fcolorbox 的粗细。
原件(正常厚度):
\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}
包含 titlesec 的那个:
\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}
我怎样才能让它保持原来更窄的灰色盒子?
答案1
不要titlesec
与 KOMA-Script 类一起使用。以下是重新定义 KOMA-Script 命令的建议\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}