我需要在 pdf 的左侧和右侧垂直放置一些文本,因此我使用以下代码,但出现了一个额外的空白页,请帮忙。
\documentclass[twoside]{article}
\usepackage{lipsum}
\usepackage{atbegshi}
\usepackage{tikz}
\usepackage{adjustbox}
\usepackage{etoolbox}
\usepackage{xhfill}
\usepackage[paperheight=9.75in,paperwidth=7.25in]{geometry}
\begin{document}
\definecolor{headbox}{RGB}{215, 229, 232}
\def\LeftSideText{\fcolorbox{white}{headbox}{Left side text}}
\def\RightSideText{\fcolorbox{white}{headbox}{Right side text}}
%\makebox[2em]{\xdotfill{.4pt}}
\newcommand{\LeftSideBar}{
\begin{tikzpicture}[remember picture,overlay]
\draw[fill,color=orange]
([xshift=1cm,yshift=0cm]current page.south west) rectangle ([xshift=0cm,yshift=0cm]current page.north west);
\node [rotate=90] at ([xshift=1.2cm,yshift=7cm]current page.west) {\sffamily\bfseries\resizebox{!}{0.5cm}{\color{black}{\LeftSideText}}$\cdots$};%
\end{tikzpicture}
}%
\newcommand{\RightSideBar}{
\begin{tikzpicture}[remember picture,overlay]
\draw[fill,color=white]
([xshift=-1cm,yshift=0cm]current page.south east) rectangle ([xshift=0cm,yshift=0cm]current page.north east);
\node [rotate=90] at ([xshift=-2cm,yshift=7cm]current page.east) {\sffamily\bfseries\resizebox{!}{0.5cm}{\color{black}{\RightSideText}}$\cdots$};%
\end{tikzpicture}
}% CadreDePage
\AtBeginShipout{
\ifnumodd{\thepage}{\LeftSideBar}{\RightSideBar}
}
\lipsum[1-20]
\end{document}
答案1
问题在于您使用的命令将内容放在下一页,这就是为什么会出现多一页的原因。我坦率地承认我太懒了,没有在 中查找“正确”的命令atbegshi
。但是,如果我使用eso-pic
基于 的atbegshi
,并且我知道它的“正确”命令,则不会出现问题。
\documentclass[twoside]{article}
\usepackage{lipsum}
\usepackage{eso-pic}
\usepackage{tikz}
\usepackage{adjustbox}
%\usepackage{etoolbox}
%\usepackage{xhfill}
\usepackage[paperheight=9.75in,paperwidth=7.25in]{geometry}
\def\LeftSideText{\fcolorbox{white}{headbox}{Left side text}}%
\def\RightSideText{\fcolorbox{white}{headbox}{Right side text}}%
\newcommand{\LeftSideBar}{%
\begin{tikzpicture}[remember picture,overlay]
\draw[fill,color=orange]
([xshift=1cm,yshift=0cm]current page.south west) rectangle ([xshift=0cm,yshift=0cm]current page.north west);
\node [rotate=90] at ([xshift=1.2cm,yshift=7cm]current page.west) {\sffamily\bfseries\resizebox{!}{0.5cm}{\color{black}{\LeftSideText}}$\cdots$};%
\end{tikzpicture}}%
\newcommand{\RightSideBar}{%
\begin{tikzpicture}[remember picture,overlay]
\draw[fill,color=white]
([xshift=-1cm,yshift=0cm]current page.south east) rectangle ([xshift=0cm,yshift=0cm]current page.north east);
\node [rotate=90] at ([xshift=-1cm,yshift=2cm]current page.east)
{\sffamily\bfseries\resizebox{!}{0.5cm}{\color{black}{\RightSideText}}$\cdots$};%
\end{tikzpicture}}% CadreDePage
\definecolor{headbox}{RGB}{215, 229, 232}
\begin{document}
%\makebox[2em]{\xdotfill{.4pt}}
\AddToShipoutPictureBG{%
\ifnum\number\value{page}>1
\ifodd\number\value{page}%
\LeftSideBar%
\else%
\RightSideBar%
\fi%
\fi}
\lipsum[1-20]
\end{document}