我使用 Latex 书籍模板,目前,我尝试在页面顶部添加一张宽图像,在页面底部添加另一张。图像应忽略边距,文本不应与图像重叠。
我的第一次尝试结果是这样的:
代码:\documentclass[10pt,a4paper,twocolumn,openany]{book}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{lipsum}
\newcommand*{\rpgarttop}[1]{%
\begin{figure*}[!t]%
\begin{tikzpicture}[remember picture,overlay]
\node[inner sep=0pt, anchor=north] at (current page.north) {\includegraphics[width=\paperwidth]{#1}};
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%
% need to get the image dimension here
%\rule{image width}{image height}
%%%%%%%%%%%%%%%%%%
\end{figure*}%
}
\newcommand*{\rpgartbottom}[1]{%
\begin{figure*}[!t]%
\begin{tikzpicture}[remember picture,overlay]
\node[inner sep=0pt, anchor=south] at (current page.south) {\includegraphics[width=\paperwidth]{#1}};
\end{tikzpicture}
\end{figure*}%
}
\begin{document}
\rpgarttop{art-top}
\rpgartbottom{art-bottom}
\section{Section 1}
\lipsum[1-15]
\end{document}
如您所见,边距被忽略,但文本与图像重叠。
如果你们中有人有任何想法可以解决这个问题,那就太好了!
另外,这里是整个项目的链接:https://github.com/Krozark/RPG-LaTeX-Template
编辑 1:添加图像尺寸的注释
答案1
\documentclass[10pt,a4paper,twocolumn,openany]{book}
\usepackage{graphicx}
\usepackage{dblfloatfix}
\usepackage[strict]{changepage}
\usepackage{lipsum}
\newlength{\rpghmargin}
\newcommand*{\pagepicture}[2]{%
\checkoddpage
\ifoddpage
\setlength{\rpghmargin}{\dimexpr 1in+\hoffset+\oddsidemargin+32pt \relax}
\else
\setlength{\rpghmargin}{\dimexpr 1in+\hoffset+\evensidemargin-25pt \relax}
\fi
\begin{figure*}[#1!]
\centering
\if #1t
\vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep \relax}
\fi
\makebox[\paperwidth][l]{
\hskip-\rpghmargin \relax
\includegraphics[width=\paperwidth]{#2}
}
\if #1b
\vspace*{-\dimexpr\paperheight-\textheight-1in+12pt-\voffset-\topmargin-\headheight-\headsep\relax}
\fi
\end{figure*}
}
\begin{document}
\pagepicture{t}{art-top}
\pagepicture{b}{art-bottom}
\lipsum
\lipsum
\end{document}
对我有帮助的链接: