如何使文档自定义页面尺寸?

如何使文档自定义页面尺寸?

我看到过 a4paper、a5paper、letterpaper 等选项,它们位于 \documentclass 后的方括号中,但我想要的是,一个文档的宽度为 8.25 英寸,高度为 10.75 英寸,另一个文档的宽度为 6 英寸,高度为 9 英寸。如何实现?

答案1

希望代码是不言自明的。

首先,

\documentclass{article}
\usepackage{blindtext}
\usepackage[paperheight=10.75in,paperwidth=8.25in,margin=1in,heightrounded,showframe]{geometry}
\begin{document}

\Blinddocument

\end{document}

第二:

\documentclass{article}
\usepackage{blindtext}
\usepackage[paperheight=9in,paperwidth=6in,top=1in,bottom=1in,right=1in,left=1in,heightrounded,showframe]{geometry}
\begin{document}

\Blinddocument

\end{document}

答案2

这是不使用包的方法:

\pdfpagewidth 8.25in
\pdfpageheight 10.75in

答案3

geometry 包版本 2020/01/02 v5.9 现在具有命令 ''heightrounded'',它可以为您计算 ''\textheight'' 中的整数行数。因此,建议如果您更改 ''\baselineskip'',请在调用 geometry 之前完成此操作:

\documentclass[11pt,openany]{book}  % XeLatex. pdf output.
  \author{Page Paperton}
  \date{2021 Sep}
  \title{A Custom Paper Size Template}
  \usepackage{comment,kantlipsum,verbatim}
  \usepackage{calc}
  \usepackage{fontspec}
  \setmainfont[Mapping=tex-text]{Minion Pro}
  \newlength{\OriginalBaselineSkip}
  \setlength{\OriginalBaselineSkip}{\baselineskip}
  \usepackage{setspace}
    \setstretch{1.05}    % Set font and line spacing before `heightrounded' below.
  \setlength{\paperwidth}{8.25in}
  \setlength{\paperheight}{10.75in}
  \usepackage[% showframe,
   % left=0.8in,   % 'left' means 'insidemargin'
    right=1.446in,  % 'right' means 'outsidemargin'
    hmarginratio={2:3},
    top=1.446in,
    vmarginratio={1:1},
    marginparwidth=0.6in,
    marginparsep=0.125in,
    heightrounded,  % To make the text block height an integer number of lines.
    driver=pdftex   % Final output is pdf.
             ]{geometry}

%  \usepackage{pdflscape}
% ------- \layout --------------------------------------------------- %
 \usepackage{layout}  % Use \layout to show page geometry             %
   % You can change \layout output metric here..                      % (Heiko Oberdiek)
   % in    = 1/72.27    = 0.013837000                                 %
   % picas = 12/72.27   = 0.166044002                                 %
   % bp    = 72/72.27   = 0.996264010                                 %
   % mm    = 25.4/72.27 = 0.351459804                                 %
   \makeatletter                                                      %
     \renewcommand*{\lay@value}[2]                                    %
     {                                                                %
       \strip@pt\dimexpr0.013837\dimexpr\csname#2\endcsname\relax\,in %
     }                                                                %
   \makeatother                                                       %
% ------------------------------------------------------------------- %
  \usepackage{booktabs}  % For nice looking tables \begin{tabular}{lcr...} ... \end{tabular}
  \usepackage{siunitx}   % Adds 'S' option for aligning table values at decimal point.
  %%%%%%%%%% A macro to display parameters in other units: %%%%%%%%%%%%%%%%%%%
       %%% Example useage: \convertto{in}{\pdfpagewidth}in %%% \the\pdfpagewidth also works.
  \makeatletter
    \def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1 }
  \makeatother
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \usepackage[hyphens]{url}
  \usepackage[hidelinks]{hyperref}

  \raggedbottom  % \flushbottom
\begin{document}
%  \pagenumbering{Alph}
  \maketitle
%  \pagenumbering{alph}
  \pagestyle{empty}
  \tableofcontents
  \thispagestyle{empty}
  \pagenumbering{arabic}
  \pagestyle{plain}
 \chapter{Benevolent Misanthropy}
  \section{Mishaps, Adventures, and Battling the Paper Sprites}
     \kant[1-7]
     \newlength{\insidemargin}
       \setlength{\insidemargin}{1.0in}
       \addtolength{\insidemargin}{\oddsidemargin}
     \newlength{\outsidemargin}
       \setlength{\outsidemargin}{\paperwidth}
       \addtolength{\outsidemargin}{-\insidemargin}
       \addtolength{\outsidemargin}{-\textwidth}
     \newlength{\topmrgn}
       \setlength{\topmrgn}{\topmargin}
       \addtolength{\topmrgn}{\headheight}
       \addtolength{\topmrgn}{1.0in}
       \addtolength{\topmrgn}{\headsep}
     \newlength{\bottommrgn}
       \setlength{\bottommrgn}{\paperheight}
       \addtolength{\bottommrgn}{-\topmrgn}
       \addtolength{\bottommrgn}{-\textheight}
     \newlength{\TextWidth}
       \setlength{\TextWidth}{\textwidth}
     \newlength{\TextHeight}
       \setlength{\TextHeight}{\textheight}
     \newlength{\LinesOfText}
     \newlength{\buffer}
       \setlength{\buffer}{\textheight}
       \addtolength{\buffer}{-\topskip}
       \setlength\LinesOfText{1pt*\ratio{\buffer}{\baselineskip}+1pt}

     \newpage
% \begin{landscape}
     \centering
     \begin{tabular}{clSSS} \toprule
       \multicolumn{1}{c}{Number} & Name & pt & in & mm \\ \midrule
        1 & \verb|\paperwidth|     & \convertto{pt}{\paperwidth}     & \convertto{in}{\paperwidth}     & {\convertto{mm}{\paperwidth}}      \\
        2 & \verb|\paperheight|    & \convertto{pt}{\paperheight}    & \convertto{in}{\paperheight}    & {\convertto{mm}{\paperheight}} \\
        3 & \verb|\textwidth|      & \convertto{pt}{\TextWidth}      & \convertto{in}{\TextWidth}      & {\convertto{mm}{\TextWidth}}   \\
        4 & \verb|\textheight|     & \convertto{pt}{\TextHeight}     & \convertto{in}{\TextHeight}     & {\convertto{mm}{\TextHeight}}  \\
        5 & \verb|\left|           & \convertto{pt}{\insidemargin}   & \convertto{in}{\insidemargin}   & {\convertto{mm}{\insidemargin}}    \\
        6 & \verb|\right|          & \convertto{pt}{\outsidemargin}  & \convertto{in}{\outsidemargin}  & {\convertto{mm}{\outsidemargin}}   \\
        7 & \verb|\top|            & \convertto{pt}{\topmrgn}        & \convertto{in}{\topmrgn}        & {\convertto{mm}{\topmrgn}}       \\
        8 & \verb|\bottom|         & \convertto{pt}{\bottommrgn}     & \convertto{in}{\bottommrgn}     & {\convertto{mm}{\bottommrgn}}    \\
        9 & \verb|\marginparwidth| & \convertto{pt}{\marginparwidth} & \convertto{in}{\marginparwidth} & {\convertto{mm}{\marginparwidth}}  \\
       10 & \verb|\marginparsep|   & \convertto{pt}{\marginparsep}   & \convertto{in}{\marginparsep}   & {\convertto{mm}{\marginparsep}}    \\
       11 & \verb|\headheight|     & \convertto{pt}{\headheight}     & \convertto{in}{\headheight}     & {\convertto{mm}{\headheight}}      \\
       12 & \verb|\headsep|        & \convertto{pt}{\headsep}        & \convertto{in}{\headsep}        & {\convertto{mm}{\headsep}}         \\
       13 & \verb|\footskip|       & \convertto{pt}{\footskip}       & \convertto{in}{\footskip}       & {\convertto{mm}{\footskip}}        \\
       \bottomrule
     \end{tabular}

     \flushleft
     \verb|\baslineskip =| \the\OriginalBaselineSkip\ (Original)\par
     \verb|\baslineskip =| \the\baselineskip\ (Current, after \verb|\setstretch|)\par
     \verb|\topskip =| \the\topskip\par
     The number of lines of text = \par
     \verb|(\textheight-\topskip)/\baselineskip + 1 = | \convertto{pt}{\LinesOfText}
% \end{landscape}

     \layout

\end{document}

相关内容