38

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}
Clément
  • 12,299
  • 15
  • 75
  • 115

4 Answers4

50

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}
finrod
  • 1,398
  • 11
  • 8
20
\null  % Empty line
\nointerlineskip  % No skip for prev line
\vfill
\let\snewpage \newpage
\let\newpage \relax
\maketitle
\let \newpage \snewpage
\vfill 
\break % page break
Alexey Malistov
  • 26,407
  • 13
  • 68
  • 88
  • 2
    This is excellent. I have created approximately 50 documents (which were relatively important) and used this code; worked every time. – alexyorke Feb 07 '14 at 23:57
3

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}
Chris
  • 5,882
  • 2
  • 32
  • 57
Fadi
  • 31
  • 1
1

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

MattAllegro
  • 6,455
  • 5
  • 45
  • 52