在设计杂志版面时,我尝试在页面外边距添加一些章节标记。由于每个章节都以自己的双页开始,但有时在左侧,有时在右侧,因此我希望这些标记在两页上均等显示(一个双页 = 一个标记)。
为了说明问题:
在这张图片中,您可以看到两个部分。我希望将“序言”也放在图像页面的相同位置,并将第二部分“某些内容”也放在部分页面。
重点是:如何在开始该章节之前获取章节标题?
如果有帮助,我会使用 LuaLaTeX,所以 Lua 解决方案也可以。
\documentclass[12pt,a5paper,DIV=calc,BCOR=5mm,twoside,titlepage]{scrartcl}
%% packages
\usepackage{graphicx}
\usepackage{ifthen}
\usepackage{xparse}
%% do the layout stuff
\usepackage[most]{tcolorbox}
\usepackage{scrlayer-scrpage}
\usepackage{marginnote}
%% pagestyles
\newtcolorbox{markbox}[1][]{rotate=90,text width=4cm,halign=center,beamer,#1}
\setlength{\marginparsep}{1cm}
\newlength{\twocentimetre}
\deftriplepagestyle{mypage}[0pt][0pt]%
{}{}{}%
{
\ifthispageodd{
\ifthenelse{\equal{\headmark}{}}{}{
\marginnote{
\setlength{\twocentimetre}{2cm}
\multiply\twocentimetre by \value{section}
\vspace*{\dimexpr-5cm-\twocentimetre}\begin{markbox}
\headmark\vspace*{.5cm}
\end{markbox}
}
}
}{}
}{Title here}{\pagemark}
\pagestyle{mypage}
%% KOMA customization
\setkomafont{pageheadfoot}{\footnotesize}
\setkomafont{section}{\dothesection}
\newtcolorbox{sectionbox}{sharp corners=north,height=2cm,valign=bottom,halign=center,spread upwards}
\def\dothesection#1{
\clearpage\begin{sectionbox}\huge #1\end{sectionbox}
}
%% own environments/commands
\NewDocumentEnvironment{picpage}{}{\clearpage\thispagestyle{mypage}}{\clearpage}
\NewDocumentCommand{\startsection}{s m}{
\IfBooleanTF{#1}{\section*{#2}}{\section{#2}}
\markboth{#2}{#2}
}
\NewDocumentCommand{\startsubsection}{s m}{
\IfBooleanTF{#1}{\subsection*{#2}}{\subsection{#2}}
}
\begin{document}
\begin{titlepage}
\setcounter{page}{-1}
\vspace*{\fill}
\begin{tcolorbox}[spread sidewards=-1cm]
\Huge\sffamily\bfseries Some title\\[.5em]
\Large Some subtitle
\end{tcolorbox}
\vfill
\end{titlepage}
\begin{picpage}
\thispagestyle{empty}
\includegraphics{example-image.pdf}
\end{picpage}
\startsection*{Table of contents}
\vspace*{\fill}
\begin{tcolorbox}[colback=white]
\makeatletter
\@starttoc{toc}
\makeatother
\end{tcolorbox}
\vfill
\begin{picpage}
\includegraphics{example-image.pdf}
\end{picpage}
\startsection{Preface}
Quack
\startsection{Something}
Test
\begin{picpage}
\includegraphics{example-image.pdf}
\end{picpage}
\thispagestyle{empty}
Back
\end{document}
更新:根据 David Carlisle 的建议,我将代码变成了节启动环境,以启用这些图片页面。现在还有一些其他问题:
- 我现在有两个环境来开始一个部分(左/右),每个环境都有一个“带星号”的版本。我真的不喜欢这种方法,因为在我看来它不是很舒服,而且没有提供真正的逻辑结构。
- 左侧图像页面的 y 轴偏移是错误的。这当然是合乎逻辑的,因为此时节计数器尚未增加。
有没有不那么繁琐的解决方案?
新代码:
\documentclass[12pt,a5paper,DIV=calc,BCOR=5mm,twoside,titlepage]{scrartcl}
%% packages
\usepackage{graphicx}
\usepackage{ifthen}
\usepackage{xparse}
%% do the layout stuff
\usepackage[most]{tcolorbox}
\usepackage{scrlayer-scrpage}
\usepackage{marginnote}
%% pagestyles
\newtcolorbox{markbox}[1][]{rotate=90,text width=4cm,halign=center,beamer,#1}
\setlength{\marginparsep}{1cm}
\newlength{\twocentimetre}
\deftriplepagestyle{mypage}[0pt][0pt]%
{}{}{}%
{
% \ifthispageodd{
\ifthenelse{\equal{\headmark}{}}{}{
\marginnote{
\setlength{\twocentimetre}{2cm}
\multiply\twocentimetre by \value{section}
\vspace*{\dimexpr-5cm-\twocentimetre}\begin{markbox}
\headmark\vspace*{.5cm}
\end{markbox}
}
}
% }{}
}{Title here}{\pagemark}
\pagestyle{mypage}
%% KOMA customization
\setkomafont{pageheadfoot}{\footnotesize}
\setkomafont{section}{\dothesection}
\newtcolorbox{sectionbox}{sharp corners=north,height=2cm,valign=bottom,halign=center,spread upwards}
\def\dothesection#1{
\clearpage\begin{sectionbox}\huge #1\end{sectionbox}
}
%% own environments/commands
\NewDocumentEnvironment{picpage}{}{\clearpage\thispagestyle{mypage}}{\clearpage}
\NewDocumentEnvironment{startleftsection}{s m}{
\IfBooleanTF{#1}{\section*{#2}}{\section{#2}}
\markboth{#2}{#2}
\begin{picpage}
}{
\end{picpage}
}
\NewDocumentEnvironment{startrightsection}{s m}{
\markboth{#2}{#2}
\begin{picpage}
}{
\end{picpage}
\IfBooleanTF{#1}{\section*{#2}}{\section{#2}}
}
\NewDocumentCommand{\startsubsection}{s m}{
\IfBooleanTF{#1}{\subsection*{#2}}{\subsection{#2}}
}
\begin{document}
\begin{titlepage}
\setcounter{page}{-1}
\vspace*{\fill}
\begin{tcolorbox}[spread sidewards=-1cm]
\Huge\sffamily\bfseries Some title\\[.5em]
\Large Some subtitle
\end{tcolorbox}
\vfill
\end{titlepage}
\begin{startrightsection}*{Table of contents}
\thispagestyle{empty}
\includegraphics{example-image.pdf}
\end{startrightsection}
\vspace*{\fill}
\begin{tcolorbox}[colback=white]
\makeatletter
\@starttoc{toc}
\makeatother
\end{tcolorbox}
\vfill
\begin{startrightsection}{Preface}
\includegraphics{example-image.pdf}
\end{startrightsection}
Quack
\begin{startleftsection}{Something}
\includegraphics{example-image.pdf}
\end{startleftsection}
Quack
\thispagestyle{empty}
Back
\end{document}
答案1
\chapter
另外,你可以扩展(or )可选参数的可选键值语法。可以使用or\section
放置侧边标记:scrlayer
scrlayer-scrpage
\documentclass[12pt,a5paper,DIV=calc,BCOR=5mm,twoside,%
headings=optiontotocandhead,open=left]{scrreprt}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}
\usepackage{scrlayer-scrpage}
\automark[chapter]{chapter}
\usepackage{afterpage}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-\dimexpr 1in+\topmargin+\headheight+\headsep}}
\makeatletter
\newtcolorbox{markbox}[1][]{rotate=90,text width=4cm,halign=center,beamer,#1}
\newtcolorbox{sectionbox}{sharp
corners=north,height=2cm,valign=bottom,halign=center,spread upwards*}
\FamilyBoolKey[.section]{KOMAarg}{titleleft}{@titleleft}
\@titlelefttrue
\DefineFamilyKey[.section]{KOMAarg}{imagecode}{%
\long\def\chapter@imagecode{#1}%
\FamilyKeyStateProcessed
}
\newcounter{abschapter}
\newlength{\chaptermarkoffset}
\renewcommand*{\chapterlinesformat}[3]{%
% calculate new vertical position of the marks
\stepcounter{abschapter}%
\global\chaptermarkoffset\dimexpr 2cm*\value{abschapter}+5cm\relax
% restart vertical position of the marks, if lowest position has been reached
\ifdim\chaptermarkoffset>\dimexpr \paperheight-4cm\relax
\setcounter{abschapter}{1}%
\global\chaptermarkoffset\dimexpr 2cm*\value{abschapter}+5cm\relax
\fi
\if@titleleft
\typeout{TRACE: Title left \thechapter}%
\ifx\chapter@imagecode\@empty\else
\afterpage{%
\thispagestyle{plain.scrheadings}
\chapter@imagecode\clearpage\global\let\chapter@imagecode\@empty%
}%
\fi
\else
\typeout{TRACE: Title right \thechapter}%
\chapter@imagecode
\cleardoubleoddpage
\thispagestyle{plain.scrheadings}%
\global\let\chapter@imagecode\@empty
\fi
\begin{sectionbox}
\@hangfrom{#2}{#3}%
\end{sectionbox}
\global\@titlelefttrue
}
\renewcommand*{\chapterheadstartvskip}{}
\newcommand*{\chapter@imagecode}{}
\deftocheading{toc}{%
\def\chapter@imagecode{\includegraphics{example-image}}
\@titleleftfalse
\@mkdouble{#1}%
\chapter*{#1}%
}
\DeclareNewLayer[background,oddpage,rightmargin,
contents={\hspace*{\fill}%
\raisebox{\dimexpr \depth-\chaptermarkoffset\relax}{%
\begin{markbox}\rightmark\end{markbox}}}
]{oddmarginnote}
\DeclareNewLayer[background,evenpage,leftmargin,
contents={%
\raisebox{\dimexpr \depth-\chaptermarkoffset\relax}{%
\begin{markbox}[rotate=180]\rightmark\end{markbox}}}
]{evenmarginnote}
\AddLayersToPageStyle{plain.scrheadings}{oddmarginnote,evenmarginnote}
\makeatother
\usepackage{mwe}
\begin{document}
\thispagestyle{empty}
\vspace*{\fill}
\begin{tcolorbox}[spread sidewards=-1cm]
\Huge\sffamily\bfseries Some title\\[.5em]
\Large Some subtitle
\end{tcolorbox}
\vfill
\tableofcontents
\blinddocument
\chapter[titleleft=true,imagecode={\includegraphics{example-image-a}},head={title
left}]{Testchapter with title left}
\Blindtext[10]
\chapter[titleleft=false,imagecode={\includegraphics{example-image-b}},head={title
right}]{Testchapter with title right}
\Blindtext[10]
\chapter[titleleft=true,imagecode={\includegraphics{example-image-c}}]{Left
manual break}
This is the text for the left page.
\clearpage
\Blindtext[10]
\chapter[titleleft=false,imagecode={\includegraphics{example-image}}]{First more}
\chapter[titleleft=false,imagecode={\includegraphics{example-image}}]{Second more}
\addchap[titleleft=false,imagecode={\includegraphics{example-image}},tocentry={}]{Not
numbered no ToC entry}
\end{document}
目录显示了未编号的章节,左侧有图片:
第 2 章演示了带有编号的章节,其中文本在左侧(自动分页到下一页):
第 3 章演示了一个编号章节,左边是图像,右边是文本:
但也支持没有图片的章节:
那么没有编号的章节怎么办?最简单的解决方案是使用\addchap
而不是\chapter*
。要避免进入目录,只需使用选项tocentry={}
。如果章节太多,侧面标记会移到页面外面,会发生什么?这不会发生。abschapter
将自动重置为 1,标记将从最顶部位置重新开始:
您可以针对这种情况添加额外的代码,例如,更改侧面标记的颜色或发出警告。
在示例中,我plain.scrheadings
通过新层扩展了页面样式。或者,您可以仅为章节标题页定义新层页面样式。您也可以根据scrheadings
需要扩展页面样式。并且您仍然可以使用等来配置和\ihead
的页眉和页脚。plain.scrheadings
scrheadings