includepdf 結果出現在不需要的標題中

includepdf 結果出現在不需要的標題中
\includepdf[pages={34-40},nup=2x2,frame,landscape,scale=0.8,%
    pagecommand=\chapter{fracture}\section{Theoretical}]{Dam-Nonlinear.pdf}
\clearpage
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8,%
    pagecommand={\section{blablah}}]{ASCE-Cyclic-Joint-Model.pdf,1,%
    ASCE-Cyclic-Joint-Test.pdf,1}
\includepdf[scale=0.8,nup=2x2,pages={9-13},frame,landscape,%
    pagecommand=\section{Experimental Work}]{Ageing-Shaking-Cracking.pdf}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8]{cement-concrete-slowik.pdf,1,% 
    Optical_Fiber-in-FPZ.pdf,1}

結果是

  1. 第 1 章(斷裂)和第 1.1 節(理論)的正確標題以及要包含的 pdf 文件(需要兩頁)
  2. 第一個問題,在第 3 頁,我再次得到:第 2 章斷裂和 2.1 理論,後面是空白。明顯錯誤
  3. 然後我正確地得到了第 2.2 節等等,後面是要包含的 pdf(一頁)。
  4. 我在兩頁的第一頁上得到了正確的 2.4 實驗工作,但第二頁(共兩頁)的標題又相同。

答案1

pagecommand選項僅適用於「非物質」的事物,例如\thispagestyle.你的使用方式將開啟新的篇章在每個包含的頁面上

我假設您正在使用類似書籍的課程,其中新的章節總是從正確的頁面開始。第二個插入的空頁\chapter才是真正搞亂的地方。

我建議完全\chapter搬離:\section\includepdf

\chapter{fracture}\section{Theoretical}
\includepdf[pages={34-40},nup=2x2,frame,landscape,scale=0.8,%
pagecommand={}]{texbook.pdf}
\clearpage
\section{blablah}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8,%
pagecommand={}]{texbook.pdf,%
1,texbook.pdf,1}
\section{Experimental Work}
\includepdf[scale=0.8,nup=2x2,pages={9-13},frame,landscape,%
pagecommand={}]{texbook.pdf}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8]{texbook.pdf,% 
1,texbook.pdf,1}

當然,我無法判斷這是否是您想要的,因為您對此提供的細節很少。

答案2

您可以將 pdf 包含兩次。第一次僅包含第一頁。第二次包括所有其他沒有標題的頁面。

\includepdf[pages=34,nup=2x2,frame,landscape,scale=0.8,
    pagecommand=\chapter{fracture}\section{Theoretical}]{Dam-Nonlinear.pdf}
\includepdf[pages={35-40},nup=2x2,frame,landscape,scale=0.8
    {Dam-Nonlinear.pdf}
\clearpage

答案3

也許你想要這樣的東西?請注意,這將是一個很多透過適當的最小範例可以更輕鬆地使用。就理解你想要做什麼而言,這一半以上是猜測——更不用說考慮實現它的方法了。

如果我的猜測是正確的,你想要輸出如下:

猜測 猜測 猜測

我不知道為什麼全是風景。在這方面,我只是遵循問題中的程式碼,儘管它作為輸出對我來說沒有多大意義。 (也許包含的文件是專門定制的或其他東西,以便縱向標題與橫向內容看起來不奇怪。)

不管怎樣,如果你需要的話,你可以調整它。

關鍵點是\chapter和/或\section等命令僅在任何單一 PDF 包含的第一頁上發出。這是透過將這些命令包裝在新命令中來實現的

\dynpage{<stuff for first page>}

在論證中pagecommand.該命令的作用是觸發一個動態序列,該序列\relax在第一次迭代後重新定義自身。因此,第一頁的內容不會在第一頁以外的任何內容上排版。

\def\victor@dynpage{\victor@firstpage\global\let\victor@dynpage\relax}
\newcommand*\dynpage[1]{%
  \def\victor@firstpage{#1}%
  \victor@dynpage}

這樣做的問題是多次需要該命令。所以,我們每次都需要重置它,這樣它就不僅僅是\relax.為此,我們\pretocmd使用電子工具箱它將我們的動態序列加入\includepdf.

\pretocmd{\includepdf}{%
  \def\victor@dynpage{\victor@firstpage\global\let\victor@dynpage\relax}%
}

完整程式碼:

\documentclass[a4paper,openany]{book}
\usepackage{geometry,pdfpages,etoolbox}
\geometry{scale=.85}
\makeatletter
\pretocmd{\includepdf}{%
  \def\victor@dynpage{\victor@firstpage\global\let\victor@dynpage\relax}%
}
\newcommand*\dynpage[1]{%
  \def\victor@firstpage{#1}%
  \victor@dynpage}
\makeatother
\begin{document}
\includepdf[pages={-},nup=2x2,frame,landscape,scale=0.8,%
pagecommand=\dynpage{\chapter{fracture}\section{Theoretical}}]{k}
\clearpage
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8,%
    pagecommand={\section{blablah}}]{example-image-a4,1,%
    example-image-a4,1}
\includepdf[scale=0.8,nup=2x2,pages={-},frame,landscape,%
pagecommand=\dynpage{\section{Experimental Work}}]{k}
\includepdfmerge[nup=1x2,frame,landscape,scale=0.8]{example-image-a4,1,%
    example-image-a4,1}
\end{document}

相關內容