2

I'm creating a list with enumerate of both positive and negative numbers, and would like the numbers to be lined up with one another, i.e. all in the same column. I also have a second list with decimal numbers, and I would like to line up the decimal points. I tried using \begin{align} within the enumerate list as in

\begin{enumerate}
\begin{align*}[t]
\item $-&2$
\item $3$
\item $-18$
\item $83.2$
\item $-112.2$
\end{align*}
\end{enumerate}

but it gives me the error \begin{aligned} allowed only in math mode. I have the amsmath package loaded, and I'm compiling with xelatex.

Edit: xelatex is now giving me this error even when I have commented out the problem area.

  • try \begin{aligned}[t] instead – cmhughes Apr 2 '13 at 19:55
  • I tried that, since I read that that was the correct syntax in math, but it gives me the same error message. – ekrah Apr 2 '13 at 19:57
  • Why don't you use an array environment with the siunitx package for alignment? – Gonzalo Medina Apr 2 '13 at 20:00
  • Doing it within enumerate seems much simpler than using an whole new package and environment, but I will try it if there is no other option. – ekrah Apr 2 '13 at 20:14
  • 2
    You are already using the amsmath package for the align environment so why not use that? align is a multi-row environment for aligning things which is exactly what you want, you are using separate align environments for each entry which means there is no alignment at all (apart from the syntax error of putting the align environment inside $..$) – David Carlisle Apr 2 '13 at 20:18
4

You cannot use \item in math mode, so your construction:

\begin{enumerate}
\begin{align*}[t]
\item $-&2$
\item $3$
...
\end{enumerate}

will produce errors.

To get the desired arrangement (tabular-like material with enumerated rows and alignment at decimal separator for certain columns), you could use a tabular environment; the alignment can be achieved using the siunitx package:

\documentclass{article}
\usepackage{siunitx}

\newcounter{tmp}

\begin{document}

\noindent\begin{tabular}{>{\stepcounter{tmp}\thetmp}lSS[table-format = 3.4]}
& 6 & 2.3456 \\
& -7 & 34.2345 \\
& 20 & -6.7835 \\
& -12 & 90.473 \\
\end{tabular}

\end{document}

enter image description here

Here are two other options: one, using just align (from the amsmath package) and the other one using a standard tabular:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\newcounter{tmp}

\begin{document}

\noindent Using \texttt{align*}:
\begin{align*}
1 && 6 && 2.3456 \\
2 && -7 && 34.2345 \\
3 && 20 && -6.7835 \\
4 && -12 && 90.473\phantom{0} \\
5 && 10 && 3.4\phantom{000} 
\end{align*}

\noindent Using \texttt{tabular}:

\setcounter{tmp}{0}
\noindent\begin{tabular}{@{}>{\stepcounter{tmp}\thetmp}lrr@{.}l}
& 6 & 2 &3456 \\
& -7 & 34 & 2345 \\
& 20 & -6 & 7835 \\
& -12 & 90 & 473 \\
& 10 & 3 & 4 
\end{tabular}
\end{document}

enter image description here

Notice that the first solution (using siunitx) implies less work.

  • I will try using the tabular environment, it does look like the better option. I appreciate you taking the time to show the differences between the two options. – ekrah Apr 3 '13 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.