将外部目录插入另一个文档

将外部目录插入另一个文档

如何将一个文档的目录插入到另一个LaTeX文档中?如果可以的话。在第一个文档中,ToC使用\tableofcontents

根据评论编辑: (部分)MWE:

\documentclass[%
 paper=A4, twoside=true, openright, parskip=full, chapterprefix=true,
 11pt, headings=normal, bibliography=totoc, listof=totoc,
 titlepage=on, captions=tableabove, draft=false,
 ]{scrreprt}
\usepackage[utf8]{inputenc}     
\usepackage[english]{babel}   
\usepackage[                    
    figuresep=colon,
    sansserif=false,
    hangfigurecaption=false,
    hangsection=true,
    hangsubsection=true,
    colorize=full,
    colortheme=bluemagenta,
]{cleanthesis}

\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{tabularx}
\usepackage{epstopdf}
\usepackage{placeins}
\usepackage{float}
\usepackage{amssymb}
\usepackage{color}
\restylefloat{figure}
\usepackage{tablefootnote}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\lstset{breakatwhitespace=false}
\usepackage{courier}
\usepackage{appendix}
\usepackage{booktabs}
\usepackage{eso-pic}
\usepackage{pbox}
\usepackage{ragged2e}
\usepackage{adjustbox}
\usepackage{graphicx} %allows for including images
\usepackage{biblatex}
\addbibresource{bib-refs}
\usepackage{pdfpages}
\usepackage{subcaption}
\usepackage{xcolor,colortbl}
\usepackage{multirow}

.toc文件:

\boolfalse {citerequest}
\boolfalse {citetracker}
\boolfalse {pagetracker}
\boolfalse {backtracker}\relax 
\defcounter {refsection}{0}\relax
\select@language {english}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{\numberline {1}Introduction}{1}{chapter.1} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.1} Expansion Project}{1}{section*.11} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.2} Safety Management}{2}{section*.12} 
\defcounter {refsection}{0}\relax

答案1

可以包含外部.toc文件,但是很繁琐并且可用性有限,因为页码等很可能不一致。

显示的.toc文件是用 制作的hyperref,这使整个问题变得复杂。

但这里有一种方法:

\documentclass[%
 paper=A4, twoside=true, openright, parskip=full, chapterprefix=true,
 11pt, headings=normal, bibliography=totoc, listof=totoc,
 titlepage=on, captions=tableabove, draft=true,final=false
 ]{scrreprt}
\usepackage[utf8]{inputenc}     
\usepackage[english]{babel}   
\usepackage[                    
    figuresep=colon,
    sansserif=false,
    hangfigurecaption=false,
    hangsection=true,
    hangsubsection=true,
    colorize=full,
    colortheme=bluemagenta,
]{cleanthesis}

\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{epstopdf}
\usepackage{placeins}
\usepackage{float}
\usepackage{amssymb}
\restylefloat{figure}
\usepackage{tablefootnote}
%
\usepackage{courier}
\usepackage{appendix}
\usepackage{booktabs}
\usepackage{eso-pic}
\usepackage{pbox}
\usepackage{ragged2e}
\usepackage{adjustbox}
\usepackage{graphicx} %allows for including images
\usepackage{biblatex}
\addbibresource{bib-refs}
\usepackage{pdfpages}
\usepackage{subcaption}
\usepackage{xcolor,colortbl}
\usepackage{multirow}

\usepackage{hyperref}
\usepackage{cleveref}


%\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
%\lstset{breakatwhitespace=false}


\newcommand{\othercontentsname}{%
  Secondary Contents%
}

% now some code that resembles the `\@starttoc` command 
\makeatletter
\newcommand{\usetocfromothersource}[1]{%
  \begingroup
  \makeatletter
  \IfFileExists{#1}{%
    \chapter*{\othercontentsname}%
    \@input{#1}% 
    \@nobreakfalse
  }{}%
  \makeatother
  \endgroup
}
\makeatother


\begin{document}
\tableofcontents

\usetocfromothersource{otherdoc.toc}

\part{Some part}
\chapter{Foo}




\end{document}

还有otherdoc.toc

\boolfalse {citerequest}%
\boolfalse {citetracker}
\boolfalse {pagetracker}
\boolfalse {backtracker}\relax 
\defcounter {refsection}{0}\relax
\select@language {english}
\defcounter {refsection}{0}\relax 
\contentsline {chapter}{\numberline {1}Introduction}{1}{chapter.1} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.1} Expansion Project}{1}{section*.11} 
\defcounter {refsection}{0}\relax 
\contentsline {section}{\numberline {1.2} Safety Management}{2}{section*.12} 
\defcounter {refsection}{0}\relax

请注意,mcode更改章节标题等似乎与不兼容KOMA

在此处输入图片描述

相关内容