答案1
这LaTex 维基使用 给出了一个很好的例子multicolumn
。以下是他们的例子的修改版本:
\begin{tabular}{cc|c|c|c|c}
\cline{3-5}
& & \multicolumn{3}{ c| }{blah} \\ \cline{3-5}
& & x & y & z \\ \cline{1-5}
\multicolumn{1}{ |c| }{var1} & a & 2 & 0 & 1 \\ \cline{1-5}
\multicolumn{1}{ |c| }{var2} & b & 2 & 0 & 0 \\ \cline{1-5}
\multicolumn{1}{ |c| }{var3} & c & 3 & 1 & 1 \\ \cline{1-5}
\end{tabular}
答案2
感谢所有试图帮助我的人。我使用 pgfplotstable 找到了解决方案。这是我的代码:
\documentclass[12pt,a4paper,oneside,titlepage]{article}
\pagestyle{headings}
%\setcounter{page}{1}
\pagenumbering{arabic}
%\pagestyle{arabic}
%\usepackage[a4paper,left=1.25in,right=1.25in,top=1in,bottom=1in]{geometry}
%\usepackage[left=1cm,right=2cm,top=2.5cm,bottom=2.5cm,footnotesep=0.5cm]{geometry}
\usepackage[a4paper,left=2.0cm,right=2.0cm,top=2.5cm,bottom=4.5cm]{geometry} % from Dr. Tahir
\usepackage[fleqn]{amsmath}
%\setlength{\mathindent}{4cm}%
\usepackage{graphics}
\usepackage{epstopdf}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{subcaption}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fr*om pgfplotstable.pdf
\usepackage{pgfplotstable}
% recommended:
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% from pgfplots.pdf
\usepackage{pgfplots}
\pgfplotsset{width=7cm, compat=1.3}% <-- moves axis labels near ticklabels (respects tick label widths)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%% pgfplotstable code start %%%%%%%%%%%%%%%%%%
\pgfplotstabletypeset[
col sep=semicolon,
row sep=\\,
columns/0/.style={string type,column name={}},
columns/1/.style={string type,column name={}},
columns/value/.style={fixed,fixed zerofill,dec sep align,precision=6,column name={$\mathbf{X}$}},
columns/sd/.style={fixed,fixed zerofill,dec sep align,precision=6,column name={$\mathbf{Y}$}},
]{
; ; x; y\\
{$Var1\ name$}; $a$ ;1;2\\
{$Var2\ name$}; $b$ ;3;4\\
{$Var3\ name$}; $c$ ;5;6\\
}
%%%%%%% pgfplotstable code end %%%%%%%%%%%%%%%%%%
\end{document}
以下是输出(与问题略有不同,但正是我想要的):
问候,贾米尔