TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this test file which is supposed to put Hello there. near the top of the page but it does not work in so far as there is still tons of vertical space at top. How can I fix this?

\documentclass{article}
\begin{document}
\vspace{-10cm}
Hello there.
\end{document}
share|improve this question

migrated from stackoverflow.com Jul 6 '12 at 19:51

This question came from our site for professional and enthusiast programmers.

up vote 37 down vote accepted

The reason for the vertical space is the default margins. I would recommend using the geometry package for changing the page geometry. With the [showframe] option to the geometry package you see that the text is actually already at the top of the page, but the page has a margin before the text starts (The gray bar at the top is the top of the page):

enter image description here

To see which dimensions you need to adjust you can use \layout from the layout package. So, with the following:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{layout}

\begin{document}\layout
Hello there.
\end{document}

you get a nice image on page 1 that shows the various dimensions. From the top of this page you see:

enter image description here

So the dimensions you are interested in are (2) and (6). From the bottom of the page we see:

enter image description here

Hence you need to adjust \voffset and \headsep. Since 1.0in is added to the dimension specified in \voffset, I set that to a negative value. So, for instance setting this to:

\setlength{\voffset}{-0.75in}
\setlength{\headsep}{5pt}

you achieve:

enter image description here

Code:

\documentclass{article}
\usepackage[showframe]{geometry}
%\usepackage{layout}

\setlength{\voffset}{-0.75in}
\setlength{\headsep}{5pt}

\begin{document}%\layout
Hello there.
\end{document}
share|improve this answer
    
Thanks. Great answer. – user1189687 Jul 5 '12 at 17:55
    
This is nice but what if I only want to remove the extra space at the beginning of the document? These changes effect every page, not just the first one. – j0equ1nn Nov 8 '15 at 3:02
    
@j0equ1nn: The extra space at the beginning of the document is going to depend on exactly how you have set up your document in terms of \documentclass and packages. I'd suggest you post a new question that with a MWE including \documentclass and the appropriate packages that reproduce the problem. If it is relevant you can reference this question in your post. – Peter Grill Nov 8 '15 at 10:34
    
That's all well and good but as this question is phrased, it does ask about reducing space at the beginning of the document, not just at the beginning of the first page. – j0equ1nn Nov 23 '15 at 4:34

To achieve a "Hello there" that is really in the top left corner of the paper, use the following bit of extreme code:

\documentclass{article}
\usepackage[a4paper]{geometry}
\geometry{textwidth=\paperwidth, textheight=\paperheight, noheadfoot, nomarginpar}
\setlength{\topskip}{0mm}
\setlength{\parindent}{0mm}
\begin{document}
Hello there.
\end{document}

It does away with the header, footer, margin paragraph, all related spaces as well as \topskip and \parindent. Please, refer to the geometry manual and this Cambridge University page for an explanation of the employed commands.

share|improve this answer

Here is a trick that accomplishes just what you asked with very minimal work, and resembles the attempt you referenced. You can make your "title" a removal of vertical space.

\documentclass{article}
\title{\vspace{-7cm}}
\author{}
\date{}
\begin{document}
\maketitle
Hello there.
\end{document}

For more precise control over the margins, etc. of the whole document, there is @PeterGrill's answer, with the addendum that if you want the changes to only effect the start of the latex document, you need to mess with the documentclass.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.