[Tex/LaTex] How to make equal width columns

arraystables

Based on Leo's answer but I removed one column and replaced the \big) with a vertical rule. Now I want to make all columns have the same width. How to do this?

enter image description here

\documentclass{article}
\usepackage{amssymb}

\begin{document}

\[
x^3 - x + 1 = (x-1)(x^2+x) + 1 \in \mathbb{F}_3[x]
\]

\[
\renewcommand\arraystretch{1.2}
\begin{array}{*{6}{r}}
&
    &
        &
            1&
                1&
                    0\\\cline{3-6}
1&
    -1&
        \multicolumn{1}{|r}{1}&
                                0&
                                    -1&
                                        1\\
&
    & 
        1&
            -1&
                &
                    \\\cline{3-5}
&
    &
        &
            1&
                -1&
                    \\
&
    &
        &
            1&
                -1&
                    \\\cline{4-6}
&
    &
        &
            &
                &
                    1\\
\end{array}
\]

\end{document}

I got the solution by using \begin{array}{*{6}{>{\hfill}m{1cm}}}, but is there any other solution?

Best Answer

I would prefer, but it's a question of taste, the following:

\usepackage{array}
\newcolumntype{R}[1]{>{\hbox to #1\bgroup\hfill$}c<{$\egroup}}

...
\[
\renewcommand\arraystretch{1.2}
\newcommand\x[1]{\multicolumn{1}{|r}{#1}} % just not to clutter the array
\begin{array}{*{6}{R{1.5em}}}
  &    &       & 1  &  1 & 0 \\\cline{3-6}
1 & -1 & \x{1} & 0  & -1 & 1 \\
  &    &    1  & -1 &    &   \\\cline{3-5}
  &    &       &  1 & -1 &   \\
  &    &       &  1 & -1 &   \\\cline{4-6}
  &    &       &    &    & 1 
\end{array}
\]

The syntax \hbox to <dimen> is low level TeX, which is generally not recommended in LaTeX because it can have disastrous effects on color management. However, since this is done at the start at the cell, it should not be a problem. The construction \hbox to 1.5em{\hfil x} is similar to \makebox[1.5em][r]{x}, but it can be split into two parts: \hbox to 1.5em\bgroup at the beginning and \egroup at the end, so the "argument" can be gathered with array's syntax.

A similar setup can be obtained by

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash$}p{#1}<{$}}
Related Question