[Tex/LaTex] aligned environment, align numbers to right

equations

I have an "equation", where I simply want to give some constant values. I'm aligning on the equation symbols, but as the numbers have different amounts of digits, I would also like to align the numbers to the right:

alignment

LaTeX currently looks as follows:

\documentclass[ngerman]{scrbook}
\usepackage{amssymb,amsmath,amsthm}
\begin{document}
\begin{equation*}
    \begin{aligned}
    \text{first value} &= 12 & \\
    \text{second value} &= 1234 & \\
    \text{third one} &= 1234567 &
    \end{aligned}
\end{equation*}
\end{document}

Is it possible to align to the right with aligned? Are there any other packages for achieving this (I would like to stick to the equation if possible, for consistency reasons).

Best Answer

Like this?

\documentclass{scrbook}
\usepackage{amssymb,amsmath,amsthm}
\begin{document}
\begin{equation*}
    \begin{alignedat}{2}
    \text{first value} &={}& 12  \\
    \text{second value} &={}& 1234  \\
    \text{third one} &={}& 1234567
    \end{alignedat}
\end{equation*}
\end{document}

I have just moved the & before the numbers and used alignedat (thanks to egreg).

enter image description here

This is with \makebox:

\documentclass{scrbook}
\usepackage{mathtools}
\newcommand\mybox[1]{\makebox[1.5cm][r]{$#1$}}  %% change 1.5cm to fit in the largest integer
\begin{document}
\begin{equation*}
    \begin{aligned}
    \text{first value} &= \mybox{12}  \\
    \text{second value} &= \mybox{1234}  \\
    \text{third one} &= \mybox{1234567}
    \end{aligned}
\end{equation*}
\end{document}

enter image description here

Another option with a tabular:

\documentclass{scrbook}
\usepackage{amsmath,array}
\begin{document}
\begin{equation*}      %% or \begin{center}
    \begin{tabular}{r!{$=$}r}
    first value & 12  \\
    second value & 1234  \\
    third one & 1234567 
    \end{tabular}      %% or \end{center}
\end{equation*}
\end{document}

Here you can use begin{center} or \centering (within a group) instead of \begin{equation*}.

enter image description here