4

I'm trying to build a graphic illustration of how a binary multiplication is solved, but I'm facing some problems while trying to align the cells of the array. Here's the code:

\begin{array}{rrrrrr}
    &&1&1&0 & * \\
    &&&1&1 & = \\
\end{array}\newline
\rule{0.25\textwidth}{0.4pt}\\
\begin{array}{rrrrrr}
    &&1&1&0 &  \\
    &1&1&0&- &  \\
\end{array}\newline
\rule{0.25\textwidth}{0.4pt}\\
\begin{array}{rrrrrr}
    1&0&0&1&0_2 \\
\end{array}\newline

And here's the result: enter image description here

2
  • Try using a single array. Oct 9, 2021 at 9:26
  • Welcome to TeX.SE.
    – Mico
    Oct 9, 2021 at 10:13

1 Answer 1

4

You should use only one {array}.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\begin{document}

$\begin{array}{@{}cccccc@{}}
  &   & 1 & 1 & 0  & * \\
  &   &   & 1 & 1  & = \\ \hline
  &   & 1 & 1 & 0 \\
  & 1 & 1 & 0 & \text{--} \\ \hline
1 & 0 & 0 & 1 & 0_2 \\
\end{array}$

\end{document}

Output of the above code

3
  • That's nice! Is there any way to align the 0_2 to the right so that the 0 is aligned with the other numbers as well?
    – Shark44
    Oct 9, 2021 at 9:46
  • 1
    @Shark44 - You could replace 0_2 with 0\rlap{$_2$}. Alternatively, you could load the mathtools package (a superset of the amsmath package) and replace 0_2 with 0\mathrlap{_2}.
    – Mico
    Oct 9, 2021 at 10:13
  • Thank you! It works perfectly
    – Shark44
    Oct 9, 2021 at 11:59

You must log in to answer this question.

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