4

I am having the issue with the alignment of an array.

Please, find the below code:

\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
          a4paper,
          total={170 mm,257 mm},
          left=20 mm,
          top=20 mm,
         }
\usepackage{amsmath,bm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{arydshln}

\setlength{\parindent}{2em}

\newcommand{\wt}[2]{\underset{\substack{\textstyle\uparrow\\\hidewidth\mathstrut#2\hidewidth}}{#1}}
\definecolor{mygray}{gray}{0.6}

\begin{document}
  \textbf{Solution :}\\
    \[
    \left.
    \hspace{1 cm}
    \begin{array}{cccccc}
               &   & 1 & 0 & 1 & 0 \\
        \times &   &   & 1 & 0 & 1 \\
        \hline
               & \underline{1} & 1 & 0 & 1 & 0 \\
               & 0 & 0 & 0 & 0 &   \\
             1 & 0 & 1 & 0 &   &   \\
        \hline
             1 & 1 & 0 & 0 & 1 & 0 \\
    \end{array}
    \right. \hspace{0.25 cm}\vline \hspace{0.1 cm} \text{\parbox[t]{13 cm}{As, the product of binary multiplication would always be less than 2. It won't generate any carry.}}
    \begin{array}{ccccccccc}
        & & \textbf{Product/Sum} & & \textbf{Base} & & \textbf{Carry} & & \textbf{Result} \\
        1 + 0 + 1 & = & 2 > 1 & = & 2 & \times & 1 & + & 0 \\[0.2 cm]   
    \end{array}
    \]
\end{document}

The obtained output of this is as follows:

Obtained output

As, one can see in the image the second array is aligned to the right of the text. I want that array below the text.

The desired output is as follows: Desired output

Can anyone help me to solve this issue?

3

Probably not too elegant since I used nested tabulars to position math elements, texts and lines.

enter image description here

\documentclass[12 pt, a4paper]{book}
\usepackage{multicol}
\usepackage{geometry}
\geometry{
          a4paper,
          total={170 mm,257 mm},
          left=20 mm,
          top=20 mm,
         }
\usepackage{amsmath,bm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{soul}
\usepackage{indentfirst}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{enumitem}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{arydshln}

\setlength{\parindent}{2em}

\newcommand{\wt}[2]{\underset{\substack{\textstyle\uparrow\\\hidewidth\mathstrut#2\hidewidth}}{#1}}
\definecolor{mygray}{gray}{0.6}

\usepackage{calc}

\begin{document}
  \textbf{Solution :}
  
\begin{tabular}{p{0.25\textwidth-2\tabcolsep-\arrayrulewidth}|p{0.75\textwidth-2\tabcolsep}}
        \(\begin{array}[t]{cccccc}
               &   & 1 & 0 & 1 & 0 \\
        \times &   &   & 1 & 0 & 1 \\
        \hline
               & \underline{1} & 1 & 0 & 1 & 0 \\
               & 0 & 0 & 0 & 0 &   \\
             1 & 0 & 1 & 0 &   &   \\
        \hline
             1 & 1 & 0 & 0 & 1 & 0 \\
    \end{array}\)
    &
    \begin{tabular}[t]{@{}p{0.75\textwidth-2\tabcolsep}@{}}
    As, the product of binary multiplication would always be less than 2. It won't generate any carry. \\
    \hdashline   
    \[\begin{array}{ccccccccc}
        & & \textbf{Product/Sum} & & \textbf{Base} & & \textbf{Carry} & & \textbf{Result} \\
        1 + 0 + 1 & = & 2 > 1 & = & 2 & \times & 1 & + & 0 \\[0.2 cm]   
    \end{array}\]
    \end{tabular}
\end{tabular}

\end{document}
| improve this answer | |
4

In order not to guess about the width of the material on the right side, you can use tabularx and nest array and tabular in it.

\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath,bm}
\usepackage{tabularx,array}
\usepackage{arydshln}

\geometry{
  a4paper,
  total={170 mm,257 mm},
  left=20 mm,
  top=20 mm,
}

\begin{document}

\noindent\textbf{Solution:}
\[
\begin{tabularx}{\textwidth}{@{} c | X @{}}
$\begin{array}{cccccc}
         &   & 1 & 0 & 1 & 0 \\
  \times &   &   & 1 & 0 & 1 \\
  \hline
         & \underline{1} & 1 & 0 & 1 & 0 \\
         & 0 & 0 & 0 & 0 &   \\
       1 & 0 & 1 & 0 &   &   \\
  \hline
       1 & 1 & 0 & 0 & 1 & 0 \\
\end{array}$ &
\begin{tabular}{@{}p{\linewidth}@{}}
As the product of binary multiplication would always be less than~$2$,
it won't generate any carry.
\\[2ex]
\hdashline
\[\begin{array}{ccccccccc}
  & & \textbf{Product/Sum} & & \textbf{Base} & & \textbf{Carry} & & \textbf{Result} \\
  1 + 0 + 1 & = & 2 > 1 & = & 2 & \times & 1 & + & 0 \\[0.2 cm]   
\end{array}\]
\end{tabular}
\end{tabularx}
\]

\end{document}

enter image description here

| improve this answer | |
2

I propose this variant code, also based on tabularx, but using a matrix environment and \Longstack for the part under the dashed line:

\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath,bm}
\usepackage{tabularx}
\usepackage{arydshln, booktabs,}
\usepackage[usestackEOL]{stackengine}

\geometry{a4paper, total={170 mm,257 mm}, left=20 mm, top=20 mm}

\begin{document}

\noindent\textbf{Solution:}
\[
\begin{tabularx}{\textwidth}{@{} c | X @{}}
$\begin{matrix}
         & & 1 & 0 & 1 & 0 \\
  \times & & & 1 & 0 & 1 \\
  \midrule
         & ^{\underline{1}} & 1 & 0 & 1 & 0 \\
         & 0 & 0 & 0 & 0 & \\
       1 & 0 & 1 & 0 & & \\
  \midrule
       1 & 1 & 0 & 0 & 1 & 0 \\
\end{matrix}$\enspace &
\begin{tabular}{@{}p{\linewidth}@{}}
As the product of binary multiplication would always be less than~$2$,
it won't generate any carry.
\\[2ex]
\hdashline
\stackMath
\[ 1 + 0 + 1 = \Longstack{\textbf{Product/Sum} \\ 2 > 1} = \Longstack{ \textbf{Base}\\ 2} \times \Longstack{\textbf{Carry}\\ 1}
  + \Longstack{\\\textbf{Result}\\0} \]
\end{tabular}
\end{tabularx}
\]

\end{document} 

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.