
我嘗試在文件標題頁的頁首和頁尾中新增居中圖片。它應該像第一張圖片一樣,是我剛剛在文字處理程式中創建的。
我嘗試了兩種不同的方法,在 LaTeX 中實現這個想法:
第一個是基於scrlayer-scrpage
.我使用這個包和以下程式碼:
\documentclass{article}
\usepackage{scrlayer-scrpage, graphicx}
\pagestyle{scrheadings}
\clearpairofpagestyles
\chead{\includegraphics{Picture1.png}}
\begin{document}
\centering{Title}
\end{document}
這段程式碼和套件的結果並不像它想要的那樣。這也可以在我附在這篇文章中的第二張圖片中看到。圖片左側太遠了。它不居中。
因此,我嘗試了第二種方式,我使用了fancyhdr
.對於這個包,我開發了以下程式碼:
\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[C]{\includegraphics{Picture1.png}}
\begin{document}
\centering{Title}
\end{document}
就像你在第三張圖片中看到的那樣,這個套件和開發的程式碼也不是正確的解決方案,因為圖片不夠高,而且離右側太遠。
因此,我只是想問是否有其他解決方案來實現我在 LaTeX 文件的頁眉和頁腳中居中圖片的想法。
編輯:
答案1
這是一個解決方案scrlayer-scrpage
。也許有更簡單的帶有background
或tikz
包的。這樣做的好處是您可以隨時套用此頁面樣式。您可以將它與許多類別和geometry
(邊距)佈局一起使用。標尺僅供參考。
\documentclass[a4paper]{mwart}
\usepackage{scrlayer-scrpage}
\usepackage{graphicx,xcolor}
%\usepackage[margin=2cm,includeheadfoot]{geometry}
\DeclareNewLayer[
background,
topmargin,
% align=t,
height=5cm,
%hoffset=7cm,
%addheight=\headheight,
mode=picture,
contents={\includegraphics[height=5cm]{frog.jpg}}
]{top}
\DeclareNewLayer[
background,
bottommargin,
%addheight=\headheight,
mode=picture,
contents={\includegraphics[height=\layerheight,width=\layerwidth]{example-image-b}}
]{bottom}
\DeclareNewLayer[
background,
%outermargin,
%topmargin,
contents=\layercontentsmeasure
]{measurelayer}
%\defpairofpagestyles[plain.scrheadings]{title}{} %use this if you want plain (bottom number) on 1st page
\defpairofpagestyles{title}{}
\AddLayersToPageStyle{title}{top,bottom,measurelayer}
%\DeclareNewPageStyleByLayers{title}{top,bottom,measurelayer} %an alternative you want to create an empty style
\title{asdf} \author{asdf}
\begin{document}
\maketitle
\thispagestyle{title}
\newpage
\setcounter{page}{1}
asdf
\end{document}