2

I want to achieve to get this multiplication in ternary:

enter image description here

I tried:

\begin{center}
\begin{tabular}{c}
$212011 \cdot 122$ \\
\hline $212011$ \\
$1201022$ \\
$1201022$ \\
\hline $112120112$ \\
\hline \hline
\end{tabular}
\end{center}

But in my result the lines are too long and the numbers are not aligned.

I also tried this

$$
\begin{gathered}
212011 \cdot 122 \\
\hline 212011 \\
1201022 \\
1201022 \\
\hline 112120112 \\
\hline \hline
\end{gathered}
$$

But that is also not correct. Can someone help me understand how the author achieved this table?

2
  • 1
    Unrelated to your question, but you should use \[ ... \] instead of $$ ... $$. tex.stackexchange.com/q/503/125871
    – Sandy G
    Commented May 25 at 1:09
  • 1
    I remember using \phantom{} for a similar case: \hline 212011 \` becomes then \hline 212011\phantom{.00} \`
    – gildux
    Commented May 25 at 2:31

2 Answers 2

2

Use a “placeholder” to pad the digits.

\documentclass{article}

\begin{document}
\[
\begingroup\lccode`~=`?\lowercase{\endgroup\def~}{\phantom{0}}
\mathcode`?="8000
\begin{array}{@{}r@{}}
212011 \cdot 122 \\
\hline
 212011?? \\
 1201022? \\
  1201022 \\
\hline
112120112 \\
\hline \hline
\end{array}
\]

\end{document}

I locally define ? to be a “phantom digit”, so the alignment is kept.

enter image description here

With a similar idea you can define . to give a \cdot centered in the space of a digit.

\documentclass{article}

\newcommand{\activatechar}[2]{%
  \begingroup\lccode`~=`#1\lowercase{\endgroup\def~}{#2}%
  \mathcode`#1="8000
}

\begin{document}
\[
\activatechar{?}{\phantom{0}}
\activatechar{.}{{\ooalign{\phantom{0}\cr\hidewidth$\cdot$\hidewidth\cr}}}
\begin{array}{@{}r@{}}
212011.122 \\ \hline
  212011?? \\
  1201022? \\
   1201022 \\ \hline
 112120112 \\ \hline \hline
\end{array}
\]

\end{document}

I defined a helper command for making characters math active (better to use it only locally).

enter image description here

3
  • This looks almost perfect but the number left from \cdot is not aligned with the numbers below. Commented May 24 at 22:31
  • 1
    @calculatormathematical Why should it be aligned with the numbers below? It isn't in the sum.
    – jlab
    Commented May 24 at 23:12
  • 1
    @calculatormathematical I don't think it's necessary, as the first line doesn't participate to the alignment. Anyway, I added a simple way to get the alignment.
    – egreg
    Commented May 25 at 8:39
5

You could make a column for each ternary place and remove spaces between columns:

enter image description here

\documentclass{article}

\begin{document}

\[
\begin{array}{*{10}{@{}c@{}}}
2&1&2&0&1&1&\cdot&1&2&2\\\hline 
&&2&1&2&0&1&1\\
&&1&2&0&1&0&2&2&\\
&&&1&2&0&1&0&2&2\\\hline
&1&1&2&1&2&0&1&1&2\\\hline \hline
\end{array}
\]

\end{document}

You must log in to answer this question.

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