我想在文档的每一页上放置一张图片(TikZ 图片)。我该怎么做?
本质上,我想控制图像在偶数页和奇数页上的放置。例如,文件夹上的孔,在奇数页上位于左侧,在偶数页上位于右侧。
编辑
因此我使用 Peter Grill 的版本进行测试,结果如下:
\documentclass[svgnames]{article}
\usepackage[left=2.5cm,right=2.5cm, top=3.75cm, bottom=3.5cm,letterpaper]{geometry}
\usepackage[all]{background}
\usepackage{lipsum,url}
\usepackage{amsmath,amssymb,enumitem,multicol}
\usepackage{tikz,bbding}
\usetikzlibrary{calc}
\usepackage{changepage}
\strictpagecheck
\newcommand*{\VOffset}{2cm}% vertical offset
\newcommand*{\HOffset}{1cm}% horizontal offset
\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,draw=black,ultra thick]
\checkoddpage
\ifoddpage
\draw [fill=gray!50] (\HOffset,-\VOffset) circle (0.5cm);
\draw [fill=gray!50] ($(\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw [fill=gray!50] ($(\HOffset,-0.5\paperheight)$) circle (0.5cm);
\else
\draw [fill=gray!50] (\paperwidth-\HOffset,-\VOffset) circle (0.5cm);
\draw [fill=gray!50] ($(\paperwidth-\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw [fill=gray!50] ($(\paperwidth-\HOffset,-0.5\paperheight)$) circle (0.5cm);
\fi
\end{tikzpicture}
}
\SetBgContents{\MyTikzLogo}% Set tikz picture
\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo
\parindent0pt \parskip8pt
\begin{document}
\begin{tikzpicture}[overlay, remember picture]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[draw=MidnightBlue,fill=MidnightBlue] (0,0) rectangle (0.75cm,3cm);%black
\draw[draw=gray!20,fill=gray!20] (0.75cm,0) rectangle (\paperwidth,3cm);%gray!20 or LightSkyBlue and \paperwidth-0.01cm
\end{tikzpicture}};
\path (current page.north west) ++(0.5,-1.55) node[rotate=90] {\color{white}\tiny revised \today};
\path (current page.north east) ++(-1,-1) node[below left] {Name: \rule{2in}{.4pt}};
\path (current page.north east) ++(-1,-1.5) node[below left] {Date: \rule{2in}{.4pt}};
\path (current page.north west) ++(1,-0.5) node[below right] {Course Name};
\path (current page.north west) ++(1,-1) node[below right] {University};
\path (current page.north west) ++(1,-1.5) node[below right] {Mathematics and Science Department};
\end{tikzpicture}
\section*{Lorem Ipsum}
\lipsum[1-25]
\end{document}
我遇到的问题是,当我尝试打印时,文件似乎没有填满整个页面。页眉部分仅适用于第一页,其他页面仅包含课程名称。
深入了解此事将会有所帮助。
答案1
这是改编自的解决方案如何使用 TikZ 和 graphicx 在左上角添加图像.这使用包裹background
在每一页上放置一个tikzpicture
。控制奇数页和偶数页行为的逻辑来自此解决方案为 if then else 针对奇数页偶数页。
控制孔位\VOffset
及\HOffset
定位的参数如下:
\documentclass[12pt]{book}
\usepackage[demo]{graphicx}
\usepackage[all]{background}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{changepage}
\strictpagecheck
\newcommand*{\VOffset}{2cm}% vertical offset
\newcommand*{\HOffset}{1cm}% horizontal offset
\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,draw=black,ultra thick]
\checkoddpage
\ifoddpage
\draw [fill=gray!50] (\HOffset,-\VOffset) circle (0.5cm);
\draw [fill=gray!50] ($(\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw [fill=gray!50] ($(\HOffset,-0.5\paperheight)$) circle (0.5cm);
\else
\draw [fill=gray!50] (\paperwidth-\HOffset,-\VOffset) circle (0.5cm);
\draw [fill=gray!50] ($(\paperwidth-\HOffset,-\paperheight+\VOffset)$) circle (0.5cm);
\draw [fill=gray!50] ($(\paperwidth-\HOffset,-0.5\paperheight)$) circle (0.5cm);
\fi
\end{tikzpicture}
}
\SetBgContents{\MyTikzLogo}% Set tikz picture
\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo
\begin{document}
\section*{Lorem Ipsum}
\lipsum[1-25]
\end{document}
答案2
另一种选择fanchydr
是scrpage2
(KOMA-Script 的一部分)。
例子:
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{scrpage2}
% right head on even page
\rehead{\tikz[overlay, remember picture]\fill [red] ($(current page.north east)-(2,10)$) circle (2mm);}
% left head on odd page
\lohead{\tikz[overlay, remember picture]\fill [green] ($(current page.north west)+(2,-10)$) circle (2mm);}
\pagestyle{scrheadings}
\usepackage{lipsum}
\begin{document}
\lipsum[1-50]
\end{document}
你也可以看看页面边框有颜色
答案3
fancyhdr
以下是使用和textpos
技巧将页眉(或本例中的页脚)放在指定区域之外的解决方案fancyhdr
。您必须根据自己的喜好调整其他页眉/页脚(请参阅fancyhdr
手动的。) 您将 放在页眉/页脚的什么位置并不重要textblock
,您只需区分偶数页和奇数页。
\documentclass[a4paper,twoside]{article}% to get even and odd pages
\usepackage{fancyhdr}
\usepackage{tikz}
\newcommand{\mytikzpic}{\tikz \shade[left color=yellow,right color=blue] (0,0) circle (1.25cm);}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{10mm}% 1 generic horizontal unit is equivalent to 10mm
\setlength{\TPVertModule}{10mm}% 1 generic vertical unit is equivalent to 10mm
\textblockorigin{0mm}{0mm}% top left corner set as origin
\pagestyle{fancy}
\fancyfoot[LO]{
\begin{textblock}{3}(17.5,10)
\mytikzpic
\end{textblock}
}
\fancyfoot[RE]{
\begin{textblock}{3}(0.5,10)
\mytikzpic
\end{textblock}
}
\usepackage{lipsum}% just for filler text
\begin{document}
\lipsum
\end{document}
答案4
包裹fanchydr
就是为了这个目的而编写的:在文档的每一页上放置一些内容,可以选择在偶数页和奇数页上放置不同内容。