我想复制此文档布局。我尝试联系作者,但没有得到任何积极回复。
到目前为止,我得到的是页眉。但我的页眉是静态的,我想要一个动态页眉(调整到节边距)。
以下是代码
\documentclass[twoside]{scrbook}
\usepackage[letterpaper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{midnightgreen}{rgb}{0.0, 0.29, 0.33}
\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north west)+(0.25in,-0.35in)$) rectangle ($(current page.north west)+(0.65in,-0.75in)$);
\fill[midnightgreen] ($(current page.north west)+(2.5in,-0.35in)$) rectangle ($(current page.north east)+(-0.6in,-0.75in)$);
\node[anchor=north west, text=white, font=\large\bfseries, minimum size=1in, inner xsep=5mm] at ($(current page.north west)+(-0.1in,-0.05in)$){\thepage};
\node[anchor=north west, text=white, font=\large\bfseries, minimum size=1in] at ($(current page.north west)+(2.6in,-0.075in)$) {\rightmark};
\end{tikzpicture}
}
\fancyhead[CE]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north west)+(0.6in,-0.35in)$) rectangle ($(current page.north east)+(-2.25in,-0.75in)$);
\fill[midnightgreen] ($(current page.north east)+(-0.65in,-0.35in)$) rectangle ($(current page.north east)+(-0.25in,-0.75in)$);
\node[anchor=north west, text=white, font=\large\bfseries, minimum size=1in, inner xsep=5mm] at ($(current page.north east)+(-1in,-0.05in)$){\thepage};
\node[anchor=north west, text=white, font=\large\bfseries, minimum size=1in] at ($(current page.north west)+(0.65in,-0.075in)$) {\leftmark};
\end{tikzpicture}
}
\setlength{\headheight}{12pt}
\title{A reasonably long title}
\date{\today}
\author{The author}
\begin{document}
\maketitle
\chapter[Hola Mundo]{Hola Mundo}
\lipsum[1-9]
\section{La prueba na' ma'}
\chapter[Hola de Nuevo]{Hola Mundo... de Nuevo}
\lipsum[10-19]
\end{document}
答案1
基于@marmot的代码,我添加了一些缺失的部分。请稍后查看MWE。
要重新创建文档所显示的结构,您需要向给定的 MWE 添加一些代码:
添加
\usepackage{multicol}
您的序言,然后添加以下代码以获得两列的目录:\begin{multicols}{2} % <================================================ \tableofcontents % <==================================================== \end{multicols} % <=====================================================
- 我添加了
\maketitle
您的代码以获取文档的标题。 为了能够轻松添加完整的虚拟文档,我将其更改
\usepackage{lipsum}
为\usepackage{blindtext} % <========================== \Blinddocument
记得
\lipsum...
改成\blindtext
...为了在章节页面等上获得所需的标题,您必须定义
\fancypagestyle{plain}{% <==============================================
(参见下面 MWE 中的完整代码)。
- 请参阅我在文本末尾添加的内容
\Blinddocument
,以获得更好填充的目录以显示两列目录。 - 您是否注意到由于使用带有 和 的 KOMA-Script 类而收到的警告
fancyhdr
?titlesec
KOMA-Script 有自己的方法来使用包构建标头scrlayer-scrpage
(请参阅texdoc KOMA-Script
终端/控制台上的 文档)。您应该考虑更改为该包,但这不是这里的问题(如果您无法自己完成,请提出一个新问题并展示您迄今为止尝试过的方法……)。
完整校正后的 MWE:
\documentclass[twoside,letterpaper]{scrbook}
\usepackage[letterpaper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr} % <=========================== better use scrlayer-scrpage
\usepackage{titlesec} % <=========================== see warnings in log file
\usepackage{multicol} % <===============================================
%\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{blindtext} % <========================== \Blinddocument
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{midnightgreen}{rgb}{0.0, 0.29, 0.33}
\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north west)+(0.25in,-0.35in)$) rectangle ($(current page.north west)+(0.65in,-0.75in)$)
node[midway,text=white, font=\large\bfseries] {\thepage};
\fill[midnightgreen] ([yshift=-0.35in]current page.north-|current page text area.west)
coordinate (TL)
rectangle ([yshift=-0.75in]current page.north-|current page text area.east);
\node[anchor=north west, text=white, font=\large\bfseries,text
height=0.2in,inner xsep=1em] at (TL) {\rightmark};
\end{tikzpicture}%
}
\fancyhead[CE]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north east)+(-0.65in,-0.35in)$) rectangle ($(current page.north east)+(-0.25in,-0.75in)$)
node[midway,text=white, font=\large\bfseries] {\thepage};
\fill[midnightgreen] ([yshift=-0.35in]current page.north-|current page text area.west)
coordinate (TL)
rectangle ([yshift=-0.75in]current page.north-|current page text area.east);
\node[anchor=north west, text=white, font=\large\bfseries,text height=0.2in,inner xsep=1em]
at (TL) {\leftmark};
\end{tikzpicture}%
}
\fancypagestyle{plain}{% <==============================================
\fancyhf{}
\fancyhead[CO]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north west)+(0.25in,-0.35in)$) rectangle ($(current page.north west)+(0.65in,-0.75in)$)
node[midway,text=white, font=\large\bfseries] {\thepage};
\fill[midnightgreen] ([yshift=-0.35in]current page.north-|current page text area.west)
coordinate (TL)
rectangle ([yshift=-0.75in]current page.north-|current page text area.east);
\node[anchor=north west, text=white, font=\large\bfseries,text
height=0.2in,inner xsep=1em] at (TL) {\rightmark};
\end{tikzpicture}%
}
\fancyhead[CE]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north east)+(-0.65in,-0.35in)$) rectangle ($(current page.north east)+(-0.25in,-0.75in)$)
node[midway,text=white, font=\large\bfseries] {\thepage};
\fill[midnightgreen] ([yshift=-0.35in]current page.north-|current page text area.west)
coordinate (TL)
rectangle ([yshift=-0.75in]current page.north-|current page text area.east);
\node[anchor=north west, text=white, font=\large\bfseries,text height=0.2in,inner xsep=1em]
at (TL) {\leftmark};
\end{tikzpicture}%
}}
\setlength{\headheight}{14pt}
\title{A reasonably long title}
\date{\today}
\author{The author}
\begin{document}
\maketitle % <==========================================================
\begin{multicols}{2} % <================================================
\tableofcontents % <====================================================
\end{multicols} % <=====================================================
\chapter[Hola Mundo]{Hola Mundo}
\blindtext
\section{La prueba na' ma'}
\chapter[Hola de Nuevo]{Hola Mundo... de Nuevo}
\blindtext
\Blinddocument % <======================================================
\end{document}
及其结果:
以及常见的章节页:
答案2
您tikzpagenodes
可以根据实际页面的宽度进行调整。它有一个节点current page text area
,它是一个覆盖文本区域的矩形。
\documentclass[twoside]{scrbook}
\usepackage[letterpaper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{midnightgreen}{rgb}{0.0, 0.29, 0.33}
\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north west)+(0.25in,-0.35in)$) rectangle ($(current page.north west)+(0.65in,-0.75in)$)
node[midway,text=white, font=\large\bfseries] {\thepage};
\fill[midnightgreen] ([yshift=-0.35in]current page.north-|current page text area.west)
coordinate (TL)
rectangle ([yshift=-0.75in]current page.north-|current page text area.east);
\node[anchor=north west, text=white, font=\large\bfseries,text
height=0.2in,inner xsep=1em] at (TL) {\rightmark};
\end{tikzpicture}%
}
\fancyhead[CE]{%
\begin{tikzpicture}[overlay, remember picture]%
\fill[midnightgreen] ($(current page.north east)+(-0.65in,-0.35in)$) rectangle ($(current page.north east)+(-0.25in,-0.75in)$)
node[midway,text=white, font=\large\bfseries] {\thepage};
\fill[midnightgreen] ([yshift=-0.35in]current page.north-|current page text area.west)
coordinate (TL)
rectangle ([yshift=-0.75in]current page.north-|current page text area.east);
\node[anchor=north west, text=white, font=\large\bfseries,text height=0.2in,inner xsep=1em]
at (TL) {\leftmark};
\end{tikzpicture}%
}
\setlength{\headheight}{12pt}
\title{A reasonably long title}
\date{\today}
\author{The author}
\begin{document}
\maketitle
\chapter[Hola Mundo]{Hola Mundo}
\lipsum[1-9]
\section{La prueba na' ma'}
\chapter[Hola de Nuevo]{Hola Mundo\dots\space de Nuevo}
\lipsum[10-29]
\end{document}