# Aligning the Arrows

Here's my code and I want all the lines to line up at the arrows. Could someone help me with that? Thank you.

1 $\longrightarrow$ trillion\\
7 $\longrightarrow$ hundred billion\\
8 $\longrightarrow$ ten billion\\
4 $\longrightarrow$ billion\\
6 $\longrightarrow$ hundred million\\
5 $\longrightarrow$ ten million\\
3 $\longrightarrow$ million\\
2 $\longrightarrow$ hundred thousands\\
0 $\longrightarrow$ ten thousands\\
1 $\longrightarrow$ thousands\\
4 $\longrightarrow$ hundreds\\
5 $\longrightarrow$ tens\\
9 $\longrightarrow$ ones\\

• Welcome to TeX.SX! The code looks like all the arrows should be aligned, except maybe for the first because of an indent of the first line of the paragraph. Can you expand your code to a minimal working example (MWE) so that we can see how it doesn't align? – Tiuri Dec 11 '19 at 10:56
• @Tiuri Ah, my bad, didn't mention that the first line is what bothers me. Is there a way to make the arrow of the first line be aligned with the rest? :) – user203109 Dec 11 '19 at 11:04
• You could add a \noindent to the 1st line, but as my answer indicates, that may still not provide proper alignment if the left column were to exceed a single digit or contain a decimal point. – Steven B. Segletes Dec 11 '19 at 11:10

The simple approach would be to add a \noindent to the first line. However, that will not account for the varied width of the leading numbers, especially if you exceed one digit or if the lead were something other than a digit, such as a decimal point.

There are many ways to accomplish this. Here is one that gives proper math spacing around the arrow, and will not break across a page boundary midway through.

\documentclass{article}
\usepackage{tabstackengine}
\begin{document}
\noindent\alignLongunderstack{
1${}\longrightarrow{}$& trillion\\
7${}\longrightarrow{}$& hundred billion\\
8${}\longrightarrow{}$& ten billion\\
4${}\longrightarrow{}$& billion\\
6${}\longrightarrow{}$& hundred million\\
5${}\longrightarrow{}$& ten million\\
3${}\longrightarrow{}$& million\\
2${}\longrightarrow{}$& hundred thousands\\
0${}\longrightarrow{}$& ten thousands\\
1${}\longrightarrow{}$& thousands\\
4${}\longrightarrow{}$& hundreds\\
5${}\longrightarrow{}$& tens\\
9${}\longrightarrow{}$& ones}
\end{document}


• It worked! Thank you so much!! :) – user203109 Dec 11 '19 at 11:11

You probably have several numbers to show the interpretation of.

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx} % also loads xparse and expl3

\ExplSyntaxOn

\NewDocumentCommand{\shownumber}{sO{c}m}
{
\IfBooleanTF { #1 }
{
\num{#3}
}
{
\ensuremath{\forest_shownumber:nn { #2 } { #3 } }
}
}

\seq_new:N \l__forest_shownumber_seq

\cs_new_protected:Nn \forest_shownumber:nn
{
\seq_set_split:Nnn \l__forest_shownumber_seq { } { #2 }
\begin{aligned}[#1]
\seq_indexed_map_function:NN \l__forest_shownumber_seq \__forest_shownumber_digit:nn
\end{aligned}
}

\cs_new_protected:Nn \__forest_shownumber_digit:nn
{
#2 & \longrightarrow
\text { \__forest_shownumber_name:n { \seq_count:N \l__forest_shownumber_seq - #1 } } \\
}

\cs_new:Nn \__forest_shownumber_name:n
{
\int_case:nn { #1 }
{
{0}{units}
{1}{tens}
{2}{hundreds}
{3}{thousands}
{4}{ten ~ thousands}
{5}{hundred ~ thousands}
{6}{million}
{7}{ten ~ million}
{8}{hundred ~ million}
{9}{billion}
{10}{ten ~ billion}
{11}{hundred ~ billion}
{12}{trillion}
%...
}
}
\ExplSyntaxOff

\begin{document}

\shownumber*{1784653201459}

$\shownumber{1784653201459}$

\shownumber*{123456} is \shownumber[t]{123456}

\end{document}


The \shownumber macro has a *-variant (just print the number); the optional argument is for the display version and tells what vertical alignment is passed to aligned (values are c, default, t or b).

We populate a sequence with the digits, then map it using the index to retrieve the textual meaning of the digit's place.

I stopped to “trillion”, but you can easily extend the list.

IN using tabular i would take a step further: with use of two columns the code is a bit shorter:

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{tabular}{@{} r @{${}\longrightarrow{}$} l @{}}
1 & trillion\\
7 & hundred billion\\
8 & ten billion\\
4 & billion\\
6 & hundred million\\
5 & ten million\\
3 & million\\
2 & hundred thousands\\
0 & ten thousands\\
1 & thousands\\
4 & hundreds\\
5 & tens\\
9 & ones
\end{tabular}
\end{document}


• +1. I've taken the liberty of streamlining your code, so that the user has to keep track of just 2 columns. Feel free to revert. – Mico Dec 11 '19 at 11:57
• @Mico, I see. Thank you very much. it is ok with two column too :-) – Zarko Dec 11 '19 at 14:32

I would encase the code chunk in a single-column, left-aligned tabular environment:

\documentclass{article}
\begin{document}
\begin{tabular}{@{} l @{}}
1 $\longrightarrow$ trillion\\
7 $\longrightarrow$ hundred billion\\
8 $\longrightarrow$ ten billion\\
4 $\longrightarrow$ billion\\
6 $\longrightarrow$ hundred million\\
5 $\longrightarrow$ ten million\\
3 $\longrightarrow$ million\\
2 $\longrightarrow$ hundred thousands\\
0 $\longrightarrow$ ten thousands\\
1 $\longrightarrow$ thousands\\
4 $\longrightarrow$ hundreds\\
5 $\longrightarrow$ tens\\
9 $\longrightarrow$ ones
\end{tabular}
\end{document}