偶数页和奇数页的章节设计

偶数页和奇数页的章节设计

如何才能显示\section从页面一侧开始的彩色背景(奇数页 = 左侧,偶数页 = 右侧),如下图所示。

在此处输入图片描述

编辑

从此代码中:

\documentclass{book}

\usepackage{xcolor}
\usepackage{titlesec}
\definecolor{mygreen}{RGB}{204,226,158}

\titleformat{\section}[hang]{\scshape\Large{\rlap{\color{mygreen}\rule[-2.3ex]{\linewidth}{6ex}\vspace{-4.5ex}}}}{\thesection}{1em}{}

\usepackage[a4paper,
            inner=20mm,
            outer=60mm,
            top=25mm,
            bottom=25mm,
            marginparsep=5mm,
            marginparwidth=50mm,
            headsep =35pt,
            ]{geometry}

\usepackage{showframe}

\begin{document}

\section{Introduction}

\end{document}

答案1

看起来这可行:

\documentclass{book}

\usepackage{xcolor}
\usepackage{titlesec}
\definecolor{mygreen}{RGB}{204,226,158}
\usepackage{ifthen}
\usepackage[a4paper,
            inner=20mm,
            outer=60mm,
            top=25mm,
            bottom=25mm,
            marginparsep=5mm,
            marginparwidth=50mm,
            headsep =35pt,
            ]{geometry}

\newlength\lineAndMargin
\setlength{\lineAndMargin}{\linewidth}
\addtolength{\lineAndMargin}{2.9cm} % not sure why this value

\titleformat{\section}[block]
{\scshape\Large
\makebox[0pt][l]{\color{mygreen}%
\ifthenelse{\isodd{\thepage}}{\hspace{-2cm}}{}%
\rule[-2.3ex]{\lineAndMargin}{6ex}}}
{\thesection} % label
{1em} % sep
{} % before code

\usepackage{showframe}

\begin{document}

\section{Introduction}

Section content

\clearpage

\section{Conclusion}

Section content

\end{document}

奇数页输出 ... 偶数页输出 请注意,这使用了条件\isodd{\thepage},这不一定是最好的主意。如果你发现你的标题表现得像在另一页上,你需要解决如果则否则奇数页/偶数页

相关内容