我正在为我的数学课设计工作表,我想在每个文档的顶角放置学校徽标和班级徽标。我的工作表有很多元素,我发现如果我在背景中制作图片,它不会导致任何放置错误,也不会跳过浮动对象的任何线条。
我的问题是,我经常(随机地)在纵向和横向文档之间切换。如果我只有纵向工作表,那么我只需使用 \BgThispage 一行即可添加徽标。但是,当我切换到横向时,每次进行此切换时,我都必须重新进行背景设置。
我想知道是否有更有效的方法来做到这一点。也许像存储 2 个不同的背景设置并根据工作表的方向调用我需要的那个?
下面是我所拥有的一个例子:
\documentclass{exam}
\usepackage{lscape} % to allow pages to be temporarily landscape instead of portrait
\usepackage[margin=3cm]{geometry} % set margins to 3cm
\usepackage{tikz} % to overlay pictures
\usepackage{pdflscape} % allows you to see landscape without turning your head 90 degrees and allows landscape on any page with \begin{landscape}
%\usepackage{showframe} % make margins visible - useful for debugging
\usepackage[pages=some]{background} % make pictures in background so pictures don't skip lines when used at the top
\begin{document}
% [Page 1] ---------------------------------------------------------------------
\begin{landscape}
% Landscape Pictures
\backgroundsetup{opacity=1, scale=1, angle=0, contents={%
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=3cm,yshift=3cm,anchor=south west] at (current page.south west){%
\includegraphics[width=3cm, angle=90]{example-image-a}};
\node[xshift=3cm,yshift=-3cm,anchor=north west] at (current page.north west){%
\includegraphics[width=3cm, angle=90]{example-image-b}};
\end{tikzpicture}}}
\BgThispage % Add logos to the top corners
\begin{center}
This is a landscape page
\end{center}
\end{landscape}
\pagebreak
% [Page 2] ---------------------------------------------------------------------
\restoregeometry % this fixes the page number being way too high. I seem to need this every time I switch from portrait to landscape
% Now I need to declare a backgroundsetup since this page has a different orientation than the last
% Portrait Pictures
\backgroundsetup{opacity=1, scale=1, angle=0, contents={%
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=3cm,yshift=-3cm,anchor=north west] at (current page.north west){%
\includegraphics[width=3cm]{example-image-a}};
\node[xshift=-3cm,yshift=-3cm,anchor=north east] at (current page.north east){%
\includegraphics[width=3cm]{example-image-b}};
\end{tikzpicture}}}
\BgThispage % Add logos to the top corners
\begin{center}
This is a portrait page
\end{center}
\pagebreak
% [Page 3] ---------------------------------------------------------------------
\BgThispage
\begin{center}
This is another portrait page that doesn't need the\\
background setup since it was used in the last page.
\end{center}
\pagebreak
% [Page 4] ---------------------------------------------------------------------
\begin{landscape}
% Landscape Pictures
\backgroundsetup{opacity=1, scale=1, angle=0, contents={%
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=3cm,yshift=3cm,anchor=south west] at (current page.south west){%
\includegraphics[width=3cm, angle=90]{example-image-a}};
\node[xshift=3cm,yshift=-3cm,anchor=north west] at (current page.north west){%
\includegraphics[width=3cm, angle=90]{example-image-b}};
\end{tikzpicture}}}
\BgThispage % Add logos to the top corners
\begin{center}
This is a landscape page that needs another background setup\\
since it is a different orientation than the last page
\end{center}
\end{landscape}
\end{document}
答案1
我认为背景包和 tikz 对此来说是完全不需要的(并且总是需要两次编译。我只需使用 shipout 钩子即可。
\documentclass{exam}
\usepackage[paper=a4paper,margin=3cm]{geometry} % set margins to 3cm
\usepackage{pdflscape} %
\usepackage{graphicx,tikz}
\newcommand\placelogos{
\put(0,0){\tikz[overlay]\draw[red,<->](0,0)--++(3cm,-3cm);} %only for test
\put(3cm,-3cm){\raisebox{-\height}{\includegraphics[width=3cm]{example-image-a}}}
\put(3cm,-\paperheight+3cm){\includegraphics[width=3cm]{example-image-b}}
\put(\paperwidth-6cm,-3cm){\raisebox{-\height}{\includegraphics[width=3cm]{example-image-c}}}
\put(\paperwidth-6cm,-\paperheight+3cm){\includegraphics[width=3cm]{example-image}}}
\newcommand\placelogoslandscape{
\put(0,0){\tikz[overlay]\draw[red,<->](0,0)--++(3cm,-3cm);} %only for test
\put(3cm,-6cm){\includegraphics[width=3cm,angle=90]{example-image-a}}
\put(3cm,-\paperheight+3cm){\includegraphics[width=3cm,angle=90]{example-image-b}}
\put(\paperwidth-3cm,-6cm){\llap{\includegraphics[width=3cm,angle=90]{example-image-c}}}
\put(\paperwidth-3cm,-\paperheight+3cm){\llap{\includegraphics[width=3cm,angle=90]{example-image}}}}
\AddToHook{env/landscape/after}{\restoregeometry} %to get around the exam incompabitily
\begin{document}
% [Page 1] ---------------------------------------------------------------------
\begin{center}
This is a portrait page
\end{center}
\begin{landscape}
% Landscape Pictures
\AddToHookNext{shipout/background}{\placelogoslandscape}
\begin{center}
This is a landscape page
\end{center}
\end{landscape}
\AddToHookNext{shipout/background}{\placelogos}
\begin{center}
This is a portrait page
\end{center}
\pagebreak
% [Page 3] ---------------------------------------------------------------------
\begin{center}
This is another portrait page that doesn't need the\\
background setup since it was used in the last page.
\end{center}
\pagebreak
% [Page 4] ---------------------------------------------------------------------
\begin{landscape}
\AddToHookNext{shipout/background}{\placelogoslandscape}
\begin{center}
This is a landscape page that needs another background setup\\
since it is a different orientation than the last page
\end{center}
\end{landscape}
\end{document}