[Tex/LaTex] How to change margin of the document title

lyxmarginstitles

I want to move the title of my document up in order to save space. I can't figure out how to do this.

This is what I have in LyX

enter image description here

And this is how it shows up in PDF. I'd like to move it up.

enter image description here

Best Answer

Within the default Article (Standard Class) (see you Document > Settings... > Document Class tab), the Title (Author and Date) is set using a macro called \@maketitle (inside article.cls. This is what that macro looks like:

\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}

You'll note that it inserts a \newpage, then sets \null (consider it just something to "start the page") and inserts a vertical skip of 2em, before starting to set the actual title (inside a centered environment).

You can get rid of this vertical skip by adding the following to your Document > Settings... > LaTeX Preamble:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@maketitle}% <cmd>
  {\newpage\null\vskip 2em}{}% <search><replace>
  {}{}% <success><failure>
\makeatother

The above patch uses etoolbox to remove the \newpage \null \vskip 2em construction from \@maketitle, thereby making the title start immediately where it's called. A similar thing can be added to remove the vertical skip at the end of the environment (given by \vskip 1.5em), if needed:

\makeatletter
\patchcmd{\@maketitle}% <cmd>
  {\par\vskip 1.5em}{\par}% <search><replace>
  {}{}% <success><failure>
\makeatother

With only the first patch, your document should now resemble:

enter image description here

In the above output I've also added the showframe package to highlight the position of the text box just as an indication that there's no white space set before the actual title.

With both patches active there's a little less space (not much) below the title:

enter image description here

Of course, instead of removing it, one can insert a negative space.

Related Question