Wie kann ich eine große Matrix gut aussehen lassen?

Wie kann ich eine große Matrix gut aussehen lassen?

Ich muss in meiner Abschlussarbeit große Matrizen verwenden und finde keinen Weg, dies auf eine schöne Art und Weise zu tun. Das Problem ist: Diese Matrizen sind sehr spärlich, aber ich brauche sie vollständig für Analysezwecke.

Bisher ist es mir gelungen, sie wie folgt darzustellen (wobei ich Leerzeichen dort lasse, wo der Wert 0 ist): Meine hässliche Matrix

Die Sache ist, dass die Matrix 14 x 14 ist, ich aber in der ersten Zeile/Spalte die Zahl 1->14 anzeigen möchte.

Irgendeine Idee, wie man es verbessern und gleichzeitig die Vollständigkeit wahren kann?

BEARBEITEN: Hier ist das 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}

Antwort1

Ein paar Möglichkeiten:

Bildbeschreibung hier eingeben

\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}

Antwort2

So würde ich es ändern. Die Schönheit einer Tabelle kann subjektiv sein, aber ich denke, dass die Linien nur für Verwirrung sorgen und es „schwieriger“ machen, die Tabelle bequem zu lesen. Ich bevorzuge es, nur (spärliche) horizontale Linien oder abwechselnde Zeilenfarben zu verwenden, wie in diesem Fall.

Alle hinzugefügten Pakete oder Befehle wurden im Code als kurze Erklärung kommentiert. Schreiben Sie einen Kommentar, wenn Sie spezielle Fragen haben.


Bearbeiten: Ich habe die richtige Ausrichtung der numerischen Werte gemäß dem Dezimaltrennzeichen hinzugefügt.

Figur ohne vertikale Linien

\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}

Wenn Sie unbedingt vertikale Linien möchten, können Sie diese \arrayrulecolor{gray!30}direkt darunter hinzufügen \rowcolors{2}{gray!10}{white}. Ersetzen Sie außerdem die Tabellenüberschrift durch Folgendes: . \begin{tabular}{.*{13}{.|}{.}}Auf diese Weise werden die vertikalen Linien nur in den Zellen und nicht an den Seiten der Tabelle angezeigt.

Figur mit vertikalen Linien

verwandte Informationen