Latex 如何创建多行表

Latex 如何创建多行表,latex,Latex,我正在尝试用LaTeX制作一个多行表,它看起来像图中所示的真正、真负等表 我正在尝试使用多行,但我不确定如何使y形帽“在”表之外 \begin{table}[tbh!] \centering \begin{tabular}{|l|l|l|} \multicolumn{3}{c}{$y$} \\ \hline %\multirow{3}{*}{$\hat{y}$} \\ & \textbf{T} & \textbf{F} \\ \hline

我正在尝试用LaTeX制作一个多行表,它看起来像图中所示的真正、真负等表

我正在尝试使用
多行
,但我不确定如何使y形帽“在”表之外

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

有人能解释一下我需要在这里更改什么来实现这一点吗?

最简单的方法是将“表外”组件作为
表格结构的一部分:

\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
用于隐藏使用
表格格式
列规范插入的一些垂直行

在侧面注释中,将其视为<代码>表> <代码>表示替代。