我遇到的麻烦有两件事:
- 仅设置右下角的边框
- 确保“对政党的信任”位于第 3 列和第 4 列之间
到目前为止,这是我正在使用的代码:
\begin{table}[H]
\begin{center}
\caption{Theory}
\begin{tabular}{ cccc }
& & Trust in political parties \\
& & Low & High \\
\multirow{2}{4em}{Emotion} & Low & A & Preemtive B \\
& High & C & D \\
\end{tabular}
\end{center}
\end{table}
谢谢
答案1
一种方法是使用nicematrix
包。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{lw{l}{1cm}w{c}{2cm}w{c}{2cm}}
& & \Block{1-2}{\textbf{Trust in political parties}} & \\
& & Low & High\\
\Block{2-1}{\textbf{Policy priority}} & Low & \Block[draw]{}A & \Block[draw]{}B\\
& High & \Block[draw]{}C & \Block[draw]{}D
\end{NiceTabular}
\end{document}
答案2
我刚刚发现了令人惊奇的表格数组包,它通过现代键值接口为表提供许多定制,并复制经典表包的功能。
这是我的第一次尝试,可能不是最佳的,但它有效。
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}
\begin{center}
\caption{Theory}
\begin{tblr}
{%
colspec={ lllll } % 5 left aligned columns
,cell{3-Z}{3-Z}={c} % center cells from row 3 and column 3 until the end
,row{1} = {font=\bfseries} % format row 1
,column{1} = {font=\bfseries} % format column 1
,hline{3-Z}={3-Z}{} % draw hlines starting from the 3rd, for rows 3 until the end
,vline{3-Z}={3-Z}{} % draw vlines starting from the 3rd, for columns 3 until the end
}
&
&
\SetCell[c=2]{c} Trust in political parties % centered across 2 columns
\\
&
& Low & High \\
\SetCell[r=2]{c} Emotion % centered across 2 rows
& Low & A & Preemtive B \\
& High & C & D
\end{tblr}
\end{center}
\end{table}
\end{document}
答案3
这是另一个例子
\documentclass{article}
\usepackage{multirow} % Merge rows
\usepackage{array} % More convenient column spec.
\newcolumntype{L}{@{}p{2.5cm}}
\newcolumntype{C}{w{c}{2.5cm}}
\begin{document}
\begin{table}[tbh]
\renewcommand*\arraystretch{1.2}
\centering
\caption{Theory}
\begin{tabular}{*2{l} | *2{C|}}
& \multicolumn{1}{c}{}
& \multicolumn{2}{c}{\bfseries Trust in political parties} \\
& \multicolumn{1}{c}{}
& \multicolumn{1}{L}{Low} & \multicolumn{1}{L}{High} \\
\cline{3-4}
\multirow{2}*{\bfseries Emotion}
& Low & A & B \\
\cline{3-4}
& High & C & D \\
\cline{3-4}
\end{tabular}
\end{table}
\end{document}
答案4
您只需要一些\multicolumn
s ,不需要任何包。
此外,表格看起来会像中心偏离但标题居中,因为被限制的数据只在右侧,所以我将把整个方案放在某个框中:
\documentclass{article}
\usepackage{multirow,array}
\begin{document}
\begin{table}\caption{Theory}
\extrarowheight2.5pt
\centering\fboxsep1em\fbox{%
\begin{tabular}{@{}c|l|p{4em}p{6em}}
\multicolumn{4}{c}{}\\[-20pt]
\multicolumn{2}{c}{} & \multicolumn{2}{c}{Trust in political parties}\\\cline{3-4}
\multicolumn{2}{c}{} & \centering Low & \multicolumn{1}{c}{High} \\\cline{3-4}
\multirow{2}{*}{Emotion} & Low & \centering A & \multicolumn{1}{|c|}{Preemtive B} \\\cline{3-4}
& High & \centering C & \multicolumn{1}{|c|}{D} \\\cline{3-4}
\end{tabular}}
\end{table}
\end{document}