2012-10-19 45 views
1

我想在LaTeX中制作一个多行表,它看起来像这个Wikipedia article中显示的真正的正面,真正的负面等表。如何创建一个多行表

我正在尝试使用multirow,但我不知道如何让这顶帽子在桌子外面。

\begin{table}[tbh!] 
\centering 
    \begin{tabular}{|l|l|l|} 
    \multicolumn{3}{c}{$y$} \\ \hline 
    %\multirow{3}{*}{$\hat{y}$} \\ 
    & \textbf{T} & \textbf{F} \\ \hline 
    \textbf{T} & TP & FP \\ \hline  
    \textbf{F} & FN & TN \\ \hline 
\end{tabular} 
\caption{Truth and prediction comparison.} 
\label{tab:revpol} 
\end{table} 

任何人都可以解释我需要改变这里来实现这个吗?

回答

1

这是最简单的方法包括“出表”组件为tabular结构的一部分:

enter image description here

\documentclass{article} 
\usepackage{multirow}% http://ctan.org/pkg/multirow 
\begin{document} 
\begin{table}[t] 
    \centering 
    \begin{tabular}{l|l|l|l|} 
    \multicolumn{2}{c}{} & \multicolumn{2}{c}{$y$} \\ \cline{3-4} 
    \multicolumn{2}{c|}{} & \textbf{T} & \textbf{F} \\ \cline{2-4} 
    \multirow{2}{*}{$\hat{y}$} & \textbf{T} & TP & FP \\ \cline{2-4}  
    & \textbf{F} & FN & TN \\ \cline{2-4} 
    \end{tabular} 
    \caption{Truth and prediction comparison.} 
    \label{tab:revpol} 
\end{table} 
\end{document} 

\cline s的意思是把一个\hline只在某些列。 \multicolumn用于隐藏使用您的tabular色谱柱规格插入的一些垂直线。

在旁注中,考虑将booktabs作为tabular表示法替代方案。