我正在尝试实现\headrule
页码下方的短暂淡入淡出。但我不知道如何在偶数/奇数页上“翻转”它。有人知道如何做到这一点吗?
我还收到一条警告,说headheight
太小了。这是由 引起的tikzpicture
,但我该如何修复它?我不想将 增加headheight
那么多...
\documentclass[11pt, titlepage, openright]{book}
\usepackage[textwidth=13cm, left=2.5cm, bottom=2cm, top=2.5cm, paperwidth=20cm, paperheight=27cm, layoutwidth=19cm, layoutheight=26cm, layouthoffset=0.5cm, layoutvoffset=0.5cm, showcrop, asymmetric]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{}
\fancyfoot{}
\definecolor{grey}{rgb}{0.6,0.6,0.6}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
\setlength{\headheight}{24pt}
\fancyhead[RO]{\sffamily\bfseries\textcolor{grey}\leftmark\hspace{0.3cm}\sffamily\textcolor{darkgrey}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgrey}\thepage\hspace{0.3cm}\sffamily\textcolor{grey}\leftmark}
\renewcommand{\headrulewidth}{0.6pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrule}{
\begin{tikzpicture}
\shade[white] (0,0) rectangle (8,0);
\shade[left color=white, right color=black, dashed] (8,1) rectangle (12.98,1.01);
\end{tikzpicture}}
\begin{document}
\chapter{Test chapter}
\lipsum
\lipsum
\end{document}
答案1
\count0
在标准 LaTeX 中,左/右标题的检查是根据via的值执行的\ifodd
。您可以在\headrule
命令中使用它来在两个页面上设置不同的图片。
headheight
在您的规范中添加选项geometry
将提供更多空间。使用日志文件中报告的值。
但是,您在问题中说您不想这样做。标题太高的原因是您试图通过在高度处绘制空白0
并在高度处绘制规则来将其向上移动1
。更简单的方法是绘制规则并使用一些垂直跳跃确保其正确定位。
\documentclass[11pt, titlepage, openright]{book}
\usepackage[textwidth=13cm, left=2.5cm, bottom=2cm, top=2.5cm,
paperwidth=20cm, paperheight=27cm, layoutwidth=19cm,
layoutheight=26cm, layouthoffset=0.5cm, layoutvoffset=0.5cm,
showcrop, asymmetric]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{}
\fancyfoot{}
\definecolor{grey}{rgb}{0.6,0.6,0.6}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
\setlength{\headheight}{24pt}
\fancyhead[RO]{\sffamily\bfseries\textcolor{grey}\leftmark\hspace{0.3cm}\sffamily\textcolor{darkgrey}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgrey}\thepage\hspace{0.3cm}\sffamily\textcolor{grey}\leftmark}
\renewcommand{\headrulewidth}{0.6pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrule}{%
\vskip-\baselineskip\vskip4pt
\ifodd\count0\hfill\begin{tikzpicture}
\shade[left color=white, right color=black, dashed] (0,0) rectangle (4.98,0.01);
\end{tikzpicture}\else\begin{tikzpicture}
\shade[left color=black, right color=white, dashed] (0,0) rectangle (4.98,.01);
\end{tikzpicture}\fi}
\begin{document}
\chapter{Test chapter}
\lipsum
\lipsum
\end{document}
答案2
您可以使用以下包来实现etoolbox
:
\documentclass[11pt, titlepage, openright]{book}
\usepackage[textwidth=13cm, left=2.5cm, bottom=2cm, top=2.5cm, paperwidth=20cm, paperheight=27cm, layoutwidth=19cm, layoutheight=26cm, layouthoffset=0.5cm, layoutvoffset=0.5cm, showcrop, asymmetric]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{}
\fancyfoot{}
\definecolor{grey}{rgb}{0.6,0.6,0.6}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}%
\usepackage{etoolbox}
\setlength{\headheight}{24pt}
\fancyhead[RO]{\sffamily\bfseries\textcolor{grey}\leftmark\hspace{0.3cm}\sffamily\textcolor{darkgrey}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgrey}\thepage\hspace{0.3cm}\sffamily\textcolor{grey}\leftmark}
\renewcommand{\headrulewidth}{0.6pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrule}{%
\begin{tikzpicture}%
\ifnumodd{\value{page}}{%
\shade[white] (0,0) rectangle (8,0);
\shade[left color=white, right color=black, dashed] (8,1) rectangle (12.98,1.01);
}%
{%
\shade[white] (0,0) rectangle (5,0);
\shade[left color=black, right color=white, dashed] (0,1) rectangle (4.98,1.02);
}
\end{tikzpicture}
}%
\begin{document}
\chapter{Test chapter}
\lipsum
\lipsum
\end{document}
答案3
您可以将\fancyhead
内容放入其中node
,然后绘图就变得容易了。
\fancyhead[RO]{%
\begin{tikzpicture}
\node[inner xsep=0pt, align=right,text width=5cm] (a) {\sffamily\bfseries\textcolor{grey}
{\leftmark}\hspace{0.3cm}\sffamily\textcolor{darkgrey}{\thepage}};
\shade[left color=white, right color=black, dashed] (a.south west) rectangle
([yshift=0.01cm]a.south east);
\end{tikzpicture}%
}
\fancyhead[LE]{%
\begin{tikzpicture}
\node[inner xsep=0pt, align=left,text width=5cm](a){\sffamily\bfseries\textcolor{darkgrey}
{\thepage}\hspace{0.3cm}\sffamily\textcolor{grey}{\leftmark}};
\shade[right color=white, left color=black, dashed] (a.south west) rectangle
([yshift=0.01cm]a.south east);
\end{tikzpicture}%
}
代码:
\documentclass[11pt, titlepage, openright]{book}
\usepackage[textwidth=13cm, left=2.5cm, bottom=2cm, top=2.5cm, paperwidth=20cm, paperheight=27cm, layoutwidth=19cm, layoutheight=26cm, layouthoffset=0.5cm, layoutvoffset=0.5cm, showcrop, asymmetric,headheight=24pt]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{}
\fancyfoot{}
\definecolor{grey}{rgb}{0.6,0.6,0.6}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
%\setlength{\headheight}{24pt}
\fancyhead[RO]{%
\begin{tikzpicture}
\node[inner xsep=0pt, align=right,text width=5cm] (a) {\sffamily\bfseries\textcolor{grey}
{\leftmark}\hspace{0.3cm}\sffamily\textcolor{darkgrey}{\thepage}};
\shade[left color=white, right color=black, dashed] (a.south west) rectangle
([yshift=0.01cm]a.south east);
\end{tikzpicture}%
}
\fancyhead[LE]{%
\begin{tikzpicture}
\node[inner xsep=0pt, align=left,text width=5cm](a){\sffamily\bfseries\textcolor{darkgrey}
{\thepage}\hspace{0.3cm}\sffamily\textcolor{grey}{\leftmark}};
\shade[right color=white, left color=black, dashed] (a.south west) rectangle
([yshift=0.01cm]a.south east);
\end{tikzpicture}%
}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
\chapter{Test chapter}
\lipsum
\lipsum
\end{document}