첨부된 문서의 시작 부분에 사용자 정의 라벨로 목차를 생성하는 방법은 무엇입니까?

첨부된 문서의 시작 부분에 사용자 정의 라벨로 목차를 생성하는 방법은 무엇입니까?

여러 페이지의 문서를 추가하고 있는데 TOC의 각 문서 첫 페이지 시작 부분에 대한 링크를 갖고 싶습니다. 맞춤형 TOC를 만들기 위한 의사코드

  1. PDF 문서의 첫 번째 페이지에 사용자 정의 라벨 추가
  2. TOC에 맞춤 라벨 추가

PDF 페이지의 크기를 줄이지 않고 페이지에 페이지 번호를 추가하지만 PDF 페이지 시작 부분에 참조를 적용하는 데는 아무런 영향을 미치지 않는 코드

\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref} % for links in TOC
% https://tex.stackexchange.com/q/56316/13173
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt} % Werner, remove top margin border
% https://tex.stackexchange.com/a/338919/13173
\usepackage{letltxmacro}
\LetLtxMacro\oldincludepdf\includepdf
\renewcommand{\includepdf}[2][]{%
  \oldincludepdf[pagecommand={‌​\thispagestyle{fancy‌​}},#1]{#2}}

\begin{document}

% TODO add custom labels to TOC 
\tableofcontents
% Pseudocode
% \addcontentsline{toc}{someLabelForPdf}{\listPdfBeginningLabels}

% TODO add here a label/... to the beginning of pdf page such that included in TOC
\includepdf[pages=1,pagecommand=\thispagestyle{plain}]{7.pdf}
% No reference to the rest
\includepdf[pages=2-,pagecommand=\thispagestyle{plain}]{7.pdf}

% TODO reference here
\includepdf[pages=1,pagecommand=\thispagestyle{plain}]{8.pdf}
% No reference to the rest
\includepdf[pages=2-,pagecommand=\thispagestyle{plain}]{8.pdf}

\end{document}

어쩌면 의사 코드가 \addcontentsline{toc}{someLabelForPdf}{\listPdfBeginningLabels}작동할 수도 있습니다.

예시 목차

Table of Contents
7               1
8               150

Samcarter의 제안을 시도해 보세요.

수동Samcarter가 가리키는 곳은 다음과 같으 addtotoc므로 다음을 시도했지만 다음과 같은 결과가 나타납니다.

\includepdf[pages=-,pagecommand=\thispagestyle{plain},addtotoc={1}]{7.pdf}

산출

<use  "7.pdf" > <use  "7.pdf" > <use  "7.pdf"  page1> <use  "7.pdf"  page1>
[1] <use  "7.pdf"  page1> <use  "7.pdf"  page1>
Runaway argument?
addtotoc={1}]{9.pdf} \includepdf [pages=-,pagecommand=\thispagestyle \ETC.
! Paragraph ended before \AM@parse@toclisti was complete.
<to be read again> 
                   \par 
l.33 

수동

addtotoc Adds an entry to the table of contents. This option requires five
arguments, separated by commas:
addtotoc={hpage number i,hsection i,hlevel i,hheading i,hlabel i}

크리스티안의 제안 반복

pages=1및 로 구분할 필요가 없습니다 pages=2-. 링크의 일부 사소한 외관 변경

\documentclass{article}
\usepackage{pdfpages}
\usepackage[hidelinks]{hyperref}
\usepackage{xcolor}
\hypersetup{
    colorlinks,
    linkcolor={red!50!black},
    citecolor={blue!50!black},
    urlcolor={blue!80!black}
}
% https://tex.stackexchange.com/q/56316/13173
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt} % Werner, remove top margin border
% https://tex.stackexchange.com/a/338919/13173
\usepackage{letltxmacro}
\LetLtxMacro\oldincludepdf\includepdf
\renewcommand{\includepdf}[4][]{%
  \oldincludepdf[pagecommand={‌​\thispagestyle{fancy‌​}},addtotoc={#4,section,1,#2,#3}, #1]{#2}}

\begin{document}
\tableofcontents
\includepdf[pages=-,pagecommand=\thispagestyle{plain}]{8.pdf}{p1d8}{1}
\end{document}

OS: Debian 8.7
하드웨어: Asus Zenbook UX303UB
테스트 파일 7.pdf:http://www.texdoc.net/texmf-dist/doc/latex/pdfpages/pdfpages.pdf
테스트 파일 8.pdf:http://ctan.sharelatex.com/tex-archive/macros/latex/required/graphics/grfguide.pdf

답변1

옵션 addtotoc이 좀 까다롭네요!

addtotoc={page-number,sectiontype,level,heading,label}의 올바른 사용법은 addtotoc,

페이지 번호는 어디에 있나요?~ 해야 하다옵션 과 함께 제공된 페이지 번호와 일치하십시오 pages=.

  • 섹션 유형 은 등이 될 수 있습니다 section.subsection
  • level은 섹션 수준입니다. 즉, 1은 section, 2는 subsection등을 의미합니다. (평소와 마찬가지로)
  • 제목은 ToC에 나타나는 이름입니다.

  • label은 포함된 PDF 파일에 적용되는 레이블입니다(비워둘 수 있음).


및는 다음 파일로 생성되었으며 이름이 변경되었습니다 7.pdf.8.pdf

\documentclass{article}

\usepackage{blindtext}

\begin{document}
\section{Beginning \jobname}
\blindtext[50]
\end{document}

실행 코드는 다음과 같습니다.

\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref} % for links in TOC
% https://tex.stackexchange.com/q/56316/13173
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt} % Werner, remove top margin border
% https://tex.stackexchange.com/a/338919/13173
\usepackage{letltxmacro}
\LetLtxMacro\oldincludepdf\includepdf
\renewcommand{\includepdf}[4][]{%
  \oldincludepdf[pagecommand={‌​\thispagestyle{fancy‌​}},addtotoc={#4,section,1,#2,#3}, #1]{#2}}

\begin{document}

% TODO add custom labels to TOC 
\tableofcontents
% Pseudocode
% \addcontentsline{toc}{someLabelForPdf}{\listPdfBeginningLabels}

% TODO add here a label/... to the beginning of pdf page such that included in TOC
\includepdf[pages=1,pagecommand=\thispagestyle{plain}]{7.pdf}{firstpage7pdf}{1}
% No reference to the rest
\includepdf[pages=2-,pagecommand=\thispagestyle{plain}]{7.pdf}{remainingpages7pdf}{2}

% TODO reference here
\includepdf[pages=1,pagecommand=\thispagestyle{plain}]{8.pdf}{firstpage8pdf}{1}
% No reference to the rest
\includepdf[pages=2-,pagecommand=\thispagestyle{plain}]{8.pdf}{remainginpages8pdf}{2}

\end{document}

키-값 인터페이스로 업데이트

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

% Switch to expl3 - Syntax

% Define a storing place for the option values
\prop_new:N \l_leo_option_prop

% keys for the new functionality
\keys_define:nn {LEO} {%
   page .code:n = {\prop_put:Nnn \l_leo_option_prop {page} {#1}},
  section .code:n = {\prop_put:Nnn \l_leo_option_prop {section} {#1}},
  level .code:n = {\prop_put:Nnn \l_leo_option_prop {level} {#1}},
  heading .code:n = {\prop_put:Nnx \l_leo_option_prop {heading} {#1}},
  label .code:n = {\prop_put:Nnn \l_leo_option_prop {label} {#1}},
}

%  Keys setting 
\cs_new:Npn \SetupPdfInclude #1 {%
  \keys_set:nn {LEO} {#1}
}

% Get some key value 
\cs_new:Npn \retrieveoption #1 {%
  \prop_item:Nn \l_leo_option_prop {#1}
}

\ExplSyntaxOff


\usepackage{pdfpages}
\usepackage{hyperref} % for links in TOC
% https://tex.stackexchange.com/q/56316/13173
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt} % Werner, remove top margin border
% https://tex.stackexchange.com/a/338919/13173
\usepackage{letltxmacro}


\makeatletter
\LetLtxMacro\pdfpages@@includepdf\includepdf

\RenewDocumentCommand{\includepdf}{O{}mo}{%
  \begingroup
  \IfValueTF{#3}{% Is there a 3rd argument? Yes
    % Process the keys for the \includepdf first in order to get the value of 'pages=...' option
    % This is stored to \AM@pagestemp (see pdfpages.sty)
    \setkeys{pdfpages}{#1}%
    \SetupPdfInclude{label={label#2\AM@pagestemp},page={\AM@pagestemp}, heading={#2},#3}
    % Call the old command with the options for addtotoc
    \pdfpages@@includepdf[pagecommand={\thispagestyle{fancy}},addtotoc={\retrieveoption{page},\retrieveoption{section},\retrieveoption{level},\retrieveoption{heading},\retrieveoption{label}},#1]{#2}
  }{% No, no 3rd. argument}
    \pdfpages@@includepdf[pagecommand={\thispagestyle{fancy}},#1]{#2}
  }%
  \endgroup% Prevent leaking of key values to the next call of the command
}
\makeatother



% Set some default values
\SetupPdfInclude{page=1,section=section,level=1}

\begin{document}

% TODO add custom labels to TOC 
\tableofcontents
% Pseudocode
% \addcontentsline{toc}{someLabelForPdf}{\listPdfBeginningLabels}

\includepdf[pagecommand=\thispagestyle{plain}]{7.pdf}[label=firstpage7pdf]
\includepdf[pages=2-,pagecommand=\thispagestyle{plain}]{7.pdf}[page=2,heading={\retrieveoption{heading} continued}]

\includepdf[pages=1,pagecommand=\thispagestyle{plain}]{8.pdf}[label=firstpage8pdf]
\includepdf[pages=2-,pagecommand=\thispagestyle{plain}]{8.pdf}[heading={\retrieveoption{heading} continued}]

\end{document}

여러 키-값은 옵션의 항목에 해당하며 addtotoc, 정확한 순서가 사용 사양이 아닌 코드에 의해 수행된다는 장점이 있습니다.

기본적으로 의 heading필수 인수 \includepdf(예: ) 를 사용합니다 #2.

관련 정보