How to use \vspace or \vspace* command in LaTeX?

In LaTeX, the \vspace command is used to insert vertical space between elements within a document. It allows you to adjust the spacing based on your specific needs. Here’s a complete guide on its usage and functionality.

Syntax of \vspace command

Let’s look at the syntax. But, you can use this command in two ways. Which is represented in the syntax below

\vspace{length}
\vspace*{length}

length: This parameter specifies length of the vertical space you want to insert. You can use various units such as cm, in, pt, em, ex, among others.

* (optional): If you include an asterisk * after \vspace, LaTeX will attempt to insert the space at desired location. For example, This command is used to insert vertical space that remains unbreakable, even if it falls at the top or bottom of a page.

Use of \vspace command

Spaces are very important to make a document beautiful. There are many commands for representing vertical space, but this is the most commonly used. Let us focus on following example, which will make your concept more clear.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in imperdiet turpis. Cras ullamcorper felis vel convallis tincidunt. Praesent at accumsan orci.

\lipsum[2][1-3]

\vspace{20px}

\lipsum[3][1-5]

\vspace{30pt}

\lipsum[4][1-5]

\vspace{1.5cm}

\lipsum[5][1-5]

\vspace{1in}

\lipsum[6][1-5]

\end{document}

Output :

A variety of length units are passed into this command.

When you compile above LaTeX code, the lipsum package will generate dummy text according to specified paragraph and sentence ranges. And \vspace commands add vertical spaces between the paragraphs or sentences with different lengths like 20px, 30pt, 1.5cm and 1in.

Use Negative value

Negative values with \vspace can be used to reduce space between elements. Let’s see an example of how to implement it between a table and its caption:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
  \centering
  \begin{tabular}{|c|c|}
    \toprule
    \textbf{Column 1} & \textbf{Column 2} \\
    \midrule
    Row 1 & Content \\
    \midrule
    Row 2 & Content \\
    \midrule
    Row 3 & Content \\
    \bottomrule
  \end{tabular}
  \vspace{-5pt}
  \caption{A table with reduced vertical space between the table and caption.}
  \label{tab:reduced-space-table}
\end{table}
\end{document}

Output:

This figure shows how you can reduce size between table and caption.

In this example, we have used \vspace{-10pt} command right after tabular environment, just before \caption command. Negative value -10pt reduces space between table and caption, making table and caption appear closer together.

Similarly, you can reduce space between other elements by passing negative values.

Inline use in Paragraph

Of course there are optional methods for this. That is, you need to add a newline after the \vspace command, then the paragraph break will occur at the exact point where you want it.

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\section*{Paragraph breaks are not occurring at the correct points}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in imperdiet turpis.\vspace{30px} Cras ullamcorper felis vel convallis tincidunt. Praesent at accumsan orci. Curabitur mattis tincidunt risus, non porttitor nulla vestibulum in. Aliquam mi odio, \vspace{10pt}finibus non purus a, auctor sollicitudin urna.Curabitur aliquam augue ut ex mollis blandit. Sed et ante a massa vehicula facilisis et sed sapien. 
\vspace{10pt}
\hrule
\vspace{10pt}
\section*{Paragraph breaks at appropriate points}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in imperdiet turpis.\vspace{30px}\\ Cras ullamcorper felis vel convallis tincidunt. Praesent at accumsan orci. Curabitur mattis tincidunt risus, non porttitor nulla vestibulum in. Aliquam mi odio, \vspace{20pt}\newline finibus non purus a, auctor sollicitudin urna.Curabitur aliquam augue ut ex mollis blandit. Sed et ante a massa vehicula facilisis et sed sapien. 
\end{document}

Output:

Inline space is used between paragraphs in this figure.

I think this is not the best practice. You can break paragraphs in the middle and use this command independently. Which is done in the first example.

Use of \vspace* command with asterisk optional argument

Before using optional arguments, you need to know why you use optional arguments. Note the following problem,

\documentclass{article}
\begin{document}
\vspace{-4cm}
\section*{The vspace command is not working}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in imperdiet turpis. Cras ullamcorper felis vel convallis tincidunt. Praesent at accumsan orci.
\end{document}

Output:

Why vspace* is needed instead of vspace? The reason is shown.

Where there is a lot of white space between the first element and the top of the page, you want to reduce or increase it. But, if you see the output, you can understand that there is no change in the space. In this case you need to pass the optional argument asterisk.

\documentclass{article}
\begin{document}
\vspace*{-4cm}
\section*{The vspace* command is working}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in imperdiet turpis. Cras ullamcorper felis vel convallis tincidunt. Praesent at accumsan orci.
\end{document}

Output:

Top margin of document is reduced to 4cm.

You can increase the default length in the same way. Which is given below.

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\vspace*{4cm}

\lipsum[1][1-5]

\end{document}

Output:

Top margin of the document has been increased by 4cm.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *