Let’s talk about the headaches of LaTeX

Why is scientific literature usually required to be written in LaTeX\LaTeXLATEX? Because it looks good, of course.

LaTeX\LaTeXLATEX is beautifully typesetted with a complex set of notations and typesetting systems. Just by looking at it, you can see that it takes more than one day to master all of them. Even the title LaTeX\LaTeXLATEX has its own special typesetting. There are many symbols that look the same, but there are very subtle differences, like these two words. Can you tell the difference?


M i c r o s o f t M i c r &western s &western f t Microsoft \qquad Micr\omicron s\omicron ft

To be honest, I can’t tell myself (or the font I’m using makes no difference), but the source code for the top line is:

Microsoft \qquad Micr\omicron s\omicron ft
Copy the code

With the latter word, ο\omicronο is actually Omicron, not ooo!

Trivials: The symbol ο\omicronο is the Greek letter that we use for higher order infinitesimal.

LaTeX’s accuracy makes it more suitable for formula typesetting, and just the number of Spaces is enough for me to write an article. Null characters can help us to align difficult rows or columns in typesetting, allowing us to adjust the details as freely as Word without losing the beauty of LaTeX. In this case, however, I don’t recommend nulls as a preferred option. ~~ It is necessary to understand LaTeX’s null characters.

Spaces of various lengths

LaTeX has a dizzying variety of whitespace. In terms of length, there are three broad categories. That is: “I will always be this long as long as I don’t change fonts” relative to fixed font length Spaces, “I will be as long as you tell me to be” custom length Spaces, and “I will be as long as you place me” adaptive length Spaces.

Fixed relative font length

Let’s start with a fixed amount of space relative to the font. This is the simplest type of space. You type it out, and it gives you a fixed amount of space. LaTeX itself does not have much of this whitespace, but the amsMath package makes it richer.

Before we go on, let’s explain a unit of length: em.

Those who use LaTeX are certainly familiar with this unit, but there are different opinions on what it means. It’s not exactly equal to the width of M in the font, it’s not exactly equal to the size of the font itself, just know that this unit changes with the font.

Common Spaces of this kind, and their respective lengths, are shown in the following table:

There are a few points to note:

  1. In principle, do not add Spaces before and after the combination of escape character and punctuation. Compared to the standarda\,b, with Spaces addeda\, bThe displayed null character is actually\,Add a normal space. Conventional white space can be adjusted to fit the layout, which results in the length of the generated white space is not only longer than expected, but also not fixed.
  2. \quad.\thinspace This type of escape + letter combination is followed by a space. The following space is not recognized as a normal space, but simply as a sign of the end of a command. However, if a space is added before a command, it is treated as a normal space.
  3. If the characters above do not reach the desired length,You can combine. Such as\; The \!A space of 2/18 em is generated. If that doesn’t work, try the custom length command below.

Custom length

Custom length commands generate a space of a given length and are very flexible to use.

Remember \hspace and \vspace. The former is used in the horizontal direction and the latter in the vertical direction. These two commands are LaTeX native and do not require the introduction of any additional packages.

The syntax is \hspace{

} fill in the desired length at

.

The following figure illustrates three use cases and their equivalent default space combinations. Hspace {1em} generates Spaces and quad, while hspace{0.11111em} generates Spaces and quad; The \! Equal length, you can even put a negative value in there, and there are equal length fixed-length Spaces to match that. There are a lot of things that can be said about units of length, such as sp, the smallest unit in LaTeX, and how many sp each unit is equal to. See this Stackexchange q&A for more details.

Another \vspace may be more general and is usually used for fine-tuning line spacing, including but not limited to distance adjustments between chart and heading, between chart and body, and between heading and body.

Let’s type a text (where the unit ex is approximately equal to the height of x in the current font) :

Good morning downstairs! Early... What a crowded crowd!\vspace{-2ex} I want to stick with the third floor!\vspace{2ex} Look at me. I'm right where I'm supposed to be.Copy the code

That’s the effect

In fact, whether the vspace command is on a single line or merged with top and bottom, the effect is the same, adding or subtracting from the default line space. In contrast to horizontal kerning, line spacing is relatively fixed, so it doesn’t pose much of a problem.

Adaptive length

This type of space is different from the above, with good typography as the first priority. They change their length to suit the desired effect.

Conventional space

The most typical of these Spaces is a regular space, where you type the longest space bar on the keyboard and you enter a regular space.

In Chinese literature writing, this space is relatively rare, while in English writing, this space can be said to be the most frequent character in a text. In order to make typesetting beautiful, English literature is usually aligned at both ends, but English words are not the same length. Often, the length of the end of a sentence is not enough, and the length of the first word in the next line is too long. LaTeX does this by adjusting the normal space length. The following quote is from the Little Match Girl.

Hfill and hfil

As the name suggests, these two commands serve as padding. The fill effect is the maximum width that can be extended. In general, if we have an image to be placed side by side, we can add a \hfill or \hfil in the middle. We can split the two side by side objects to create a left and a right alignment.

Here’s an example with side-by-side minipages:

\noindent\begin{minipage} {0.3\textwidth}
    Most terribly cold it was; it snowed, and was nearly quite dark, and evening - the last evening of the year.
\end{minipage}
\hfill % or \ hfil
\begin{minipage} {0.3\textwidth}
    In this cold and darkness there went along the street a poor little girl, bareheaded, and with naked feet.
\end{minipage}
\hfill % or \ hfil
\begin{minipage} {0.3\textwidth}
    When she left home she had her slippers on, it is true;
\end{minipage}
Copy the code

The result is as follows. You can see that the three minipages are separated by two Spaces of equal length.

If you replace both \hfill with \hfil, the result will be exactly the same. However, if you change only one of them, you’ll notice that the space in \hfil disappears completely. Why is that?

By definition, both fill and fil are infinite in accordance with typography rules. Fill, however, is a higher order infinity than fil. If \hfill and \hfil are on the same line, \hfil will be squeezed into nothing by \hfill. And it makes sense that even infinity is 0 in front of higher order infinity. And equal order infinity, the length of the space extended over the same line is the same.

There are also vertical versions of these two commands, \vfill and \vfil, that extend up to a full page. Also, there is \hfilll and \vfilll, which are infinities higher than the fill of the two L’s. I won’t go into much detail here.

Special space

Spaces that do not fold

Sometimes we need everything before and after the space to be on one line, such as the title of a chart, Fig. 3, Tab. 4, and so on. Breaking lines is weird. LaTeX provides a non-breaking space for this, which is ~. It only needs to be written as Fig.~3.

The space after the command

Some commands generate text in the document, and sometimes you want to add a space after that text. However, LaTeX will only use it as a sign that the command is over, no matter how many Spaces you put at the end of the command, and the resulting document will stick close to the text that follows.

The correct solution is to add an escape character \ followed by a space, or to use {} as the terminator of the command so that the following space is recognized as a regular space. That is:

The date is \today and it's raining heavily.
% the result of the above sentence:
The date is February 24, 2021and it's raining heavily.

The date is \today \ and it's raining heavily.
The date is \today{} and it's raining heavily.
% The result of the above two sentences is the same:
% The date is February 24, 2021 and it’s raining heavily.
Copy the code

conclusion

LaTeX has a plethora of whitespace characters that are not exhaustive. Here I just summarize some commonly used characters, based on my access to information and personal understanding, there are mistakes are welcome to point out ah 🙂

reference

  • LaTeX horizontal space: qquad,hspace, thinspace,enspace
  • What are the various units (ex, em, in, pt, bp, dd, pc) expressed in mm
  • Which measurement uints should one use in latex
  • Spaces and Boxes
  • What is the difference between ‘fil’ and ‘fill’ ?