views:

513

answers:

4

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.

+3  A: 

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.

Etaoin
+1 good answer, better than the others.
High Performance Mark
+1  A: 

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.

Charles Stewart
IMHO, you answer a different question.
Alexey Malistov
@Alexey: No. Latex's tabbing environment will set tab stops after whitespace generated using hskip, so this answer provides information on how to solve the problem.
Charles Stewart
Yep, this did answer the question, in fact I think it is a more elegant solution than the one I accepted. But given that that one also has a nice little description on how it all plays out in the tabbing environment, it's a bit more useful for people landing on this page.
humble coffee
+2  A: 

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 not 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

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

jetxee
This is exactly the sort of solution I had in mind. Although using the `\hskip` command that Charles Stewart suggested is probably even neater. I've accepted this one because it explains how to make it work in the tabbing environment.
humble coffee
+1  A: 

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.

Svante