[Tex/LaTex] How to display simply an addition in latex

math-mode

Given A, B, C any string or maths code, given + any operation of my choice, I would like to display a really simple calculation – here addition. On below the result I would like to obtain :

 A
+B
__
 C

I can't do it here, but please see the underline as right under B (not my above ugly displaying). A, B and C should be aligned. The operator is displayed on the left of B.

Actually, I am wondering if there is a package for that, to perform this simply ?

Best Answer

What you can do is use the tabular environment:

\documentclass[12pt,a4paper]{article}

\usepackage{array}
\usepackage{siunitx}


\begin{document}

\begin{tabular}{lS}
  & 354.42\\
  $+$& 42.1\\
  & 396.52\\
\end{tabular}

\end{document}

By using the S column of the siunitx package, you are able to set everything accordingly to their value (unidades, decenas, centenas, etc.)

Now, regarding the line... I'm sorry, but I don't know what is the best approach. The result of the code mentioned above is:

enter image description here

I just realized that you could use \hline or \bottomrule if using the booktabs package and get something decent:

\documentclass[12pt,a4paper]{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{siunitx}


    \begin{document}

    \begin{tabular}{lS}
      & 354.42\\
      $+$& 42.1\\
    \hline %or \bottomrule if using the `booktabs` package
      & 396.52\\
    \end{tabular}

\end{document}

This would be the result:

enter image description here

Related Question