表格数组宽度错误

表格数组宽度错误

我想创建一个具有索引(左侧和顶部位置)以及总列和行(底部和右侧位置)的矩阵。我尝试过:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{table}
                \begin{center}
                    \begin{tabular}{c c c c }
%                       &&~~~$ \begin{array}{ccccccccccc}
                        &&$ \begin{array}{lllllllllllllllll}
                            1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11
                        \end{array}$&\\
                        \\
                        $M^2$ =& $\begin{array}{c}
                        1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\ 7 \\ 8 \\ 9 \\ 10 \\ 11
                        \end{array}$
                         & $\left( \begin{array}{lllllllllllllllll}
                          5 & 1 & 3 & 7 & 6 & 5 & 5 & 3 & 4 & 5 & 6 \\ 
                          6 & 2 & 1 & 7 & 6 & 4 & 4 & 2 & 2 & 6 & 5 \\ 
                          3 & 2 & 2 & 5 & 4 & 3 & 5 & 2 & 3 & 4 & 4 \\ 
                          5 & 3 & 3 & 8 & 6 & 4 & 5 & 1 & 2 & 5 & 5 \\ 
                          3 & 1 & 1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 2 \\ 
                          2 & 0 & 1 & 1 & 2 & 2 & 1 & 1 & 1 & 2 & 2 \\ 
                          4 & 2 & 2 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 \\ 
                          1 & 1 & 2 & 3 & 3 & 3 & 3 & 2 & 2 & 3 & 4 \\ 
                          4 & 2 & 3 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 \\ 
                          5 & 2 & 2 & 7 & 6 & 5 & 5 & 2 & 2 & 7 & 6 \\ 
                          5 & 2 & 4 & 7 & 7 & 6 & 5 & 2 & 3 & 5 & 7 \\
                        \end{array}\right)$&
                        $\begin{array}{c}
                        50 \\ 45 \\ 37 \\ 47 \\ 24 \\ 15 \\ 43 \\ 27 \\ 44 \\ 49 \\ 53 %rowSums
                        \end{array}$\\
                        \\
                        &&$ \begin{array}{lllllllllllllllll}
                            43 & 18 & 24 & 59 & 53 & 42 & 46 & 21 & 28 & 49 & 51 %colSums
                        \end{array}$&\\
                    \end{tabular}
                \end{center}
            \end{table}

\end{document}

但是顶部和底部的索引/总和与矩阵不对齐...我该怎么做?

在此处输入图片描述

答案1

借助blkarray

% arara: pdflatex

\documentclass{article}
\usepackage{blkarray}
\usepackage{xcolor}
\newcommand*{\matindex}[1]{\mbox{\scriptsize#1}}
\newcommand*{\matsum}[1]{\color{red} #1}

\begin{document}
\[
    M^2 =
    \begin{blockarray}{*{13}{c}}
        & \matindex1 & \matindex2 & \matindex3 & \matindex4 & \matindex5 & \matindex6 & \matindex7 & \matindex8 & \matindex9 & \matindex{10} & \matindex{11} & \\
        \begin{block}{r(*{11}{c})c}
            \matindex1 & 5 & 1 & 3 & 7 & 6 & 5 & 5 & 3 & 4 & 5 & 6 & \matsum{50} \\ 
            \matindex2 & 6 & 2 & 1 & 7 & 6 & 4 & 4 & 2 & 2 & 6 & 5 & \matsum{45} \\ 
            \matindex3 & 3 & 2 & 2 & 5 & 4 & 3 & 5 & 2 & 3 & 4 & 4 & \matsum{37} \\ 
            \matindex4 & 5 & 3 & 3 & 8 & 6 & 4 & 5 & 1 & 2 & 5 & 5 & \matsum{47} \\ 
            \matindex5 & 3 & 1 & 1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 2 & \matsum{24} \\ 
            \matindex6 & 2 & 0 & 1 & 1 & 2 & 2 & 1 & 1 & 1 & 2 & 2 & \matsum{15} \\ 
            \matindex7 & 4 & 2 & 2 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 & \matsum{43} \\ 
            \matindex8 & 1 & 1 & 2 & 3 & 3 & 3 & 3 & 2 & 2 & 3 & 4 & \matsum{27} \\ 
            \matindex9 & 4 & 2 & 3 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 & \matsum{44} \\ 
            \matindex{10} & 5 & 2 & 2 & 7 & 6 & 5 & 5 & 2 & 2 & 7 & 6 & \matsum{49} \\ 
            \matindex{11} & 5 & 2 & 4 & 7 & 7 & 6 & 5 & 2 & 3 & 5 & 7 & \matsum{53} \\
        \end{block}
        & \matsum{4}3 & \matsum{18} & \matsum{24} & \matsum{59} & \matsum{53} & \matsum{42} & \matsum{46} & \matsum{21} & \matsum{28} & \matsum{49} & \matsum{51} & \\
    \end{blockarray}
\]  
\end{document}

在此处输入图片描述

答案2

bigdelim下面是使用和multirow包并执行命令的 MWE \bigdelim

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bigdelim}
\usepackage{multirow}
\begin{document}
\begin{center}
$M^2=\quad%
\begin{array}{@{}cl@{\hspace{0.5em}}*{11}{c}@{\hspace{0.5em}}rr}
 &                  & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 &                     & \\\noalign{\vskip1ex}
1 & \ldelim({11}{10pt}  & 5 & 1 & 3 & 7 & 6 & 5 & 5 & 3 & 4 & 5 & 6 & \rdelim){11}{10pt}& 50 \\ 
2 &                 & 6 & 2 & 1 & 7 & 6 & 4 & 4 & 2 & 2 & 6 & 5 &                       & 45 \\ 
3 &                 & 3 & 2 & 2 & 5 & 4 & 3 & 5 & 2 & 3 & 4 & 4 &                       & 37 \\ 
4 &                 & 5 & 3 & 3 & 8 & 6 & 4 & 5 & 1 & 2 & 5 & 5 &                       & 47 \\ 
5 &                 & 3 & 1 & 1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 2 &                       & 24 \\ 
6 &                 & 2 & 0 & 1 & 1 & 2 & 2 & 1 & 1 & 1 & 2 & 2 &                       & 15 \\ 
7 &                 & 4 & 2 & 2 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 &                       & 43 \\ 
8 &                 & 1 & 1 & 2 & 3 & 3 & 3 & 3 & 2 & 2 & 3 & 4 &                       & 27 \\ 
9 &                 & 4 & 2 & 3 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 &                       & 44 \\ 
10 &                    & 5 & 2 & 2 & 7 & 6 & 5 & 5 & 2 & 2 & 7 & 6 &                   & 49 \\ 
11 &                    & 5 & 2 & 4 & 7 & 7 & 6 & 5 & 2 & 3 & 5 & 7 &                   & 53 \\\noalign{\vskip1ex}
 &                  & 43 & 18 & 24 & 59 & 53 & 42 & 46 & 21 & 28 & 49 & 51 &            &  %colSums
\end{array}$
\end{center}
\begin{table}
                \begin{center}
                    \begin{tabular}{c c c c }
%                       &&~~~$ \begin{array}{ccccccccccc}
                        &&$ \begin{array}{lllllllllllllllll}
                            1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11
                        \end{array}$&\\
                        \\
                        $M^2$ =& $\begin{array}{c}
                        1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\ 7 \\ 8 \\ 9 \\ 10 \\ 11
                        \end{array}$
                         & $\left( \begin{array}{lllllllllllllllll}
                          5 & 1 & 3 & 7 & 6 & 5 & 5 & 3 & 4 & 5 & 6 \\ 
                          6 & 2 & 1 & 7 & 6 & 4 & 4 & 2 & 2 & 6 & 5 \\ 
                          3 & 2 & 2 & 5 & 4 & 3 & 5 & 2 & 3 & 4 & 4 \\ 
                          5 & 3 & 3 & 8 & 6 & 4 & 5 & 1 & 2 & 5 & 5 \\ 
                          3 & 1 & 1 & 2 & 3 & 2 & 3 & 2 & 3 & 2 & 2 \\ 
                          2 & 0 & 1 & 1 & 2 & 2 & 1 & 1 & 1 & 2 & 2 \\ 
                          4 & 2 & 2 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 \\ 
                          1 & 1 & 2 & 3 & 3 & 3 & 3 & 2 & 2 & 3 & 4 \\ 
                          4 & 2 & 3 & 6 & 5 & 4 & 5 & 2 & 3 & 5 & 5 \\ 
                          5 & 2 & 2 & 7 & 6 & 5 & 5 & 2 & 2 & 7 & 6 \\ 
                          5 & 2 & 4 & 7 & 7 & 6 & 5 & 2 & 3 & 5 & 7 \\
                        \end{array}\right)$&
                        $\begin{array}{c}
                        50 \\ 45 \\ 37 \\ 47 \\ 24 \\ 15 \\ 43 \\ 27 \\ 44 \\ 49 \\ 53 %rowSums
                        \end{array}$\\
                        \\
                        &&$ \begin{array}{lllllllllllllllll}
                            43 & 18 & 24 & 59 & 53 & 42 & 46 & 21 & 28 & 49 & 51 %colSums
                        \end{array}$&\\
                    \end{tabular}
                \end{center}
            \end{table}

\end{document}

将阵列设置更改为

{@{}cl@{\,\,}*{11}{@{\,\,}c@{\,\,}}@{\,\,}rc}

您将得到一个更窄的数组,如下所示。

在此处输入图片描述

相关内容