Math & ScienceVertical arithmetic

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
bluefoxicy
Posts: 5
Joined: Thu Jan 28, 2010 2:51 pm

Vertical arithmetic

Post by bluefoxicy »

Google isn't helping so...

I'm trying to make output that looks like the following:

Code: Select all

  3
 10
x 2.5
-----
 45
The best I can get is of course

Code: Select all

3 \times 10 \times 2.5 = 45
Trying to write some very basic math stuff into a basic math-to-algebra book.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Vertical arithmetic

Post by localghost »

See code below for two possible solutions.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{booktabs,dcolumn}

\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}
  \begin{alignat*}{2}
    \quad  &     & 3   \\
    \times &\quad& 10  \\
    \times &\quad& 1.5 \\ \cline{1-3}
           &     & 45
  \end{alignat*}

  \[
    \begin{array}{@{}cd{2.1}@{}}
             & 3   \\
      \times & 10  \\
      \times & 1.5 \\ \midrule
             & 45
    \end{array}
  \]
\end{document}

Best regards
Thorsten
bluefoxicy
Posts: 5
Joined: Thu Jan 28, 2010 2:51 pm

Vertical arithmetic

Post by bluefoxicy »

Thanks. I eventually came up with:

Code: Select all

\begin{tabular}{l r}
 & 345\\
+& 456\\
\hline
 & 801
\end{tabular}
Bigger challenges include actually processing LaTeX to output, i.e. this renders great in pdflatex and latex2html but not on Kindle (Kindle ignores html tables); pdflatex generates zero-margin columns with @{} while latex2html doesn't; etc.

So with this long addition, I'll have to play with it to get it on Kindle. I might try to define \longaddition{345}{456}...{801} or something so I can mess with it later.
Post Reply