根据纸张尺寸设定文本高度

根据纸张尺寸设定文本高度

如何使文档中的文本高度根据所选的纸张尺寸(信纸或 A4)动态变化。

\documentclass[a4paper]{article}

    \setlength{\textheight}{9.2in} % change this value based on a4paper option

\begin{document}
     text....
\end{document}

答案1

您可以在文档类选项中检查。如果找到匹配项,\pdfmatch则返回 1:a4paper\pdfmatch

\documentclass[a4paper]{article}

\makeatletter
% Check if a4paper options was passed in class option list
\ifnum\pdfmatch{a4paper}{\@classoptionslist}=1
  \setlength{\textheight}{9.2in}
\fi
\makeatother

\begin{document}
text....
\end{document}

答案2

您可以使用以下方法测试页面大小

\ifdim\paperheight=297mm \textheight=9.21in\fi% note the space

其中(来自 article.cls)

\DeclareOption{a4paper}
   {\setlength\paperheight {297mm}%
    \setlength\paperwidth  {210mm}}
\DeclareOption{a5paper}
   {\setlength\paperheight {210mm}%
    \setlength\paperwidth  {148mm}}
\DeclareOption{b5paper}
   {\setlength\paperheight {250mm}%
    \setlength\paperwidth  {176mm}}
\DeclareOption{letterpaper}
   {\setlength\paperheight {11in}%
    \setlength\paperwidth  {8.5in}}
\DeclareOption{legalpaper}
   {\setlength\paperheight {14in}%
    \setlength\paperwidth  {8.5in}}
\DeclareOption{executivepaper}
   {\setlength\paperheight {10.5in}%
    \setlength\paperwidth  {7.25in}}
\DeclareOption{landscape}
   {\setlength\@tempdima   {\paperheight}%
    \setlength\paperheight {\paperwidth}%
    \setlength\paperwidth  {\@tempdima}}

相关内容