答案1
有一个slashbox
包(未包含在 TeX Live2010 中)用于在矩阵单元中绘制对角线;但是,使用此包获得的结果相当差(见下面的示例)。另一个选择是使用TikZ
和matrix of nodes
。在下面的例子中,我展示了两种方法:一个例子取自slashbox.tex
,另一个例子在的帮助下构建TikZ
:
\documentclass{article}
\usepackage{slashbox}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tabular}{|l||*{5}{c|}}\hline
\backslashbox{Room}{Date}
&\makebox[3em]{5/31}&\makebox[3em]{6/1}&\makebox[3em]{6/2}
&\makebox[3em]{6/3}&\makebox[3em]{6/4}\\\hline\hline
Meeting Room &&&&&\\\hline
Auditorium &&&&&\\\hline
Seminar Room &&&&&\\\hline
\end{tabular}
\vspace{1cm}
\begin{tikzpicture}
% the matrix
\matrix [matrix of nodes,text height=8pt,text depth=2pt,text width=0.5cm,nodes={align=center}] (mat)
{
a & b & c \\
d & e & f \\
g & h & i \\
j & k & l \\
};
% the horizontal lines
\foreach \i in {1,2,3,4}
\draw (mat-\i-1.north west) -- (mat-\i-3.north east);
\draw (mat-4-1.south west) -- (mat-4-3.south east);
% the vertical lines
\foreach \i in {1,2,3}
\draw (mat-1-\i.north west) -- (mat-4-\i.south west);
\draw (mat-1-3.north east) -- (mat-4-3.south east);
% the diagonal lines
\draw (mat-1-1.north west) -- (mat-1-1.south east);
\draw (mat-3-3.north west) -- (mat-3-3.south east);
\end{tikzpicture}
\end{document}