简要说明所需变更

简要说明所需变更

我正在尝试制作一个文档,其中第一页有一个文本框,文档的其余部分则采用我喜欢的风格。

我尝试过,如果我创建两个不同的文档(也就是两个不同的 tex 文件),我就可以做到这一点。在第一个中,我使用了

\usepackage[paperwidth=16cm,paperheight=24cm]{geometry}
\usepackage[a4,frame,center]{crop}

在第二个中我使用了:

\documentclass[a4paper,twoside]{report}
\pagestyle{fancy}

有什么办法可以只做一份文档吗?

答案1

简要说明所需变更

  • 页面样式:您可以使用 轻松更改单个页面的页面样式\thispagestyle{style},或使用宏 更改所有后续页面的页面样式\pagestyle{style},这两个宏均来自fancyhdr-package。

  • 布局-package使得使用其命令和原始设置来geometry更改页面的边距、文本宽度、高度等变得相当容易。\newgeometry{arguments}\restoregeometry

  • 纸张尺寸 在文档中间更改纸张大小更加困难,为了进行这些更改,我一直在使用在答案中找到的信息查尔斯·斯图尔特在文中在文档中间更改纸张尺寸。那里还有其他替代答案,值得一读。


我所做的是首先设置一个标准页面大小,然后将该页面的尺寸存储到所调用的长度中\originalPaperWidth\originalPaperHeight以便能够将页面恢复到该尺寸。

用法

我创建了两个宏,\changePaper{width}{height}[optional arguments for \newgeometry]\restorePaper,这样可以轻松创建自定义页面。将其与\thispagestyle{style}或结合使用\pagestyle{style}

输出

enter image description here

代码

\documentclass[a4paper,11pt]{article}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{xparse} % Needed for newdocumentcommand
\usepackage{lipsum}
%\usepackage{showframe}

\pagestyle{fancy}

\newlength{\originalPaperHeight}
\newlength{\originalPaperWidth}
\setlength{\originalPaperHeight}{\pdfpageheight}
\setlength{\originalPaperWidth}{\pdfpagewidth}

\newcommand{\restorePaperSize}{%
\clearpage%
\pdfpagewidth=\originalPaperWidth \pdfpageheight=\originalPaperHeight
\restoregeometry
}

\NewDocumentCommand{\changePaper}{mmO{}}{%
    % Input:
    % #1: width
    % #2: height
    % #3: optional arguments for \newgeometry
    \pdfpagewidth=#1 \pdfpageheight=#2
\newgeometry{layoutwidth=#1,layoutheight=#2,#3}
    }
\begin{document}
\thispagestyle{empty}
\changePaper{16cm}{23cm}[margin=1cm,top=2cm]
\section{Special page}
\lipsum[1-2]
\restorePaperSize
\section{Back to normal fancy pages}
\lipsum[3-5]
\end{document}

相关内容