标题页垂直居中

发布于 2024-09-07 03:18:01 字数 456 浏览 3 评论 0原文

我正在尝试使用乳胶将标题垂直居中在自定义尺寸的页面上。我编写了以下代码,但由于某种原因它没有居中。有人可以指出我有什么问题吗?

谢谢!

\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}

I'm trying to vertically center a title on a custom-sized page with latex. I've written the following code, but for some reason it doesn't center. Could someone please point me to what's wrong with it?

Thanks!

\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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浴红衣 2024-09-14 03:18:01

您的代码中有两个小错误。

首先,如果您希望 \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}

There are two small bugs in your code.

First, if you want the \vspace to work at the beginning or end of a page, you should use the starred version (\vspace*).

This would work, but \maketitle is a pretty complicated macro, and if used like in your example, it just puts the title at the second page. You can use the titlepage environment, which gives you much more command over how the title page looks like -- including the spacing. For example, you could use the following code:

\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}
终难愈 2024-09-14 03:18:01
\null  % Empty line
\nointerlineskip  % No skip for prev line
\vfill
\let\snewpage \newpage
\let\newpage \relax
\maketitle
\let \newpage \snewpage
\vfill 
\break % page break
\null  % Empty line
\nointerlineskip  % No skip for prev line
\vfill
\let\snewpage \newpage
\let\newpage \relax
\maketitle
\let \newpage \snewpage
\vfill 
\break % page break
浅紫色的梦幻 2024-09-14 03:18:01

如果您想让一切正常工作,即使使用 \maketitle 也可以将 \vspace*{\fill} 放在第一个和最后一个属性 exp 中:

 \title{**\vspace*{\fill}**[[title]]}

 \date{[[date]]}

 \author{[[author]]**\vspace*{\fill}**[[}

 \begin{document}

    \maketitle

    \newpage

   [[text]]

\end{document}

If you want to make everything work even with \maketitle put your \vspace*{\fill} inside the first and the last attribute, exp:

 \title{**\vspace*{\fill}**[[title]]}

 \date{[[date]]}

 \author{[[author]]**\vspace*{\fill}**[[}

 \begin{document}

    \maketitle

    \newpage

   [[text]]

\end{document}
幼儿园老大 2024-09-14 03:18:01

正如 finrod 的回答所示,\maketitle 是一个非常复杂的宏,这就是为什么我不想自己覆盖它(\renewcommand\maketitle{...)。尽管如此,复制、粘贴和编辑 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}

输出:

As in the answer by finrod, \maketitle is a pretty complicated macro, this is why I didn't feel like overwriting it myself (\renewcommand\maketitle{...). Nevertheless, copying, pasting and editing lines 170-201 of article.cls documentclass, I could add a new one to customize (\newcommand\mymaketitle{...) as follows:

\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}

The output:

screenshot of output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文