简体   繁体   中英

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?

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

结果截图

Using tables (eg 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 .

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM