在几页的页边空白处添加黑色框

在几页的页边空白处添加黑色框

我有一本课本的 latex 文档,里面有几个章节和一个目录。最后,我使用命令添加了几个 pdf 文件includepdf。然而,棘手的部分是现在仍然添加一个黑框,其中写有“I”和“II”,具体取决于 pdf 的运行索引。对于第一个 pdf,黑框应该位于右上角,并且只出现在奇数页上;对于第二个 pdf,黑框应该位于第一个 pdf 下方,也只出现在奇数页上。到目前为止,我拥有的是

\documentclass[b5paper]{book}
\usepackage[final]{pdfpages}
\usepackage{tikz}
\usepackage{ifthen}

\usepackage{lipsum}

\begin{document}

\tableofcontents

\chapter{First Chapter}
\lipsum \lipsum


\newpage
\ifodd\value{page}
  \AddToShipoutPictureBG{
      \begin{tikzpicture}[remember picture,overlay]
      \node[minimum width=2cm, minimum height=2cm, font=\Huge, rotate=90,
        rectangle, opacity=1, fill=black, text=white] 
        at (current page.north east) {I};
        \end{tikzpicture}
 }
\fi

% Some pdf with several pages
%\includepdf[pages=-,pagecommand={},width=\textwidth]{1.pdf}
\lipsum

\newpage
\ifodd\value{page}
  \AddToShipoutPictureBG{
      \begin{tikzpicture}[remember picture,overlay]
      \node[minimum width=2cm, minimum height=2cm, font=\Huge, rotate=90,
        rectangle, opacity=1, fill=black, text=white] 
        at (current page.north east) {II};
        \end{tikzpicture}
 }
\fi
%\includepdf[pages=-,pagecommand={},width=\textwidth]{2.pdf}
\lipsum
\end{document}

(我注释掉了这些includepdf部分,因为我无法在这里添加任何运行示例,因此用一些 libpsum 文本代替...)

我的问题是

  • ifodd命令未被识别
  • inputpdf如何告诉 Latex 只将 tikz 图形放在使用下一个命令创建的页面中
  • 如何向attikz 图中的位置部分添加偏移量。

编辑:只是为了完整性,这是我现在如何在每个块前面使用它(接受答案之后),inputpdf然后我只需手动调整坐标。

\AddEverypageHook{
\ifnum\value{page}>120
\ifnum\value{page}<137
{\ifodd\value{page}
  \begin{tikzpicture}[remember picture,overlay]
    \node[minimum width=2cm, minimum height=2cm, font=\Huge, rotate=90,
      rectangle, opacity=1, fill=black, text=white] 
      at (14.2,-2) {II};
  \end{tikzpicture}
\fi}
\fi
\fi}

答案1

以下是如何使用 everypage:

\documentclass[b5paper]{book}
\usepackage[final]{pdfpages}
\usepackage{tikz}
\usepackage{everypage}
\usepackage{lipsum}% MWE only

\AddEverypageHook{\ifodd\value{page}
  \begin{tikzpicture}[remember picture,overlay]
    \node[minimum width=2cm, minimum height=2cm, font=\Huge, rotate=90,
      rectangle, opacity=1, fill=black, text=white, above left=\topmargin] 
      at (current page.north east) {I};
  \end{tikzpicture}
\fi}
\begin{document}

\tableofcontents

\chapter{First Chapter}
\lipsum \lipsum[1-10]

\end{document}

至于选择特定页面而不是只选择奇数页面,关键是将信息放入辅助文件中。这可以使用自定义宏来完成(请参阅侧身图)或使用\refstepcounter\label\getpagerefnumber

相关内容