我怎样才能使大矩阵看起来好看?

我怎样才能使大矩阵看起来好看?

我必须将大型矩阵放入我的论文中,但我找不到一种漂亮的方式来做到这一点。问题是:这些矩阵确实很稀疏,但出于分析目的,我需要它们完整。

到目前为止,我已经设法像这样表示它们(在值为 0 的地方留下空白): 我的丑陋矩阵

问题是,矩阵是 14x14,但我需要第一行/列来显示数字 1->14。

有什么想法可以在保持完整性的同时对其进行改进吗?

编辑:这是MWE:

\documentclass[11pt,a4paper]{article}
\usepackage{array}
\begin{document}
\begin{table}[!h]
\centering
\begin{tabular}{|c>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.7cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.5cm}|>{\centering\arraybackslash}p{0.85cm}|}
\hline
{\bfseries SVM} & \multicolumn{1}{|c|}{1} & \multicolumn{1}{c|}{2} & \multicolumn{1}{c|}{3} & \multicolumn{1}{c|}{4} & \multicolumn{1}{c|}{5} & \multicolumn{1}{c|}{6} & \multicolumn{1}{c|}{7} & \multicolumn{1}{c|}{8} & \multicolumn{1}{c|}{9} & \multicolumn{1}{c|}{10} & \multicolumn{1}{c|}{11} & \multicolumn{1}{c|}{12} & \multicolumn{1}{c|}{13} & \multicolumn{1}{c|}{14} \\
\hline
\multicolumn{1}{|c|}{1} &   &   &   &   &   &   &   &   &   &   &   &   &   & 2.3 \\
\hline \multicolumn{1}{|c|}{2} &   &   &   &   &   &   &   &   &   &   &   &   &   & 0.4 \\  
\hline \multicolumn{1}{|c|}{3} & & & & & & & & & & & & & & \\  
\hline \multicolumn{1}{|c|}{4} & & & & & & & & & & & & & & 0.2 \\
\hline  \multicolumn{1}{|c|}{5} && & & & & & & & 0.7 & & & & & 1.2 \\                   
\hline \multicolumn{1}{|c|}{6} & & & & & & & & & & & & & & 0.3 \\  
\hline \multicolumn{1}{|c|}{7} & & & & & & & & & & & & & & 0.2 \\         
\hline \multicolumn{1}{|c|}{8} & & & & & & & & & & & & & & 0.1 \\  
\hline \multicolumn{1}{|c|}{9} & & & & & & & & & 3.4 & & & & & 1.5 \\  
\hline \multicolumn{1}{|c|}{10} & & & & & & & & & & 11.0 & & & & \\      
\hline  \multicolumn{1}{|c|}{11} & & & & & & & & & & & & & & 0.1 \\      
\hline \multicolumn{1}{|c|}{12} & & & & & & & & & & & & & & 2.6 \\  
\hline \multicolumn{1}{|c|}{13} & & & & & & & & & & & & & & 0.1 \\  
\hline \multicolumn{1}{|c|}{14} & & & & & & & & & 0.2 & 0.3 & & & & 200.0 \\ 
\hline
\end{tabular}
\caption{Mean confusion matrices for the first multi-class classification.}
\label{table6}
\end{table}
\end{document}

答案1

有几种可能性:

在此处输入图片描述

\documentclass[11pt,a4paper]{article}
\usepackage{dcolumn}
\newcolumntype{d}{D..{3.1}}
\begin{document}


\noindent X\dotfill X

\bigskip
\begin{table}[htp]% not ever [!h]
\centering

\setlength\tabcolsep{.37pt}
\small
\begin{tabular}{@{}|D..{2.0}|*{14}{d|}@{}}
\hline
\multicolumn{1}{|c|}{\footnotesize\bfseries SVM} &
 \multicolumn{1}{c|}{1}
 & \multicolumn{1}{c|}{2}
 & \multicolumn{1}{c|}{3}
 & \multicolumn{1}{c|}{4}
 & \multicolumn{1}{c|}{5}
 & \multicolumn{1}{c|}{6}
 & \multicolumn{1}{c|}{7}
 & \multicolumn{1}{c|}{8}
 & \multicolumn{1}{c|}{9}
 & \multicolumn{1}{c|}{10}
 & \multicolumn{1}{c|}{11}
 & \multicolumn{1}{c|}{12}
 & \multicolumn{1}{c|}{13}
 & \multicolumn{1}{c|}{14}
 \\
\hline
1 &   &   &   &   &   &   &   &   &   &   &   &   &   & 2.3 \\
\hline 2 &   &   &   &   &   &   &   &   &   &   &   &   &   & 0.4 \\  
\hline 3 & & & & & & & & & & & & & & \\  
\hline 4 & & & & & & & & & & & & & & 0.2 \\
\hline  5 && & & & & & & & 0.7 & & & & & 1.2 \\                   
\hline 6 & & & & & & & & & & & & & & 0.3 \\  
\hline 7 & & & & & & & & & & & & & & 0.2 \\         
\hline 8 & & & & & & & & & & & & & & 0.1 \\  
\hline 9 & & & & & & & & & 3.4 & & & & & 1.5 \\  
\hline 10 & & & & & & & & & & 11.0 & & & & \\      
\hline  11 & & & & & & & & & & & & & & 0.1 \\      
\hline 12 & & & & & & & & & & & & & & 2.6 \\  
\hline 13 & & & & & & & & & & & & & & 0.1 \\  
\hline 14 & & & & & & & & & 0.2 & 0.3 & & & & 200.0 \\ 
\hline
\end{tabular}
\caption{Mean confusion matrices for the first multi-class classification.}
\label{table6}
\end{table}

\begin{table}[htp]% not ever [!h]
\centering

\setlength\tabcolsep{.58pt}
\small
\def\z{\multicolumn{1}{D.\cdot{2.2}}{.}}

\begin{tabular}{@{}D..{2.0}|*{14}{d}@{}}

\multicolumn{1}{c|}{\footnotesize\bfseries SVM} &
 \multicolumn{1}{c}{1}
 & \multicolumn{1}{c}{2}
 & \multicolumn{1}{c}{3}
 & \multicolumn{1}{c}{4}
 & \multicolumn{1}{c}{5}
 & \multicolumn{1}{c}{6}
 & \multicolumn{1}{c}{7}
 & \multicolumn{1}{c}{8}
 & \multicolumn{1}{c}{9}
 & \multicolumn{1}{c}{10}
 & \multicolumn{1}{c}{11}
 & \multicolumn{1}{c}{12}
 & \multicolumn{1}{c}{13}
 & \multicolumn{1}{c}{14}
 \\
\hline
1 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 2.3 \\
 2 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.4 \\  
 3 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & \\  
 4 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.2 \\
  5 &\z &\z &\z &\z &\z &\z &\z &\z & 0.7 &\z &\z &\z &\z & 1.2 \\                   
 6 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.3 \\  
 7 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.2 \\         
 8 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.1 \\  
 9 &\z &\z &\z &\z &\z &\z &\z &\z & 3.4 &\z &\z &\z &\z & 1.5 \\  
 10 &\z &\z &\z &\z &\z &\z &\z &\z &\z & 11.0 &\z &\z &\z & \\      
  11 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.1 \\      
 12 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 2.6 \\  
 13 &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z &\z & 0.1 \\  
 14 &\z &\z &\z &\z &\z &\z &\z &\z & 0.2 & 0.3 &\z &\z &\z & 200.0 \\ 

\end{tabular}
\caption{Mean confusion matrices for the first multi-class classification.}
\label{tablezz}
\end{table}

\end{document}

答案2

以下是我要修改的方法。表格的美观程度可能是主观的,但我认为线条只会增加噪音,使阅读表格变得“更难”。我更喜欢只使用(稀疏的)水平线,或者交替使用行颜色,就像在这种情况下一样。

任何添加的包或命令都已在代码中注释,以作简要说明。如果您有具体问题,请发表评论。


编辑:我已经根据小数点分隔符添加了正确的数值对齐。

没有垂直线的图形

\documentclass{article}
\usepackage{booktabs, dcolumn} % required for \toprule command. Others are \midrule, and \bottomrule, second one required for aligning numerals by decimal separator
\usepackage{array,ragged2e}
\usepackage[table]{xcolor}    % loads also »colortbl«, required for the alternate row colours

\makeatletter
\newcommand*{\centerfloat}{%
  \parindent \z@
  \leftskip \z@ \@plus 1fil \@minus \textwidth
  \rightskip\leftskip
  \parfillskip \z@skip}
\makeatother % this one is required for the \centerfloat command to work

\newcolumntype{.}{D{.}{.}{-1}}
%\newcolumntype{z}[1]{D{.}{.}{#1}} % so your top tabular doesn't look as messy

\begin{document}

\begin{figure}[!htbp]
     \centerfloat
\rowcolors{2}{gray!10}{white}
\begin{tabular}{.*{15}{.}} % *{num}{form}, the format form is repeated num times.


\multicolumn{1}{c}{{\bfseries SVM}} &
\multicolumn{1}{c}{1} &
\multicolumn{1}{c}{2} &
\multicolumn{1}{c}{3} &
\multicolumn{1}{c}{4} &
\multicolumn{1}{c}{5} &
\multicolumn{1}{c}{6} &
\multicolumn{1}{c}{7} &
\multicolumn{1}{c}{8} &
\multicolumn{1}{c}{9} &
\multicolumn{1}{c}{10} &
\multicolumn{1}{c}{11} &
\multicolumn{1}{c}{12} &
\multicolumn{1}{c}{13} &
\multicolumn{1}{c}{14} \\

\toprule

\multicolumn{1}{c}{1} &   &   &   &   &   &   &   &   &   &   &   &   &   & 2.3 \\
\multicolumn{1}{c}{2} &   &   &   &   &   &   &   &   &   &   &   &   &   & 11110.4 \\
\multicolumn{1}{c}{3} & & & & & & & & & & & & & & \\
\multicolumn{1}{c}{4} & & & & & & & & & & & & & & 0.2 \\
\multicolumn{1}{c}{5} && & & & & & & & 0.7 & & & & & 1.2 \\
\multicolumn{1}{c}{6} & & & & & & & & & & & & & & 0.3 \\
\multicolumn{1}{c}{7} & & & & & & & & & & & & & & 0.2 \\
\multicolumn{1}{c}{8} & & & & & & & & & & & & & & 0.1 \\
\multicolumn{1}{c}{9} & & & & & & & & & 3.4 & & & & & 1.5 \\
\multicolumn{1}{c}{10} & & & & & & & & & & 11.0 & & & & \\
\multicolumn{1}{c}{11} & & & & & & & & & & & & & & 0.1 \\
\multicolumn{1}{c}{12} & & & & & & & & & & & & & & 2.6 \\
\multicolumn{1}{c}{13} & & & & & & & & & & & & & & 0.1 \\
\multicolumn{1}{c}{14} & & & & & & & & & 0.2 & 0.3 & & & & 200.0 \\

\end{tabular}
\caption{Mean confusion matrices for the first multi-class classification.}
\label{table6}
\end{figure}
\end{document}

如果您确实想要垂直线,您可以\arrayrulecolor{gray!30}在正下方添加\rowcolors{2}{gray!10}{white}。还可以将表格标题替换为:\begin{tabular}{.*{13}{.|}{.}},这样,垂直线只会出现在单元格中,而不会出现在表格的两侧。

带有垂直线的图形

相关内容