2

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*)}]
            \item { \opadd[style=text] {61}{7} }
            \item {\opadd[style=text] {1}{7} }
            \item {\opadd[style=text] {161}{7} }
            \item {\opadd[style=text] {1}{700} }
        \end{enumerate}

    \end{document}

Current output

enter image description here

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

enter image description here

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? enter image description here

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.

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

3 Answers 3

2

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}
\newcommand\mopadd[2]{\makebox[\mopwid][r]{%
  \opadd[style=text] {#1}{#2}%
  \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*)}]
        \item { \mopadd{61}{7} }
        \item {\mopadd{1}{7} }
        \item {\mopadd{161}{7} }
        \item {\mopadd{1}{700} }
    \end{enumerate}
\end{document}

enter image description here

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.

1

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

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

\newenvironment{additions}
 {%
  \par
  \vspace{\topsep}%
  \setcounter{enumi}{0}%
  \renewcommand{\theenumi}{(\arabic{enumi})}%
  \renewcommand{\item}{%
    \refstepcounter{enumi}%
    \makebox[\labelwidth][r]{\theenumi}%
  }%
  \renewcommand{\opadd}[3][]{&##2&##3&\the\numexpr##2+##3\relax}%
  \noindent
  \tabular{
    @{}
    c
    >{$}r<{$}
    @{${}+{}$}
    >{$}l<{$}
    @{${}={}$}
    l
    @{}
  }
 }{%
   \endtabular
   \par\vspace{\topsep}%
 }

\begin{document}

\begin{additions}
\item \opadd[style=text]{61}{7} \\
\item \opadd[style=text]{1}{7} \\
\item \opadd[style=text]{161}{7} \\
\item \opadd[style=text]{1}{700} \\
\end{additions}

\end{document}

enter image description here

1

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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .