代码之家  ›  专栏  ›  技术社区  ›  Clément

标题页垂直居中

  •  32
  • Clément  · 技术社区  · 16 年前

    我正试图垂直居中的标题在一个自定义大小的乳胶页。我已经编写了以下代码,但出于某种原因,它不在中心。有人能告诉我怎么回事吗?

    谢谢!

    \documentclass{article}
    \setlength{\pdfpagewidth}{88.184mm}
    \setlength{\pdfpageheight}{113.854mm}
    
    \usepackage[margin=0.5cm, paperwidth=88.184mm, paperheight=113.854mm]{geometry}
    
    \title{[[title]]}
    \date{[[date]]}
    \author{[[author]]}
    
    \begin{document}
        \vspace{\fill}
        \maketitle
        \vspace{\fill}
    
        \newpage
    
        [[text]]
    \end{document}
    
    4 回复  |  直到 8 年前
        1
  •  42
  •   finrod    16 年前

    代码中有两个小错误。

    首先,如果你想要 \vspace 要在页面的开头或结尾工作,应使用带星号的版本( \vspace* )

    这是可行的,但是 \maketitle 是一个相当复杂的宏,如果像在示例中那样使用,它只会将标题放在第二页。你可以使用 titlepage 环境,它可以让您对标题页的外观(包括间距)有更多的了解。例如,可以使用以下代码:

    \documentclass{article}
    \setlength{\pdfpagewidth}{88.184mm}
    \setlength{\pdfpageheight}{113.854mm}
    
    \usepackage[margin=0.5cm, paperwidth=88.184mm, paperheight=113.854mm]{geometry}
    
    \begin{document}
      \begin{titlepage}
        \vspace*{\fill}
        \begin{center}
          {Huge [[title]]}\\[0.5cm]
          {Large [[author}\\[0.4cm]
          [[date]]
        \end{center}
        \vspace*{\fill}
      \end{titlepage}
    
      [[text]]
    \end{document}
    
        2
  •  15
  •   Alexey Malistov    16 年前
    \null  % Empty line
    \nointerlineskip  % No skip for prev line
    \vfill
    \let\snewpage \newpage
    \let\newpage \relax
    \maketitle
    \let \newpage \snewpage
    \vfill 
    \break % page break
    
        3
  •  1
  •   Chris    12 年前

    如果你想让一切都能正常工作 \maketitle 把你的 \vspace*{\fill} 在第一个和最后一个属性中,exp:

     \title{**\vspace*{\fill}**[[title]]}
    
     \date{[[date]]}
    
     \author{[[author]]**\vspace*{\fill}**[[}
    
     \begin{document}
    
        \maketitle
    
        \newpage
    
       [[text]]
    
    \end{document}
    
        4
  •  0
  •   MattAllegro    8 年前

    正如finrod的答案一样, \makeTitle 是一个相当复杂的宏 ,这就是为什么我觉得自己不想重写它( \renewcommand\makeTitle. )。不过,复制、粘贴和编辑第170-201行,共 article.cls documentClass ,我可以添加一个新的来定制( \newcommand\mymakeTitle. …)如下:

    \设置长度\pdfpagewidth 88.184mm
    \设置长度\pdfpageheight 113.854mm
    
    \ usepackage[页边距=0.5厘米,纸张宽度=88.184毫米,纸张高度=113.854毫米]几何
    
    标题{标题}
    日期{日期}
    作者{作者}
    
    制作字母
    \新命令\MyMakeTitle%
    \开始标题
    \空\vfil\vskip 40\p@
    开始{中心}
    \大\@标题\段落
    VSKIP 2.5EM
    \大\行跳过.75em \@作者\段落
    VSKIP 1.5 EM
    \大\@日期\参数
    \结束中心\ par
    谢谢
    \VFIL\null
    \{TITLE页}
    }
    化妆师
    
    \开始文档
    我的名字
    
    文本
    \Enter {文档}
    < /代码> 
    
    

    输出:

    (\renewcommand\maketitle{……)不过,复制、粘贴和编辑第170-201行article.cls documentclass,我可以添加一个新的自定义(\newcommand\mymaketitle{…)如下:

    \documentclass{article}
    \setlength{\pdfpagewidth}{88.184mm}
    \setlength{\pdfpageheight}{113.854mm}
    
    \usepackage[margin=0.5cm, paperwidth=88.184mm, paperheight=113.854mm]{geometry}
    
    \title{Title}
    \date{Date}
    \author{Author}
    
    \makeatletter
    \newcommand\mymaketitle{%
      \begin{titlepage}
        \null\vfil\vskip 40\p@
        \begin{center}
          {\LARGE \@title \par}
          \vskip 2.5em
          {\large \lineskip .75em \@author \par}
          \vskip 1.5em
          {\large \@date \par}
        \end{center}\par
        \@thanks
        \vfil\null
      \end{titlepage}
    }
    \makeatother
    
    \begin{document}
    \mymaketitle
    
    Text
    \end{document}
    

    输出:

    screenshot of output