将 TikZ 图片定位在页面背景上,使其位于双面文档的每一页上

将 TikZ 图片定位在页面背景上,使其位于双面文档的每一页上

在文档中,\documentclass[12pt, twoside]{book}我试图定位一个稍微复杂一点的图片,\scope其中包含两个。我尝试使用这个问题的答案:在每一页上放置一张 TikZ 图片

但据我所能解决这个问题,我无法将上述问题的答案\VOffset和命令传递到环境中。\HOffset\scope{}

就像在 MWE 中一样,我必须手动放置徽标(通过反复试验找到移位的参数)。有没有更好、更方便、更可控的方法来做到这一点,类似于上述答案中的代码?

MWE 相当冗长,因为我认为需要我的徽标的完整代码才能解决这个问题。如果您有任何建议可以进一步简化徽标代码,我将不胜感激。

非常感谢

梅威瑟:

\documentclass[12pt,twoside]{book}

\usepackage{lastpage}
\usepackage[lastpage]{zref}
\makeatletter
\zref@newprop*{numpage}{\the\value{page}}
\zref@addprop{main}{abspage}
\makeatother

\usepackage{refcount}
\setrefcountdefault{-1}

\usepackage[scale=1,opacity=1]{background}

\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shapes,calc,positioning,shadows.blur,decorations.pathreplacing}

\newcommand{\nuclei}[1]{%
    \shade[ball color=white] (#1) circle (.4);
}

\newcommand{\nucleus}{%
    \nuclei{0.1,0.3}
    \nuclei{0,0}
    \nuclei{0.3,0.2}
    \nuclei{-0.2,0.1}
    \nuclei{-0.1,0.3}
    \nuclei{0.2,-0.15}
    \nuclei{-0.05,-0.12}
    \nuclei{0.17,0.21}
}

%\electron{xwidth,ywidth,rotation angle}
\newcommand{\electron}[3]{%
    \draw[rotate = #3](0,0) ellipse (#1 and #2)[color=blue];
    \shade[ball color=black] (0,#2)[rotate=#3] circle (.2);
}

\usepackage{changepage}
\strictpagecheck

\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,scale=1]
\checkoddpage
\ifoddpage
  \begin{scope}[shift={(-7.7,17.9)}, scale=0.25]
  \begin{scope}[rotate=360*\the\value{page}/\getpagerefnumber{LastPage}]
    \nucleus
  \end{scope}       
    \electron{1.2}{1.4}{260+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4}{2}{30+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5}{1}{60+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5.5}{1.5}{150+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4.8}{2.25}{80+(360*\the\value{page}/\getpagerefnumber{LastPage})}
  \end{scope}
\else
  \begin{scope}[shift={(0.9,2.9)}, scale=0.25]
  \begin{scope}[rotate=360*\the\value{page}/\getpagerefnumber{LastPage}]
    \nucleus
  \end{scope}       
    \electron{1.2}{1.4}{260+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4}{2}{30+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5}{1}{60+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5.5}{1.5}{150+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4.8}{2.25}{80+(360*\the\value{page}/\getpagerefnumber{LastPage})}
  \end{scope}
\fi
 \end{tikzpicture}
}

\SetBgContents{\MyTikzLogo}% Set tikz picture

\SetBgPosition{current page.south east}% Select location

\begin{document}
\section*{Lorem Ipsum}
\lipsum[1-25]
\end{document}

答案1

我一直以为电子是绿色的,因为它们在示波器上看起来就是这样的。;-) 它eso-pic很简单。

\documentclass[12pt,twoside]{book}

\usepackage{lastpage}
\usepackage[lastpage]{zref}
\makeatletter
\zref@newprop*{numpage}{\the\value{page}}
\zref@addprop{main}{abspage}
\makeatother

\usepackage{refcount}
\setrefcountdefault{-1}

%\usepackage[scale=1,opacity=1]{background}
\usepackage{eso-pic}

\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shapes,calc,positioning,shadows.blur,decorations.pathreplacing}

\newcommand{\nuclei}[1]{%
    \shade[ball color=white] (#1) circle (.4);
}

\newcommand{\nucleus}{%
    \nuclei{0.1,0.3}
    \nuclei{0,0}
    \nuclei{0.3,0.2}
    \nuclei{-0.2,0.1}
    \nuclei{-0.1,0.3}
    \nuclei{0.2,-0.15}
    \nuclei{-0.05,-0.12}
    \nuclei{0.17,0.21}
}

%\electron{xwidth,ywidth,rotation angle}
\newcommand{\electron}[3]{%
    \draw[rotate = #3](0,0) ellipse (#1 and #2)[color=blue];
    \shade[ball color=black] (0,#2)[rotate=#3] circle (.2);
}

\usepackage{changepage}
\strictpagecheck

\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,scale=1]
\checkoddpage
\ifoddpage
  \begin{scope}[shift={([xshift=2cm,yshift=2cm]current page.south west)}, scale=0.25]
  \begin{scope}[rotate=360*\the\value{page}/\getpagerefnumber{LastPage}]
    \nucleus
  \end{scope}       
    \electron{1.2}{1.4}{260+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4}{2}{30+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5}{1}{60+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5.5}{1.5}{150+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4.8}{2.25}{80+(360*\the\value{page}/\getpagerefnumber{LastPage})}
  \end{scope}
\else
  \begin{scope}[shift={([xshift=-2cm,yshift=2cm]current page.south east)}, scale=0.25,local bounding box=test]
  \begin{scope}[rotate=360*\the\value{page}/\getpagerefnumber{LastPage}]
    \nucleus
  \end{scope}       
    \electron{1.2}{1.4}{260+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4}{2}{30+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5}{1}{60+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{5.5}{1.5}{150+(360*\the\value{page}/\getpagerefnumber{LastPage})}
    \electron{4.8}{2.25}{80+(360*\the\value{page}/\getpagerefnumber{LastPage})}
  \end{scope}
\fi
 \end{tikzpicture}
}

\AddToShipoutPictureBG{\MyTikzLogo}
\begin{document}
\section*{Lorem Ipsum}
\lipsum[1-25]
\end{document}

在此处输入图片描述

相关内容