# xlop alignment of multiple equations when resultstyle=text

Is there a way to align xlop equations when the resultstyle is text

    \documentclass[20pt,fleqn,leqno]{extarticle}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{xlop}% http://ctan.org/pkg/xlop

\begin{document}

\begin{enumerate}[label={\arabic*)}]
\end{enumerate}

\end{document}


Current output

Desired output (opereator and equal to sign aligned, if place value alignment can be done that will be great too).

I am constrained to use xlop for some reason but if this is not possible with xlop, I will look at other regular math equation options.

edit: Does it make it easier if the output follows regular alignment rules like this?

ps: Trying to keep the solution to xlop as output is getting generated conditionally in a larger program - not using the opadd with style text will require access to code I do not have. The proposed solutions are much appreciated.

• You can do very well without xlop, why do you need xlop? – AndréC Sep 2 '17 at 16:23

I don't see it possible to change the output of xlop to meet the esoteric needs of the question, namely to make the first number right aligned and the second number left aligned, using a field width that, at the invocation of problem 1, cannot be fully known.

However, if the problem were reduced to using the standard xlop output, but aligning at the equal sign, then it could be done.

For the sample problem, involving only addition and positive numbers, one could do this. Basically, I use \numexpr to calculate the result, and add the appropriate number of blanks spaces to the end of the right-aligned result. The field width for the \mopadd macro is specified in the definition \mopwid.

\documentclass[20pt,fleqn,leqno]{extarticle}
\usepackage{enumitem}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{xlop}% http://ctan.org/pkg/xlop
\def\mopwid{1.8in}
\ifnum\numexpr#1+#2\relax<1000\relax\phantom{0}\fi%
\ifnum\numexpr#1+#2\relax<100\relax\phantom{0}\fi%
\ifnum\numexpr#1+#2\relax<10\relax\phantom{0}\fi%
}}
\begin{document}

\begin{enumerate}[label={\arabic*)}]
\end{enumerate}
\end{document}


As indicated by AndreC, the problem is really made for something in the align family, rather than xlop, given that all 4 problems have to be provided in advance for the proper field widths to be known.

I'm not sure you want this, because the alignment will be rather weird.

\documentclass{article}
\usepackage{array,xlop}

{%
\par
\vspace{\topsep}%
\setcounter{enumi}{0}%
\renewcommand{\theenumi}{(\arabic{enumi})}%
\renewcommand{\item}{%
\refstepcounter{enumi}%
\makebox[\labelwidth][r]{\theenumi}%
}%
\noindent
\tabular{
@{}
c
>{$}r<{$}
@{${}+{}$}
>{$}l<{$}
@{${}={}$}
l
@{}
}
}{%
\endtabular
\par\vspace{\topsep}%
}

\begin{document}

\end{document}


With a simple array:

\documentclass[20pt,fleqn,leqno]{extarticle}
\newcounter{No}
\newcommand\opadd[2]{\stepcounter{No}(\theNo) & #1 & #2 & \the\numexpr#1+#2\relax}
\begin{document}

$\begin{array}{r @{\quad} r @{\,+\,} l @{\,=\,} l } \opadd{61}{7} \\ \opadd{1}{7}\\ \opadd{161}{7}\\ \opadd{1}{700} \\ \end{array}$
\end{document}


The next array needs a preceeding \setcounter{No}{0}