Search code examples
latexalignmentvertical-alignmentdigitstext-alignment

latex: indents in the equation (boxes instead of digit)


I want to do the task - addition to the column with unknown digits.

How to make everything so that it is aligned in the center of the boxes and digits?

To digits were under the digits, boxes under the digits, digits under the boxes?

\def\msquare{\mathord{\scalerel*{\Box}{gX}}}


\begin{multline*}
\begin{array}{r}
+
\begin{array}{r}
\msquare64\msquare\msquare\msquare\\
661977\\
\end{array}\\
\hline
\begin{array}{r}
1\msquare\msquare631\msquare
\end{array}\\
\end{array}
\end{multline*}

enter image description here


Solution

  • This can be done with an array. As your values are just squares or number, it is better to use the tabular environment where intercolumn spacing can be more finely controlled. To do that, the simpler is to redefine the tabcolsep length, but there packages like array that can provide other means to control it.

    \documentclass{article}
    \usepackage{amsmath}
    \usepackage{array}
    
    \begin{document}
    % \def\msquare{\mathord{\scalerel*{\Box}{gX}}} % redifined, because I do know what \Box does.
    \def\msquare{\raisebox{1mm}{\framebox[2mm][r]{}}}
    
    
    \setlength{\tabcolsep}{0.5pt}
    \begin{multline*}
      \begin{array}{r}
        +
        \begin{tabular}{ccccccc}
          &\msquare&6&4&\msquare&\msquare&\msquare\\
          &6&6&1&9&7&7\\
          \hline
          1&\msquare&\msquare&6&3&1&\msquare
        \end{tabular}\\
      \end{array}
    \end{multline*}
    \end{document}
    

    enter image description here

    To avoid the redefinition of tabcolsep in all your document, enclose this code in braces.