需要在同一页的不同位置打印两个水印,一个在左下角,一个在页面中央。为此,需要用到宏\AtPageLowerLeft
和\AtAtPageCenter
from 包eso-pic
。我想根据条件设置坐标原点。因此\position
引入了另一个宏\let
。但这会导致前一个水印打印在错误的位置,详情请看代码:
\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}
\begin{document}
\null
\let\position\AtPageCenter
\AddToShipoutPictureBG{%
\position{%
\put(0,0){paper center waterprint}
}
}
%
\let\position\AtPageLowerLeft
\AddToShipoutPictureBG{%
\position{%
\put(20,20){lower left waterprint}
}
}
\end{document}
您可以看到两个水印都位于页面的左下角。
谁能告诉我原因?
答案1
回答评论中的问题。例如,您可以这样做:
\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}
\makeatletter
\let\mypackage@esopicposition@pc\AtPageCenter
\newcommand\mypackage@waterprint@pc{\put(0,0){paper center waterprint}}
\let\mypackage@esopicposition@ll\AtPageLowerLeft
\newcommand\mypackage@waterprint@ll{\put(20,20){paper left waterprint}}
\newcommand\mywaterprint[1]{%
\AddToShipoutPictureBG{%
\csname mypackage@esopicposition@#1\endcsname {%
\csname mypackage@waterprint@#1\endcsname
}
}}
\makeatother
\begin{document}
\null
\mywaterprint{pc}
\mywaterprint{ll}
\end{document}
由于您对命令名称中的 @ 非常反感,因此这里提供了一个没有 @ 的版本:
\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}
\let\mypackageXesopicpositionXpc\AtPageCenter
\newcommand\mypackageXwaterprintXpc{\put(0,0){paper center waterprint}}
\let\mypackageXesopicpositionXll\AtPageLowerLeft
\newcommand\mypackageXwaterprintXll{\put(20,20){paper left waterprint}}
\newcommand\mywaterprint[1]{%
\AddToShipoutPictureBG{%
\csname mypackageXesopicpositionX#1\endcsname {%
\csname mypackageXwaterprintX#1\endcsname
}
}}
\begin{document}
\null
\mywaterprint{pc}
\mywaterprint{ll}
\end{document}
答案2
\documentclass[12pt,a4paper]{article}
\usepackage{eso-pic}
\newcommand\myWaterprint[1][C]{%
\AddToShipoutPictureBG{%
\ifx#1C
\AtPageCenter{\put(0,0){paper center waterprint}}%
\else
\AtPageLowerLeft{\put(20,20){lower left waterprint}}%
\fi}}
\begin{document}
\null
\myWaterprint% default is [C]
\myWaterprint[L]
\end{document}