在 \documentclass 中声明选项 a4paper 产生的边距与在 \geometry 中声明该选项产生的边距不同

在 \documentclass 中声明选项 a4paper 产生的边距与在 \geometry 中声明该选项产生的边距不同

我在a4paper,我应该在哪里声明它?在文档类中还是几何中?\documentclass[a4paper]{article}并且那里选择的答案暗示我们是否使用或是否使用没有区别\usepackage[a4paper]{geometry}

但我的观察与所选的答案相矛盾。

这是我在文件中的代码foo.tex

\documentclass[a4paper]{article}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nec
lobortis justo. Praesent ut scelerisque risus, sit amet mollis erat.
Fusce at lacus at libero consequat consectetur.

Proin at vehicula ligula. Vivamus quis ligula id lacus aliquet
ultricies. Vivamus tristique, velit vestibulum tincidunt fermentum,
lacus sem euismod risus, ut volutpat augue dolor vitae est. Proin odio
nunc, sollicitudin quis nisi a, sodales efficitur quam. Phasellus ex
velit, porttitor vestibulum consectetur eu, maximus et nisi.

Nulla pharetra augue ex, quis scelerisque sem iaculis id. Aliquam in
tincidunt quam. Praesent ac laoreet elit. Aenean varius ullamcorper
dolor ac finibus. Proin est sapien, tempor nec mollis ut, ultricies et
ante. Maecenas hendrerit velit non augue rutrum, mollis pharetra nisl
auctor. Ut nisl mauris, porta ut nisi ut, elementum tristique nibh. 
\end{document}

这是文件中的另一个bar.tex。这里唯一不同的是使用\usepackage[a4paper]{geometry}而不是\documentclass[a4paper]{article}

\documentclass{article}
\usepackage[a4paper]{geometry}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nec
lobortis justo. Praesent ut scelerisque risus, sit amet mollis erat.
Fusce at lacus at libero consequat consectetur.

Proin at vehicula ligula. Vivamus quis ligula id lacus aliquet
ultricies. Vivamus tristique, velit vestibulum tincidunt fermentum,
lacus sem euismod risus, ut volutpat augue dolor vitae est. Proin odio
nunc, sollicitudin quis nisi a, sodales efficitur quam. Phasellus ex
velit, porttitor vestibulum consectetur eu, maximus et nisi.

Nulla pharetra augue ex, quis scelerisque sem iaculis id. Aliquam in
tincidunt quam. Praesent ac laoreet elit. Aenean varius ullamcorper
dolor ac finibus. Proin est sapien, tempor nec mollis ut, ultricies et
ante. Maecenas hendrerit velit non augue rutrum, mollis pharetra nisl
auctor. Ut nisl mauris, porta ut nisi ut, elementum tristique nibh.
\end{document}

foo.pdf但两个文件的输出不同。以下是左右两图的并排比较bar.pdf

我有三个问题:

答案1

geometry改变布局(除非您使用选项传递)。

geometry因此带有 的文件和不带有 的文件是有区别的geometry

但如果你加载几何图形,那么a4paper设置

\documentclass[a4paper]{article}
\usepackage{geometry}

\documentclass{article}
\usepackage[a4paper]{geometry}

答案2

我认为看出差异的最清楚的方法是使用包来layout显示当前的书写区域和边距以及文档的几毫米长度。

请看此代码

\documentclass[a4paper]{article}

\usepackage{layout}
% from https://tex.stackexchange.com/questions/173244/to-display-the-lengths-in-millimeters-by-default
\makeatletter
\renewcommand*{\lay@value}[2]{%
  \strip@pt\dimexpr0.351459\dimexpr\csname#2\endcsname\relax\relax mm%
}
\makeatother


\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nec
lobortis justo. Praesent ut scelerisque risus, sit amet mollis erat.
Fusce at lacus at libero consequat consectetur.

Proin at vehicula ligula. Vivamus quis ligula id lacus aliquet
ultricies. Vivamus tristique, velit vestibulum tincidunt fermentum,
lacus sem euismod risus, ut volutpat augue dolor vitae est. Proin odio
nunc, sollicitudin quis nisi a, sodales efficitur quam. Phasellus ex
velit, porttitor vestibulum consectetur eu, maximus et nisi.

Nulla pharetra augue ex, quis scelerisque sem iaculis id. Aliquam in
tincidunt quam. Praesent ac laoreet elit. Aenean varius ullamcorper
dolor ac finibus. Proin est sapien, tempor nec mollis ut, ultricies et
ante. Maecenas hendrerit velit non augue rutrum, mollis pharetra nisl
auctor. Ut nisl mauris, porta ut nisi ut, elementum tristique nibh. 
\clearpage
\layout
\end{document}

以及最终的布局:

在此处输入图片描述

现在请将上面的结果与此代码进行比较

\documentclass{article}

\usepackage[a4paper]{geometry}
\usepackage{layout}
% from https://tex.stackexchange.com/questions/173244/to-display-the-lengths-in-millimeters-by-default
\makeatletter
\renewcommand*{\lay@value}[2]{%
  \strip@pt\dimexpr0.351459\dimexpr\csname#2\endcsname\relax\relax mm%
}
\makeatother


\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nec
lobortis justo. Praesent ut scelerisque risus, sit amet mollis erat.
Fusce at lacus at libero consequat consectetur.

Proin at vehicula ligula. Vivamus quis ligula id lacus aliquet
ultricies. Vivamus tristique, velit vestibulum tincidunt fermentum,
lacus sem euismod risus, ut volutpat augue dolor vitae est. Proin odio
nunc, sollicitudin quis nisi a, sodales efficitur quam. Phasellus ex
velit, porttitor vestibulum consectetur eu, maximus et nisi.

Nulla pharetra augue ex, quis scelerisque sem iaculis id. Aliquam in
tincidunt quam. Praesent ac laoreet elit. Aenean varius ullamcorper
dolor ac finibus. Proin est sapien, tempor nec mollis ut, ultricies et
ante. Maecenas hendrerit velit non augue rutrum, mollis pharetra nisl
auctor. Ut nisl mauris, porta ut nisi ut, elementum tristique nibh. 
\clearpage
\layout
\end{document} 

及其结果([a4paper]是包的选项geometry):

在此处输入图片描述

\textheight你看到和 的长度不同了\textwidth吗?这最终意味着和类geometry使用的标准边距不同。articlegeometry

现在请看一下此代码,[a4paper]其中仅将选项放置为类选项article

\documentclass[a4paper]{article}

\usepackage{geometry}
\usepackage{layout}
% from https://tex.stackexchange.com/questions/173244/to-display-the-lengths-in-millimeters-by-default
\makeatletter
\renewcommand*{\lay@value}[2]{%
  \strip@pt\dimexpr0.351459\dimexpr\csname#2\endcsname\relax\relax mm%
}
\makeatother


\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nec
lobortis justo. Praesent ut scelerisque risus, sit amet mollis erat.
Fusce at lacus at libero consequat consectetur.

Proin at vehicula ligula. Vivamus quis ligula id lacus aliquet
ultricies. Vivamus tristique, velit vestibulum tincidunt fermentum,
lacus sem euismod risus, ut volutpat augue dolor vitae est. Proin odio
nunc, sollicitudin quis nisi a, sodales efficitur quam. Phasellus ex
velit, porttitor vestibulum consectetur eu, maximus et nisi.

Nulla pharetra augue ex, quis scelerisque sem iaculis id. Aliquam in
tincidunt quam. Praesent ac laoreet elit. Aenean varius ullamcorper
dolor ac finibus. Proin est sapien, tempor nec mollis ut, ultricies et
ante. Maecenas hendrerit velit non augue rutrum, mollis pharetra nisl
auctor. Ut nisl mauris, porta ut nisi ut, elementum tristique nibh. 
\clearpage
\layout
\end{document}

[a4paper]及其结果。您会看到,它的长度结果与我们仅使用选项后得到的结果相同geometry

在此处输入图片描述

因此结论是使用选项a4paper作为类选项,因为如果它与它们相关,所有其他包都会注意到此选项......

article使用除之外的其他标准边距geometry,这就是您获得差异的原因。

答案3

输出不同,因为geometry更新布局(库存边距)除了页面大小之外。相比之下,加载文档类(例如)article只会a4paper更改纸张尺寸。请参阅几何包的默认边距

以下是\documentclass[a4paper]{article}

\DeclareOption{a4paper}
   {\setlength\paperheight {297mm}%
    \setlength\paperwidth  {210mm}}

我更喜欢使用包加载任何与几何相关的设置,因为这就是您加载它的目的。也就是说,使用以下序列:

\usepackage{geometry}
\geometry{
  % <geometry settings>
}

相关内容