提问于:
浏览数:
2277
## 编译环境
操作系统
* [x] Windows 7/8/10
* [ ] macOS
* [ ] Linux
`若需勾选,请把[ ]改成[x]`
Tex发行版
* [x] TexLive `2020`
* [ ] MikTeX `版本号`
* [ ] CTeX
`若需勾选,请把[ ]改成[x]`
## 我的问题
总的来说,就是两个问题:
1. 为什么`\include`命令不能加后缀?根据[lshort-zh-cn](http://mirrors.ctan.org/info/lshort/chinese/lshort-zh-cn.pdf)中所给的例子:

该命令应当是使用文件的路径,而对于tex文件是可以省去的,但在我这里出现的问题是,添加后缀后文件编译出现问题,而不使用后缀的话能够正常编译。
2. 为什么`\include`之后那个LastPage的label会失效呢?
我猜测可能的原因是`\include`命令是相当于这个:
```
\clearpage
\input{}
\clearpage
```
然后刚好那个label贴在`\clearpage`上面,就没了,所以又有个衍生的问题,为啥label贴在`\clearpage`上面会没了呢?
求各位大佬解答,十分感谢!
## 事发流程
> 下面是详细的经过
我在一个全英文路径下,创建了两个文件,分别是:
```
%test.tex
\documentclass{article}
\begin{document}
This is a \LaTeX \ file.
The LastPage is Page \pageref{LastPage}
\input{anotherfile.tex}
%\include{anotherfile.tex}
\label{LastPage}
\end{document}
```
```
%anotherfile.tex
This is anotherfile.
```
补充一下文件结构,是这样的:

用pdflatex编译两次后,我得到了满意的结果:

但是,当我把第一个文件改成这样的时候:
```
%test.tex
\documentclass{article}
\begin{document}
This is a \LaTeX \ file.
The LastPage is Page \pageref{LastPage}
%\input{anotherfile.tex}
\include{anotherfile.tex}
\label{LastPage}
\end{document}
```
编译两次,输出没了第二个文件的内容,同时LastPage变成无定义的了。

然后,我再修改一下:
```
%test.tex
\documentclass{article}
\begin{document}
This is a \LaTeX \ file.
The LastPage is Page \pageref{LastPage}
%\input{anotherfile.tex}
\include{anotherfile}
\label{LastPage}
\end{document}
```
多了一页,放上了第二个文件的内容,但是LastPage依然无定义:

2 回答
0
`\include`会另起一页。可以将`\label{LastPage}`放在另一个文件里。
0
首先你的猜测是对的, 在 `texdoc latex2e` 的 24.2 节有提到

另外就您的问题我在 TEX.SX 上提了一个问题, [链接]( https://tex.stackexchange.com/questions/582431/it-appears-a-when-i-put-label-after-clearpage)在这里.
简要的描述一下原因: 因为你在使用 `\clearpage` 的时候, 并没有真的一页输出出来, 你需要让这一页出现, 即使用
```latex
\documentclass{article}
% \usepackage{lastpage}
\begin{document}
this is main file. \pageref{LastPage}
\clearpage
\null
\label{LastPage}
\end{document}
```
来让最后的 `\label` 生效.
另外, 在最新的 [`lshort-zh-cn`](https://github.com/CTeX-org/lshort-zh-cn) 中已经修改了这一部分内容

你的回答
请登录后回答
你的回答将会帮助更多人,请务必认真回答问题。