![如何在表格中添加同一案例中的两个变量](https://linux22.com/image/376229/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%A1%A8%E6%A0%BC%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%90%8C%E4%B8%80%E6%A1%88%E4%BE%8B%E4%B8%AD%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%8F%98%E9%87%8F.png)
事实上,我想在同一个案例中添加两个变量(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}