如何在 LaTeX 中的 \include 之后没有分页符

发布于 2024-07-29 22:31:17 字数 188 浏览 5 评论 0原文

我的 LaTeX 在每个小节之后都会分页,因为我的小节位于单独的文件中。 我使用命令 \include{file} 在使用后添加分页符。

我希望不会因使用 \include{file} 而导致分页。

使用 include 命令后如何不分页?

My LaTeX makes me pagebreaks after each subsection because my subsections are in separate files. I use the command \include{file} which adds a pagebreak after the use of it.

I would like to have no pagebreak caused by the use of \include{file}.

How can you no pagebreak after the use of include -command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

破晓 2024-08-05 22:31:17

Will Robertson 建议的 newinclude 包对于避免清除页面非常有用。 看来,为了让 \includeonly 工作,必须在 \documentclass{...} 之后立即调用该包。 在我的论文的复杂环境中,我也遇到了参考文献损坏的问题。

当最终版本不需要 includeonly 时,一个好的解决方法是仅在草稿中使用 include:

\newif\ifdraft\drafttrue

\newif\ifdraft\draftfalse

\ifdraft
  \include{...}
\fi

\ifdraft
  \include{file}
\else
  \input{file}
\fi

第一行可以轻松地由 makefile 附加,以制作草稿或生产版本的生产 make 目标。

\includeonly{file1,file2,...} 允许指定使用 \include{file1} 调用的源文件列表(其中 file1是一个示例),它将显示在结果文档中。 其他的不会显示,但当包含相应的辅助文件时,会考虑将其用于计数器、标签、目录。

换句话说,通过使用 includeincludeonly 可以在草稿中保持较短的编译时间,同时拥有正确的引用。
进一步阅读维基教科书

@Will Robertson

\include 非常有用,因为它允许通过 \includeonly{...} 只构建需要的部分。 在处理较长的文本时,仅包含冗长章节的一部分可能会在编译时间上产生很大的差异。 它也非常有用,因为人们在工作时不必翻阅长草稿。 最后,较小的源代码文件更容易在版本管理中处理,例如 git。

The newclude package suggested by Will Robertson is rather useful to avoid the clearpage. It appears, in order for \includeonly to work one has to call the package immediately after \documentclass{...}. In the complex environment of my dissertation I also ran into problems with broken references.

A good workaround, when includeonly is not needed for a final version, is to use includes only in the draft:

\newif\ifdraft\drafttrue

or

\newif\ifdraft\draftfalse

\ifdraft
  \include{...}
\fi

\ifdraft
  \include{file}
\else
  \input{file}
\fi

The first line can be easily appended by a makefile, to make draft or production version production make targets.

\includeonly{file1,file2,...} allows to specify a list of source files called with \include{file1} (where file1 is an example) that will show in the resulting document. The others will not show up, but are considered for counters, labels, tables of contents when the corresponding aux files are included.

In other words, by using include and includeonly one can keep the compile time short in a draft while having correct references.
Further reading on Wikibooks.

@Will Robertson

\include is so useful because it allows through \includeonly{...} to build only needed sections. While working on longer text it can make quite a difference in compile time to include only a section of a lengthy chapter. It is also invaluably useful as one doesn't have to page through a long draft while working at one point. Lastly, smaller files of source code are easier to handle in version management, e.g. git.

[浮城] 2024-08-05 22:31:17

\include 始终使用 \clearpage,这是一个不完全合理的默认值。 它适用于整个章节,而不是小节(为什么要将小节放在单独的文件中?)。

您可以通过使用 \input{filename} 或加载 newinclude 包并写入 \include*{filename} 来修复此问题。

\include always uses \clearpage, a not entirely sensible default. It is intended for entire chapters, not for subsections (why would you want subsections in separate files, anyway?).

You can fix it either by using \input{filename} or loading the newclude package and writing \include*{filename} instead.

云之铃。 2024-08-05 22:31:17

您可以通过在 \include 前面放置 \let\clearpage\relax 来阻止由 \include 引起的分页。 因此,

\let\clearpage\relax
\include{file1}
\include{file2}
\include{file3}

会将三个文件(以及任何随后包含的文件)的内容放在一起,并且它们之间没有分页符。 如果您想停止放宽 \clearpage 命令,则将文件包装在不带分页符的组中,如下所示:

\begingroup
\let\clearpage\relax
\include{file1}
\include{file2}
\endgroup
\include{file3}

这将停止 file1 和 file2 之间的分页符,但在 file2 之后插入正常分页符。 (注意:我不知道这是否会干扰引用和页码,尽管我认为应该没问题。)

You can stop pagebreaks caused by \include by placing \let\clearpage\relax before it. So,

\let\clearpage\relax
\include{file1}
\include{file2}
\include{file3}

would put the contents of the three files (and any subsequently included files) together without a pagebreak between them. If you want to stop relaxing the \clearpage command, then wrap the files to include without pagebreaks within a group like this:

\begingroup
\let\clearpage\relax
\include{file1}
\include{file2}
\endgroup
\include{file3}

This will stop a pagebreak between file1 and file2, but insert the normal pagebreak after file2. (Note: I do not know if this interferes with referencing and page numbering, though I imagine it should be OK.)

云仙小弟 2024-08-05 22:31:17

以下内容在大多数情况下都是可靠的:

\cleardoublepage
\begingroup
\let\clearpage\relax
\include{./common/yourFile.tex}
\endgroup

第一个 \cleardoublepage 确保您的章节最终位于双面的奇数页上。

\let\clearpage\relax 禁用由 \include 插入的clearpage

\begingroup \endgroup 确保范围仅限于 include。

The following is robust in most situations:

\cleardoublepage
\begingroup
\let\clearpage\relax
\include{./common/yourFile.tex}
\endgroup

The first \cleardoublepage ensures that your chapter ends up on an odd page for 2-sided.

The \let\clearpage\relax disables clearpage inserted by \include

The \begingroup \endgroup makes sure that the scope is just that include.

记忆消瘦 2024-08-05 22:31:17

谢谢您,剑桥

使用 \include 代替 \input,并使用 \includeonly 命令选择要处理的部分

Thank you, Cambridge!

use \include instead of \input, and use the \includeonly command to select sections to process

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文