How to set tab stops after whitespaces in LaTeX?

38,743

Solution 1

The tabbing environment allows to set tab stops and position text accordingly; it may be used to simulate simple tables.

\= in the first line sets a tab stop, \> advances to the next tab stop in the second line and below.

Please note that tabbing does not expand tab stops, so you need to ensure they are placed wide enough from each other. For example, I put some nonbreakable spaces after A in the first line:

\begin{tabbing}
A~~~~ \= $\to$ \= B \\
CD \> $\to$ \> A \\
BDD \> $\to$ \> F \\
\end{tabbing}

The result looks like

result screenshot

Using tables (e.g. tabular) is often easier, but tabbing allows to redefine tab points later, so it may be used to simulate indented text, like source code.

See also: LaTeX: tabbing.

Solution 2

If you want this in math mode, put \usepackage{amsmath} in your preamble, and try

\begin{align*}
  A &\to B \\
  CD &\to A
\end{align*}

The ampersands are invisible, and are aligned with each other, so the arrows will line up.

This can also be done in text mode as a table (without needing the amsmath package):

\begin{tabular}{r @{$\to$} l}
  A & B \\
  CD & A
\end{tabular}

With the @ expression in the column specification, the columns will be separated by whatever symbol you like -- in this case, the arrow -- thus aligning that symbol between rows.

Solution 3

Use {\hskip 4em} to specify whitespace four font-width spaces wide, or what have you. There are a number of prespecified whitespace characters in Latex, such as \qquad for \hskip2em.

\hskip whitespace specified in this way is inflexible, that is, Tex will not change the amount of whitespace, but you can use something like {\hskip 3em plus 1em minus 1em} for space that tries to be 3ems long, but can stretch or shorten to between 2ems and 4ems.

Solution 4

If you want to use tabbing (instead of e.g. tabular), you can use kill to make a "template" line that sets the stops. See http://latex.computersci.org/Reference/TableEnvironments.

Share:
38,743
nedned
Author by

nedned

Updated on June 11, 2020

Comments

  • nedned
    nedned almost 4 years

    I'm trying to set tab stops in LaTeX in the tabbing environment. My problem is that I want to set a tab stop after a number of whitespaces. The problem is that LaTeX of course ignores multiple whitespaces, and it seems to only support setting tab stops after actual text.

    What I would like to be able to do is format the arrows below so that they line up together.

    A   -> B
    CD  -> A 
    BDD -> F
    

    The problem is that the extra spaces after the characters on the left of the arrows are ignored for the purposes of setting the tab stop. What is the solution?