我需要设计一个如下所示的部分:
奇数页和偶数页都遵循此规则。到目前为止,我已经这样做了:
\documentclass{tufte-book}
\usepackage{xcolor} % for colour
\usepackage{lipsum} % just for sample text
\setcounter{secnumdepth}{2}
% section format
\titleformat{\section}%
{\normalfont\Large\itshape\color{orange}}% format applied to label+text
{\llap{\colorbox{orange}{\parbox{1.5cm}{\hfill\color{white}\thesection}}}}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\begin{document}
\chapter{Chapter}
\lipsum[1]
\section{Section}
\lipsum[1]
\subsection{Sub section}
\lipsum[1]
\end{document}
但它需要一些编辑。
答案1
这是一个解决方案,仅适用于单行部分标题:
\documentclass{tufte-book}
\geometry{showframe, twoside}
\usepackage{xcolor} % for colour
\usepackage{lipsum} % just for sample text
\AtBeginDocument{\PassOptionsToPackage{explicit, calcwidth, pagestyles}{titlesec}}
\setcounter{secnumdepth}{2}
%
\usepackage{etoolbox}
\newlength\outermargin
\newlength\innermargin
\setlength{\innermargin}{1in}
\setlength{\outermargin}{\dimexpr\paperwidth-\textwidth-\innermargin\relax}
\titleformat{\section}%
{\normalfont\Large\itshape\color{orange}\setlength\fboxrule{0.8pt}}% format applied to label+text
{\llap{\colorbox{orange}{\makebox[\outermargin][r]{\raisebox{0pt}[\dimexpr\height+\fboxrule][\dimexpr\depth+\fboxrule]%
{\vphantom{lp}\color{white}\bfseries\thesection\enspace}}}}}% label
{0pt}% horizontal separation between label and title body
{\rlap{\hspace{-\fboxrule}\framebox[\dimexpr\linewidth + 2\fboxrule\relax][l]{\vphantom{lp}}\colorbox{orange}{\makebox[\outermargin][r]{\raisebox{0pt}[\dimexpr\height+\fboxrule][\dimexpr\depth+\fboxrule]%
{\vphantom{lp}}}}}\hspace{1cm}}% before the title body
[]
\begin{document}
\chapter{Chapter}
\lipsum[1]
\section{Section}
\lipsum[1]
\subsection{Sub section}
\lipsum[1]
\section{Another section}
\end{document}