我有两个参数,section
以及如何second optional argument
在同一个中打印boxes
。如何增加box
宽度应该达到paperwidth
。
我的 MWE 是:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{xcolor,lipsum,mdframed}
\definecolor{sectcolor}{cmyk}{0,1,.75,.39}
\definecolor{sectbgcolor}{RGB}{0,106,168}
\renewcommand{\thesection}{\thechapter\Alph{section}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\titleformat{\section}
{\fontsize{18}{20}\selectfont\color{white}\bfseries}
{\llap{\smash{\parbox[t]{2em}{\raggedleft%
\colorbox{sectcolor}{%
\makebox[\dimexpr2em-2\fboxsep\relax][r]{%
\hfill\strut\thesection
}%
}\\[1ex]
\includegraphics[width=1.5em]{image1.png}\\[2pt]
\includegraphics[width=1.5em]{image2.png}\\[2pt]
\includegraphics[width=1.5em]{image3.png}\\[2pt]
\includegraphics[width=1.5em]{image4.png}\\
}}\hspace*{0.5em}}%
}
{0em}
{\colorbox{sectbgcolor}{\parbox[t]{\dimexpr\textwidth-2\fboxsep\relax} {\strut#1}}}
\begin{document}
\chapter{Chapter Title Here}
\section{Number systems}{Consolidating}
\lipsum[1-3]
\section{Count systems}
\lipsum[4]
\end{document}
答案1
不要重载标准\section
命令(可以这样做,但我认为这不是一个好主意),我建议您\Ssection
对带有副标题的部分使用新命令(对于没有副标题的部分,您仍然可以使用标准\section
命令):
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{xcolor,lipsum,mdframed}
\definecolor{sectcolor}{cmyk}{0,1,.75,.39}
\definecolor{sectbgcolor}{RGB}{0,106,168}
\definecolor{sectsubbgcolor}{RGB}{0,139,191}
\renewcommand{\thesection}{\thechapter\Alph{section}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\makeatletter
\titleformat{\section}
{\fontsize{18}{20}\selectfont\color{white}\bfseries}
{\llap{\smash{\parbox[t]{2em}{\raggedleft%
\colorbox{sectcolor}{%
\makebox[\dimexpr2em-2\fboxsep\relax][r]{%
\hfill\strut\thesection
}%
}\\[1ex]
\includegraphics[width=1.5em]{image-1}\\[2pt]
\includegraphics[width=1.5em]{image-2}\\[2pt]
\includegraphics[width=1.5em]{image-3}\\[2pt]
\includegraphics[width=1.5em]{image-4}\\
}}\hspace*{0.5em}}%
}
{0em}
{\makebox[\linewidth][l]{\colorbox{sectbgcolor}{\parbox[t]{\dimexpr\paperwidth-\oddsidemargin-1in-2\fboxsep-5pt\relax}{%
\strut#1%
\if\sectionsubtitle\empty
\else
\hspace{5pt}\smash{\colorbox{sectsubbgcolor}{\strut\large\sectionsubtitle}}%
\fi}
}}%
}
\makeatother
\def\sectionsubtitle{\empty}
\newcommand\Ssection[3][]{%
\gdef\sectionsubtitle{#3}\section[#1]{#2}\gdef\sectionsubtitle{\empty}%
}
\begin{document}
\chapter{Chapter Title Here}
\Ssection{Number systems}{Consolidating}
\lipsum[1]
\section{Count systems}
\lipsum[1]
\end{document}
结果: