我想让 tikz 图片在特定页面样式的每一页上重复出现,但章节标题页除外。编译 MWE 时,我只在章节标题页面上看到图片,其他地方都看不到。我还想从章节的第一页省略章节标题。
\documentclass[12pt, oneside,headsepline=true,chapterprefix=false,headings=optiontohead,toc=indentunnumbered, usegeometry]{scrreprt}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{tikz}
%%%---header/footer
\usepackage[
automark,
autooneside=false,% <- needed if you want to use \leftmark and \rightmark in a onesided document
headsepline
]{scrlayer-scrpage}
\newpairofpagestyles{MyIntro}{%
\clearpairofpagestyles%
\ohead*{\ifstr{\leftmark}{\rightbotmark}{}{\rightbotmark}}{%
\begin{tikzpicture}[remember picture,overlay]
\node[rectangle, minimum width=0.12\paperheight, minimum height=1.3cm, fill=gray!50, text=white, font=\fontsize{14}{14}\bfseries, xshift=-.55cm,yshift=-5cm,rotate=90] at (current page.north east){\makebox[0pt][c]{\hspace{0cm} Introduction}};
\end{tikzpicture}
}
\ofoot*{\pagemark}
}
\usepackage{lipsum}
\begin{document}
\thispagestyle{empty}
\tableofcontents
\chapter{Introduction}
\pagestyle{MyIntro}
\section{The First Section}
\lipsum[1-3]
\section{The Second Section}
\lipsum[4-12]
\end{document}
答案1
目前您正在tikzpicture
将选择页面样式。要使其成为页面样式的一部分,可以使用等添加它,\ohead
或者定义一个新层并将此新层添加到页面样式中。此外,我不建议\pagemark
在普通样式中添加任何标记(但),因为它提到普通样式用于没有运行头的页面。所以我得到,例如:
\documentclass[12pt, oneside,headsepline=true,chapterprefix=false,headings=optiontohead,toc=indentunnumbered, usegeometry]{scrreprt}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{tikz}
%%%---header/footer
\usepackage[
automark,
autooneside=false,% <- needed if you want to use \leftmark and \rightmark in a onesided document
headsepline
]{scrlayer-scrpage}
\newpairofpagestyles{MyIntro}{%
\clearpairofpagestyles
\ohead{%
\Ifstr{\leftmark}{\rightbotmark}{}{\rightbotmark}%
\begin{tikzpicture}[remember picture,overlay]
\node[rectangle, minimum width=0.12\paperheight, minimum height=1.3cm,
fill=gray!50, text=white, font=\fontsize{14}{14}\bfseries,
xshift=-.55cm,yshift=-5cm,rotate=90] at (current page.north
east){\makebox[0pt][c]{\hspace{0cm} Introduction }};
\end{tikzpicture}
}%
\ofoot*{\pagemark}%
}
\pagestyle{MyIntro}
\usepackage{lipsum}
\begin{document}
\thispagestyle{empty}
\tableofcontents
\chapter{Introduction}
\pagestyle{MyIntro}
\section{The First Section}
\lipsum[1-3]
\section{The Second Section}
\lipsum[4-12]
\end{document}
顺便说一句:选项oneside
和chapterprefix=false
是默认的scrreprt
。仅当您加载包时选项usegeometry
才有意义geometry
。
另一个建议是,对章节缩略图的文本也使用 LaTeX 标记机制,例如,使用记录中的新命令ltmarks-doc.pdf
(在每个提供这些命令的 LaTeX 发行版中都可用):
\documentclass[12pt, oneside,headsepline=true,chapterprefix=false,headings=optiontohead,toc=indentunnumbered, usegeometry]{scrreprt}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{tikz}
%%%---header/footer
\usepackage[
automark,
autooneside=false,% <- needed if you want to use \leftmark and \rightmark in a onesided document
headsepline
]{scrlayer-scrpage}
\NewMarkClass{chaptername}
\newpairofpagestyles{MyIntro}{%
\clearpairofpagestyles
\ohead{%
\Ifstr{\leftmark}{\rightbotmark}{}{\rightbotmark}%
\begin{tikzpicture}[remember picture,overlay]
\node[rectangle, minimum width=0.12\paperheight, minimum height=1.3cm,
fill=gray!50, text=white, font=\fontsize{14}{14}\bfseries,
xshift=-.55cm,yshift=-5cm,rotate=90] at (current page.north
east){\FirstMark{chaptername}};
\end{tikzpicture}
}%
\ofoot*{\pagemark}%
}
\usepackage{xpatch}
\xapptocmd{\chaptermark}{\InsertMark{chaptername}{#1}}{}{}
\pagestyle{MyIntro}
\usepackage{lipsum}
\begin{document}
\thispagestyle{empty}
\tableofcontents
\chapter{Introduction}
\pagestyle{MyIntro}
\section{The First Section}
\lipsum[1-3]
\section{The Second Section}
\lipsum[4-12]
\end{document}
顺便说一句:目前,定义一对新的页面样式而不是使用预定义的一对scrheadings
和是没有意义的plain.scrheadings
。但是,也许在你的实际文档中,这是有意义的。所以我没有改变这一点。