我使用tikz
图片作为标题的一部分,带有scrlayer-scrpage
和geometry
。
如果我使用固定值定义高度,则页眉会按预期显示。但是,如果我用 替换\headheight
,页眉会从一页变大到另一页。以下是该问题的说明。奇数页包含扩展页眉,偶数页包含固定页眉:
\documentclass{scrreprt}
\usepackage[twoside,inner=2.5cm,outer=4cm,bindingoffset=1cm,
top=4cm,bottom=4cm,headheight=1.5cm, headsep=1cm]{geometry}
\usepackage[manualmark]{scrlayer-scrpage}
\usepackage{tikz}
\usepackage{lipsum}
\newcommand{\myheader}{%
\begin{tikzpicture}
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,minimum height=\headheight,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,minimum height=\headheight,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,minimum height=\headheight,anchor=east] {};
\end{tikzpicture}%
}
\newcommand{\myheadertwo}{%
\begin{tikzpicture}
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,minimum height=1.5cm,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,minimum height=1.5cm,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,minimum height=1.5cm,anchor=east] {};
\end{tikzpicture}%
}
\lohead*{\myheader}
\lehead*{\myheadertwo}
\begin{document}
\lipsum[1-100]
\end{document}
从下面的图片中你可以看出,在第一个双页跨页中,页眉是相等的,但奇数页的页眉不断增大。
对于我的实际文档,我可以轻松使用固定值,因此这不是一个迫切的问题,但我想了解这种行为的原因,以防出现一些更深层次的潜在问题可能会再次困扰我。
答案1
scrlayer-scrpages 会告诉您为什么会发生这种情况。您只需查看日志文件:
Package scrlayer-scrpage Warning: \headheight to low.
(scrlayer-scrpage) At least 83.4793pt needed,
(scrlayer-scrpage) but only 79.39928pt found.
(scrlayer-scrpage) I'll enlarge \headheight, for further
(scrlayer-scrpage) processing, but you should do this yourself,
(scrlayer-scrpage) e.g., setting geometry's option
(scrlayer-scrpage) `head=83.4793pt'.
(scrlayer-scrpage) I'll also decrease \topmargin on input line 47.
(几天前我也遇到了这个问题,真希望我可以告诉 scrlayer 不要打扰我并保持我的布局原样...)。
答案2
图片插入在页眉基线上方。但\headheight
页眉的总高度包括基线下方的深度。因此,您必须将图片向下移动以\dp\strutbox
获得
代码:
\documentclass{scrreprt}
\usepackage[twoside,inner=2.5cm,outer=4cm,bindingoffset=1cm,
top=4cm,bottom=4cm,headheight=1.5cm, headsep=1cm]{geometry}
\usepackage[manualmark]{scrlayer-scrpage}
\usepackage{tikz}
\usepackage{lipsum}
\newcommand{\myheader}{%
\begin{tikzpicture}[nodes={minimum height=\headheight}]
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,anchor=east] {};
\end{tikzpicture}%
}
\newcommand{\myheadertwo}{%
\begin{tikzpicture}[nodes={minimum height=1.5cm}]
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,anchor=east] {};
\end{tikzpicture}%
}
\lohead*{\raisebox{-\dp\strutbox}{\myheader}}
\lehead*{\raisebox{-\dp\strutbox}{\myheadertwo}}
\begin{document}
\lipsum[1-100]
\end{document}
或者
\documentclass{scrreprt}
\usepackage[twoside,inner=2.5cm,outer=4cm,bindingoffset=1cm,
top=4cm,bottom=4cm,headheight=1.5cm, headsep=1cm]{geometry}
\usepackage[manualmark]{scrlayer-scrpage}
\usepackage{tikz}
\usepackage{lipsum}
\newcommand{\myheader}{%
\begin{tikzpicture}[baseline=\dp\strutbox,nodes={minimum height=\headheight}]
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,anchor=east] {};
\end{tikzpicture}%
}
\newcommand{\myheadertwo}{%
\begin{tikzpicture}[baseline=\dp\strutbox,nodes={minimum height=1.5cm}]
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,anchor=east] {};
\end{tikzpicture}%
}
\lohead*{\myheader}
\lehead*{\myheadertwo}
\begin{document}
\lipsum[1-100]
\end{document}
您还可以通过以下方式降低节点的高度-\dp\strutbox
:
\documentclass{scrreprt}
\usepackage[twoside,inner=2.5cm,outer=4cm,bindingoffset=1cm,
top=4cm,bottom=4cm,headheight=1.5cm, headsep=1cm]{geometry}
\usepackage[manualmark]{scrlayer-scrpage}
\usepackage{tikz}
\usepackage{lipsum}
\newcommand{\myheader}{%
\begin{tikzpicture}[nodes={minimum height=\headheight-\dp\strutbox}]
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,anchor=east] {};
\end{tikzpicture}%
}
\newcommand{\myheadertwo}{%
\begin{tikzpicture}[nodes={minimum height=1.5cm-\dp\strutbox}]
\node (graybar)
[fill=black!30,inner sep=0pt,text width=\textwidth,anchor=west] {};
\node (leftsidebar) at (graybar.west)
[fill=black,inner sep=0pt,text width=12pt,anchor=west] {};
\node (rightsidebar) at (graybar.east)
[fill=black,inner sep=0pt,text width=12pt,anchor=east] {};
\end{tikzpicture}%
}
\lohead*{\myheader}
\lehead*{\myheadertwo}
\begin{document}
\lipsum[1-100]
\end{document}
或者您可以使用\smash
内部\lohead*
和\lehead*
来隐藏图片的高度。