There is always a need to apply some amount of spacing when doing adjustments in our work for a better presentation.
Aspect of spacing is very important and this article will guide you to have a full understanding of spacing in LaTeX.
LaTeX Algorithm permits the treatment of blank spaces by ignoring them whereby a sequence of blank spaces is treated as a single space. LaTeX does the same for a sequence of blank lines, it converts it to a single newline.
LaTeX provides us with a good number of commands to help us in creating both vertical and horizontal spacing.
Spacing in LaTeX makes use of length commands.
In this context, there are basically 3 types of length commands when dealing with spacing.
- Length data commands represent a fixed length. It can be assigned or used as the length in other commands.
- Length assignment command basically assigns value to the length data.
- Length setting command which generate a blank space with a certain height or width.
Horizontal spacing
The following are length commands that generate horizontal space with their various descriptions and examples.
1. \quad
and \qquad
generates a horizontal blank space with a width of 1em and 2em respectively. In summary, \qquad
doubles the effect of \quad
.
Space produced by \quad
and \qquad
simultaneously can be demonstrated:⏹ ⏹ and ⏹ ⏹
Example:
- Apples
\quad
Apples will give Apples Apples. - Apples
\qquad
Apples will give Apples Apples.
2. \hspace{length}
and \hspace*{length}
generate a horizontal blank(white) space equivalent to the length. \hspace*{length}
produces a non-ignoring space.
By default, LaTeX will delete any space at the beginning or end of a line. This command forces the space to be
implemented.
NB: Lengths can be positive or negative.
- Apples
\hspace{5em}
Apples will give Apples Apples. will give
This is to demonstrate the effect of negative space.
3. \hfill
command generates a white space that fills the entire line.
Example:
\rule{0.5cm}{1em}\hfill \rule{0.5cm}{1em}
will give
4. \hphantom{text}
command gives us a white space that is equivalent to the width of the text.
Example:
The quick \hphantom{brown}
fox jump over the lazy dog.
will give
The quick fox jump over the lazy dog.
5. \thinspace
or \, generates a horizontal blank(white) space with a width of 0.16667em. It is mostly used in character spacing.
6. \negthinspace
or \! generates a horizontal blank(white) space with a width of −0.2777em. It can be used for character adjustment.
7. \medspace
or \: generates a horizontal blank(white) space with a width of 0.2222em.
8. \thickspace
or \; generates a horizontal blank(white) space with a width of 0.2777 em.
9. \enskip
generates a horizontal blank(white) space with a width of 0.5em.
10. \enspace
generates a horizontal blank(white) space with a width of 0.5em and can be use for character spacing adjustments.
Vertical spacing
The following are length commands that generate vertical space with their various descriptions and examples.
1. \vspace{height}
and \vspace*{height}
produces vertical white space equivalent to the specified height in the braces.
\vspace*{height}
will forcefully produce a vertical space equivalent to the specified height in the braces at the top of page. The height can either be positive or negative.
2. \vfill
generates a white space the vertical fills the rest of the page.
3. \vphantom{text}
generates a vertical blank of width zero and a total height equal to the total height of the text in the braces.
4. \smallskip
generate a vertical space with a height of 3pt ± 1pt.
5. \medskip
doubles the effect of the \smallskip
i.e 6pt ± 2pt.
6. \bigskip
generates a vertical space which is equivalent to four times the effect of \smallskip
i.e 12pt ± 4pt.
\phantom{text}
Generates a blank with a total height and width equal to the total height and width of the text in the braces, respectively.
Horizontal Spacing Summary
Commands | Effects |
---|---|
\quad |
1em horizontal space |
\qquad |
2em horizontal space |
\hspace{length} |
horizontal space equal to length specification |
\hspace*{length} |
horizontal space at beginning of line equal to length specification |
\hfill |
a horizontal white space that fill entire line |
\hphantom{text} |
white space equal to width of text |
\enskip |
horizontal blank(white) space with a width of 0.5em. |
\enspace |
horizontal blank(white) space with a width of 0.5em. |
\thinspace or \, |
horizontal blank(white) space with a width of 0.16667em. |
\negthinspace or \! |
horizontal blank(white) space with a width of −0.16667em. |
\medspace or \: |
horizontal blank(white) space with a width of 0.2222em. |
\thickspace or \; |
horizontal blank(white) space with a width of 0.2777 em. |
Vertical Spacing Summary
Commands | Effects |
---|---|
\vspace{height} |
vertical space equal to the length specification |
\vspace*{height} |
vertical space at the top of page equal to the length specification |
\vfill |
a vertical white space that fills an entire page |
\vphantom{text} |
white space equal to the total height of text |
smallskip |
vertical white space with a height 3pt ± 1pt |
medskip |
vertical white space with a height 6pt ± 2pt |
bigskip |
vertical white space with a height 12pt ± 4pt |
Conclusion
Understanding how to deal with spacing is of utmost importance to become proficient in LaTeX.
This tutorial helps you to have a full understanding of the different spacing commands available in LaTeX.