![每侧页面边距中的图形取决于奇数/偶数](https://linux22.com/image/432145/%E6%AF%8F%E4%BE%A7%E9%A1%B5%E9%9D%A2%E8%BE%B9%E8%B7%9D%E4%B8%AD%E7%9A%84%E5%9B%BE%E5%BD%A2%E5%8F%96%E5%86%B3%E4%BA%8E%E5%A5%87%E6%95%B0%2F%E5%81%B6%E6%95%B0.png)
答案1
这使用了\AddToHook{shipout/background}
,它相对较新并且内置于 LaTeX 中。
请注意,shipout\value{page}
是可靠的。只有在使用浮动或页面最后一段(好吧,任何可能排在最后的段落)时,才需要 changepage 或 ifoddpage 之类的东西。
\documentclass[a4paper]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{MyBlue}{HTML}{0053A6}
\newcommand\ColorMargin{%
\ifodd\value{page}%
\put (1 cm,-1cm){% relative to upper left corner
\begin{tikzpicture}[baseline=(current bounding box.north)]
\node[rotate=90, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {\bfseries\large MY TEXT};
\end{tikzpicture}}%
\else
\put (\paperwidth - 2 cm,-1cm){%
\begin{tikzpicture}[baseline=(current bounding box.north)]
\node[rotate=270, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {\bfseries\large MY TEXT};
\end{tikzpicture}}%
\fi
}
\AddToHook{shipout/background}[myhook]{\ColorMargin}
\begin{document}
\sloppy\lipsum[1-50]\lipsum[1-50]
\RemoveFromHook{shipout/background}[myhook]
\lipsum[1-50]
\end{document}
答案2
对我的问题的评论让我得到了很多不同的答案。我使用以下方法从中编译了一个 MWE eso-picture
:
\documentclass{article}[a4paper]
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{changepage}
\strictpagecheck
\usepackage{xcolor}
\usepackage{eso-pic}
\definecolor{MyBlue}{HTML}{0053A6}
\newcommand\ColorMargin{%
\checkoddpage
\ifoddpage
\put (1 cm,480){
\begin{tikzpicture}
\node[rotate=90, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {\bfseries\large MY TEXT};
\end{tikzpicture}}
\else
\put (\paperwidth - 2 cm,480){
\begin{tikzpicture}
\node[rotate=270, minimum height=1 cm, minimum width=10 cm, fill=MyBlue, text=white] at (0, 0) {\bfseries\large MY TEXT};
\end{tikzpicture}}
\fi
}
\AddToShipoutPicture{\ColorMargin}
\begin{document}
\sloppy\lipsum[1-50]\lipsum[1-50]
\ClearShipoutPicture
\lipsum[1-50]
\end{document}