%20%E9%87%8D%E3%81%AD%E5%90%88%E3%82%8F%E3%81%9B%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B%3F.png)
結合しようとしている一連の PDF ファイルがあります。 ここまでは問題なくできます。
また、各ページの上の「外側」の角に、各ページがどの元の文書から来たのかを本質的に識別する少量のテキストを追加する必要があります。これまでのところ、各ページの左上隅にテキストを配置することに成功しています。これについては、Stack Exchange に他の質問があります。
しかし、いずれも、テキストを奇数ページと偶数ページで異なる位置に配置する方法 (つまり、偶数ページでは左上隅、奇数ページでは右上隅) には対応していません。 これを実現するにはどうすればよいでしょうか?
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{pdfpages}
\usepackage{tikz}
\renewcommand{\contentsname}{My combined file}
\setlength\parindent{0pt}
\begin{document}
\includepdf[pages=-]{cover.pdf}
\includepdf[pages=2-4,pagecommand={\begin{tikzpicture}[remember picture, overlay]
\node[right] at (-2, 2.5) {\LARGE{doc1}};
\end{tikzpicture}}]{doc1.pdf}
% More files included here
\end{document}
追加のクレジットとして、挿入されたテキストとして、含まれているドキュメントのファイル名を(自動的に)使用する方法はありますか?
答え1
これはeverypage
パッケージを使用してタスクを実行します。構文は次のとおりです。
\atxy{this page X}{alternate page X}{Y}{content}
奇数ページで呼び出された場合、「このページ X」は奇数ページのコンテンツの x 位置であり、「代替ページ X」は偶数ページのコンテンツの x 位置です。偶数ページで呼び出された場合はその逆になります。
マクロでコンテンツを更新する\updateText{}
これが私の MWE です。必要に応じて、プロセスを 1 ページ目以降に呼び出せるように編集されています (ただし、MWE では 1 ページで呼び出されると示されています)。
\documentclass{article}
\usepackage{everypage}
\usepackage{lipsum}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\def\localX{0in}
\def\ThisX{0in}
\def\AltX{0in}
% SYNTAX \atxy{This page X}{Alt page X}{y}{content}
\newcommand\atxy[4]{%
\def\XYtext{#4}
\gdef\ThisX{#1}\gdef\AltX{#2}%
\AddEverypageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+\localX\relax}%
\raisebox{\dimexpr\PageTopMargin+\voffset-#3\relax}{\XYtext}}}}
\AddEverypageHook{\ifdim\localX=\ThisX\gdef\localX{\AltX}\else\gdef\localX{\ThisX}\fi}
\newcommand\updateText[1]{\gdef\XYtext{#1}}
\begin{document}
\atxy{7in}{0.2in}{0.5in}{\parbox[t]{1in}{\Huge This is my initial text}}
\lipsum[1-7]
\updateText{\parbox[t]{1in}{\Huge Follow Up text}}
\lipsum[8-35]
\end{document}
答え2
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{pdfpages}
\usepackage{ifoddpage}
\usepackage{background}
\newcommand{\mypdfinclude}[2][]{%
\backgroundsetup{%
placement=top,
angle=0,
nodeanchor=north east,
color=red,
scale=1,
contents={%
\checkoddpage\ifoddpage%
\begin{tikzpicture}[remember picture,overlay]
\node[text width=2in,anchor=north east,align=right,font=\Large] at
([shift={(-1cm,-1cm)}]current page.north east) {#2};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node[text width=2in,anchor=north west,font=\Large] at ([shift={(1cm,-1cm)}]current
page.north west) {#2};
\end{tikzpicture}
\fi
}
}
\includepdf[#1]{#2}
}
\begin{document}
\mypdfinclude[pages=2-4]{pgfmanual.pdf}
\end{document}
答え3
ここでは、パッケージを使用して、scrlayer
含まれる PDF の特別なページスタイルを定義する別の提案を示します。
\documentclass[a4paper]{book}
\usepackage{pdfpages}
\usepackage{xcolor}
\usepackage{scrlayer}
\newcommand{\pdfpagestext}{}
\colorlet{pdfpagescolor}{purple}
% define new layers
\DeclareNewLayer[
foreground,
oddpage,
voffset=1cm,% distance from top
hoffset=1cm,% distance from left
width=\dimexpr\paperwidth-2cm\relax,% width of the layer
height=2cm,% height of the layer
contents={\parbox{\layerwidth}{\raggedleft\textcolor{pdfpagescolor}{\pdfpagestext}}}
]{pdfpages.odd}
\DeclareNewLayer[
clone=pdfpages.odd,
evenpage,
contents={\parbox{\layerwidth}{\raggedright\textcolor{pdfpagescolor}{\pdfpagestext}}}
]{pdfpages.even}
% define new pagestyle
\DeclareNewPageStyleByLayers{pdfpages}{pdfpages.odd,pdfpages.even}
\newcommand*\myincludepdf[2][]{%
\renewcommand\pdfpagestext{#2}%
\includepdf[pagecommand=\thispagestyle{pdfpages},#1]{#2}%
}
\begin{document}
\myincludepdf[pages=1-3]{dummy.pdf}
\end{document}
片面レイアウトを使用する場合にも機能します。その場合、テキストは各ページの右 (= 外側) 余白に自動的に配置されます。
\documentclass[a4paper,oneside]{book}