如何在表格中添加同一案例中的两个变量

如何在表格中添加同一案例中的两个变量

事实上,我想在同一个案例中添加两个变量(de,e),如下图所示:

这是我编写的代码,但我不知道如何将 de 和 e 放在同一个位置:

\begin{table}[!ht]
\centering
\caption{Définitions des variables linguistiques}
\begin{tabular}{ c c c c c c c c} 
\toprule
\makecell{de} & \makecell{ NB}& \makecell{NM} & \makecell{NS} & \makecell{Z} 
& \makecell{PS}& \makecell{PM} & \makecell{PB}  \\ 
\midrule
NB &  Z & PS & PM & NB & NM & NS & Z\\
NM &  NS & Z & PS & NM & NS & Z & PS\\
NS &  NM & NS & Z & NS & Z & PS & PM\\
Z &  NB & NM & NS & Z & PS & PM & PB\\
PS &  NB & NB & NM & PS & PM & PB & PB\\
PM &  NB & NB & NB & PM & PB & PB & PB\\
PB &  NB & NB & NB & PB & PB & PB & PB\\
\bottomrule
\end{tabular}
\end{table}

答案1

您可以使用该包diagbox

诊断框

\documentclass{article}
\usepackage{booktabs,makecell}
\usepackage{diagbox}

\begin{document}
\begin{table}[!ht]
\centering
\caption{Définitions des variables linguistiques}
\begin{tabular}{ c c c c c c c c} 
\toprule
\diagbox{de}{e} & \makecell{ NB}& \makecell{NM} & \makecell{NS} & \makecell{Z} 
& \makecell{PS}& \makecell{PM} & \makecell{PB}  \\ 
\midrule
NB &  Z & PS & PM & NB & NM & NS & Z\\
NM &  NS & Z & PS & NM & NS & Z & PS\\
NS &  NM & NS & Z & NS & Z & PS & PM\\
Z &  NB & NM & NS & Z & PS & PM & PB\\
PS &  NB & NB & NM & PS & PM & PB & PB\\
PM &  NB & NB & NB & PM & PB & PB & PB\\
PB &  NB & NB & NB & PB & PB & PB & PB\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

答案2

这也同样清晰,并避免了可怕的对角线。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % not needed for LaTeX 2018-04-01 or later
\usepackage[french]{babel}

\usepackage{booktabs}

\begin{document}

\begin{table}[!htp]
\centering
\caption{Définitions des variables linguistiques}
\begin{tabular}{@{} c c c c c c c c @{}}
\toprule

de & \multicolumn{7}{c}{e} \\
\cmidrule(l){2-8}
   & NB & NM & NS & Z  & PS & PM & PB \\ 
\midrule
NB & Z  & PS & PM & NB & NM & NS & Z  \\
NM & NS & Z  & PS & NM & NS & Z  & PS \\
NS & NM & NS & Z  & NS & Z  & PS & PM \\
Z  & NB & NM & NS & Z  & PS & PM & PB \\
PS & NB & NB & NM & PS & PM & PB & PB \\
PM & NB & NB & NB & PM & PB & PB & PB \\
PB & NB & NB & NB & PB & PB & PB & PB \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容