Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set tab stops after whitespaces in LaTeX?

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?

like image 713
nedned Avatar asked Apr 01 '10 06:04

nedned


2 Answers

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.

like image 160
sastanin Avatar answered Sep 23 '22 20:09

sastanin


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.

like image 40
Etaoin Avatar answered Sep 25 '22 20:09

Etaoin