我想在页眉旁边的边距中添加一个图像。图像的底部应与页眉基线对齐。在我的 MWE(见下文)中,图像的顶部与页眉顶部一起调整。
我怎样才能调整基线处的图像?
marginnote
您建议其他改进吗?例如,在 中使用是否有意义ihead
?
梅威瑟:
\documentclass{scrreprt}
\usepackage{blindtext, graphicx, marginnote}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\ihead{%
\marginnote{%
\includegraphics[width=\marginparwidth]{example-image-a}%
}
}
\begin{document}
\Blinddocument
\end{document}
答案1
我不会使用marginnote
,但只会scrlayer-scrpage
:
\documentclass{scrreprt}
\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\rohead{\headmark\makebox[0pt][l]{\hskip\marginparsep\includegraphics[width=\marginparwidth]{example-image-a}}}
\lehead{\makebox[0pt][r]{\includegraphics[width=\marginparwidth]{example-image-a}\hskip\marginparsep}\headmark}
\begin{document}
\Blinddocument
\end{document}
您还可以将自己的图层添加到页面样式中scrheadings
,如果您希望图像也显示在纯文本页面上,则可以plain.scrheadings
:
\documentclass{scrreprt}
\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\DeclareNewLayer[background,
head,
addhoffset=\ifodd\value{page}\textwidth+\marginparsep\else-\marginparwidth-\marginparsep\fi,
width=\marginparwidth,% optional reduce layer width
contents={\includegraphics[width=\marginparwidth]{example-image-a}}]{image}
\AddLayersToPageStyle{scrheadings}{image}
%\AddLayersToPageStyle{plain.scrheadings}{image}
\begin{document}
\Blinddocument
\end{document}
结果是一样的,但你不需要将 拆分\ihead
成\lehead
和\rohead
。你只需激活单个注释行即可激活纯文本页面的图像。
顺便说一句:我建议将图像一次放入一个框中,然后在每一页上使用该框:
\documentclass{scrreprt}
\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\DeclareNewLayer[background,
head,
addhoffset=\ifodd\value{page}\textwidth+\marginparsep\else-\wd\headimagebox-\marginparsep\fi,
width=\marginparwidth,
contents=\usebox\headimagebox]{image}
\AddLayersToPageStyle{scrheadings}{image}
\AddLayersToPageStyle{plain.scrheadings}{image}% used on chapter start page
\begin{document}
\Blinddocument
\end{document}
如果代码应在单面模式下将徽标始终放在右侧:
\documentclass{scrreprt}
%\documentclass[twoside]{scrreprt}
\usepackage{mwe,graphicx}
\usepackage{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\makeatletter
\DeclareNewLayer[background,
head,
addhoffset=\ifcase\if@twoside \ifodd\value{page} 0 \else 1 \fi\else 0 \fi\textwidth+\marginparsep\else-\wd\headimagebox-\marginparsep\fi,
width=\marginparwidth,
contents=\usebox\headimagebox]{image}
\makeatother
\AddLayersToPageStyle{scrheadings}{image}
\AddLayersToPageStyle{plain.scrheadings}{image}% used on chapter start page
\begin{document}
\Blinddocument
\end{document}
但在这种情况下,对左页和右页使用不同的层可能会更容易:
\documentclass{scrreprt}
%\documentclass[twoside]{scrreprt}
\usepackage{mwe,graphicx}
\usepackage{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\DeclareNewLayer[background,
oddpage,% for right pages in double-side mode or all pages in single-side mode
head,
addhoffset=\textwidth+\marginparsep,
width=\marginparwidth,
contents=\usebox\headimagebox]{image.odd}
\DeclareNewLayer[background,
evenpage,% for left pages in double-side mode
head,
addhoffset=-\wd\headimagebox-\marginparsep,
width=\marginparwidth,
contents=\usebox\headimagebox]{image.even}
\AddLayersToPageStyle{scrheadings}{image.odd,image.even}
\AddLayersToPageStyle{plain.scrheadings}{image.odd,image.even}% used on chapter start page
\begin{document}
\Blinddocument
\end{document}