combine
我包含了一个使用带有选项的类的MWE(一个主文件和三篇文章)book
。有两个问题。格式化过程会产生 LaTeX 错误:环境摘要未定义,并且格式化在\begin{abstract}
第一个输入文件中的第一个命令处停止。按“r”继续格式化过程。除了输入文章文档中的章节编号(0.1、0.2......而不是 1、2......)之外,生成的 PDF 几乎正确。文章文档\setcounter{section}{0}
在序言中包含命令。如果我book
用替换,文件格式report
会发生变化,但章节编号问题仍然存在。主文档是我需要的一个准确示例(一本包含部分的书、几个没有输入文件的章节和几个有输入文件的章节。)所有输入文件都使用文章文档类。我在 Windows 7 上使用 MiKTeX 2.9。
\documentclass[book]{combine}
\usepackage[english]{babel}
\usepackage{blindtext}
\title{The collection}
\author{A. N. Editor}
\begin{document}
\maketitle
\tableofcontents
\part{First part}
\blindtext[1]
\chapter{First chapter}
\section{Introduction}
\blindtext[1]
\chapter{Second chapter}
\section{Introduction}
\ldots
\begin{papers}
\coltoctitle{First article}
\coltocauthor{Author of first article}
\import{inputDoc1}
\coltoctitle{Second article}
\coltocauthor{Author of second article}
\import{inputDoc2}
\end{papers}
\chapter{Third chapter}
\section{Introduction}
\ldots
\begin{papers}
\coltoctitle{Third article}
\coltocauthor{Author of third article}
\import{inputDoc3}
\end{papers}
\chapter{Chapter 4}
\section{Final introduction}
\end{document}
%first article
\documentclass[]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\title{First article}
\author{Author of first article}
\maketitle
\begin{abstract}
\blindtext[2]
\end{abstract}
\section{first section}
\blindtext[3]
\end{document}
%second article
\documentclass[]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\setcounter{section}{0}
\begin{document}
\title{Second article}
\author{Author of second article}
\maketitle
\begin{abstract}
\blindtext[1]
\end{abstract}
\section{first section}
\blindtext[1]
\end{document}
%third article
\documentclass[]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\setcounter{section}{0}
\begin{document}
\title{Document 1a}
\author{Author of document 1a}
\maketitle
\begin{abstract}
\blindtext[3]
\end{abstract}
\section{first section}
\blindtext[1]
\section{second section}
\blindtext[1]
\end{document}
答案1
由于您只导入文章,而article
文档类未定义,\chapter
因此您将获得0
每个导入文章的章节的值。正如@Papiro 指出的那样,您可以使用来避免显示章节计数器\renewcommand*\thesection{\arabic{section}}
。但是,这样一来,您将失去主文档中各节的格式\thechapter.\thesection
,而这对我来说是没问题的。
下面我介绍了其他保留格式的解决方案\thechapter.\thesection
(无需\makeatletter \@ifclassloaded{combine}{\renewcommand*\thesection{\arabic{savechapter}.\arabic{section}}}{}\makeatother
在每次输入文章时添加)。
\documentclass[book]{combine}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{filecontents}
\usepackage{etoolbox}
\newcounter{savechapter}
\AtBeginEnvironment{papers}{\setcounter{savechapter}{\value{chapter}}}
\makeatletter
\let\oldimport\import
\renewcommand*{\import}{\renewcommand*\thesection{\arabic{savechapter}.\arabic{section}}\oldimport}
\makeatother
% The input articles
\begin{filecontents*}{inputDoc1.tex}
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\title{First article}
\author{Author of first article}
\maketitle
\begin{abstract}
\blindtext[2]
\end{abstract}
\section{first section}
\blindtext[3]
\section{Second section}
\end{document}
\end{filecontents*}
\begin{filecontents*}{inputDoc2.tex}
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\title{Second article}
\author{Author of second article}
\maketitle
\begin{abstract}
\blindtext[1]
\end{abstract}
\section{first section}
\blindtext[1]
\end{document}
\end{filecontents*}
\begin{filecontents*}{inputDoc3.tex}
\makeatother
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\setcounter{section}{1}
\begin{document}
\title{Document 1a}
\author{Author of document 1a}
\maketitle
\begin{abstract}
\blindtext[3]
\end{abstract}
\section{first section}
\blindtext[1]
\section{second section}
\blindtext[1]
\end{document}
\end{filecontents*}
% Define abstract to be used in book class (or use report)
% http://tex.stackexchange.com/questions/51483/how-to-write-abstract-and-acknowledgement-in-book-format
\makeatletter
\if@titlepage
\newenvironment{abstract}{%
\titlepage
\null\vfil
\@beginparpenalty\@lowpenalty
\begin{center}%
\bfseries \abstractname
\@endparpenalty\@M
\end{center}}%
{\par\vfil\null\endtitlepage}
\else
\newenvironment{abstract}{%
\if@twocolumn
\section*{\abstractname}%
\else
\small
\begin{center}%
{\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
\end{center}%
\quotation
\fi}
{\if@twocolumn\else\endquotation\fi}
\fi
\makeatother
% The main document
\begin{document}
\title{The collection}
\author{A. N. Editor}
\date{\today}
\maketitle
\begin{abstract}
\blindtext[1]
\end{abstract}
\tableofcontents
\part{First part}
\blindtext[1]
\chapter{First chapter}
\section{Introduction}
\blindtext[1]
\chapter{Second chapter}
\section{Introduction}
\ldots
\begin{papers}
\coltoctitle{First article}
\coltocauthor{Author of first article}
\import{inputDoc1}
\coltoctitle{Second article}
\coltocauthor{Author of second article}
\import{inputDoc2}
\end{papers}
\chapter{Third chapter}
\section{Introduction}
\ldots
\begin{papers}
\coltoctitle{Third article}
\coltocauthor{Author of third article}
\import{inputDoc3}
\end{papers}
\chapter{Chapter 4}
\section{Final introduction}
\end{document}