TransWikia.com

Issue with the alignment of the array

TeX - LaTeX Asked on September 2, 2021

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{textstyleuparrowhidewidthmathstrut#2hidewidth}}{#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 Answers

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{textstyleuparrowhidewidthmathstrut#2hidewidth}}{#1}}
definecolor{mygray}{gray}{0.6}

usepackage{calc}

begin{document}
  textbf{Solution :}
  
begin{tabular}{p{0.25textwidth-2tabcolsep-arrayrulewidth}|p{0.75textwidth-2tabcolsep}}
        (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.75textwidth-2tabcolsep}@{}}
    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}

Correct answer by leandriis on September 2, 2021

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}

noindenttextbf{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

Answered by egreg on September 2, 2021

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}

noindenttextbf{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}} ]
end{tabular}
end{tabularx}
]

end{document} 

enter image description here

Answered by Bernard on September 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP