问题描述
如果全文都只是对应一个 tex
文件的话,很显然这个会带来很多管理方面的麻烦,因为行数太多了,本来已经确定第一章节了,但是写第二章节的时候还总要看第一章节的 tex 文字,就比较不清爽。
更重要的是,如果我需要写的不是一片论文而是一本书,那么如果只是一个 tex 文件,那也太麻烦了。每次寻找自己的章节都需要花费很多时间。
分章节编写目标
总共 6 个章节以及附录,我们除了一个 main.tex ,对应的还有 7 个 tex 文件一一对应 6 个章节和附录。
解决方法
核心方法很简单:使用 \include
关键字,其他的拆解就是正常的拆解。
这里我们以 elegantbook
为例,可以前去下载 https://www.overleaf.com/latex/templates/elegantbook-template/zpsrbmdsxrgy , 它总共 6 个章节,1 个附录,但是却对应的是一个 tex 文件,我们现在进行拆解,拆解后的文件夹如图所示:
接着对应的 section1 ~ section6 以及 appendix 都是从原来的 elegantbook
中摘录出来的,我们需要最外层的 elegantbook-cn.tex 中引用这 7 个文件即可。
\documentclass[lang=cn,10pt]{elegantbook}
\title{ElegantBook:优美的 \LaTeX{} 书籍模板}
\subtitle{Elegant\LaTeX{} 经典之作}
\author{Ethan Deng \& Liam Huang}
\institute{Elegant\LaTeX{} Program}
\date{April 9, 2022}
\version{4.3}
\bioinfo{自定义}{信息}
\extrainfo{不要以为抹消过去,重新来过,即可发生什么改变。—— 比企谷八幡}
\setcounter{tocdepth}{3}
\logo{logo-blue.png}
\cover{cover.jpg}
% 本文档命令
\usepackage{array}
\newcommand{\ccr}[1]{\makecell{{\color{#1}\rule{1cm}{1cm}}}}
% 修改标题页的橙色带
% \definecolor{customcolor}{RGB}{32,178,170}
% \colorlet{coverlinecolor}{customcolor}
\begin{document}
\maketitle
\frontmatter
\tableofcontents
\mainmatter
\input{sections/section1}
\input{sections/section2}
\input{sections/section3}
\input{sections/section4}
\input{sections/section5}
\input{sections/section6}
\nocite{*}
\printbibliography[heading=bibintoc, title=\ebibname]
\appendix
\input{sections/appendix}
\end{document}
最后对这个文件进行编译即可生成与原版一模一样的pdf文件了。
源码
所有的源码都上传到 gitee 中,请前去下载或clone。地址为:https://gitee.com/smile-yan/elegantbook-cn-chapter
总结
latex 编写文档更加合理,比word更加舒服,推荐感兴趣的小伙伴们可以多了解了解。
Smileyan
2023.03.31 20:20