latex多斜线表格的终极解决方案

iefan posted @ 2013年5月07日 15:40 in 程序设计与学习 , 15977 阅读

latex表格据说是比较复杂的,接触后,感觉普通的三线表格倒不是那么复杂,文档上说国际上标准的文档多采用三线表格,只是在中国这个特殊的国情中,三线表格倒显得另类了,在大量的公文格式中,凡牵扯到表格,多采用实线交叉的,而且一个比较头痛的还牵扯到斜线表头的绘制。

通常在WINDOWS下采用的是word或excel来绘制,但多斜线便需要用自绘线来添加,而且斜线表头的文字需要用文本框来添加,总体来说比较繁锁。但是用word绘制的多斜线表头表格在ubuntu下用abiword打开,格式就乱了。

在latex中,采用tabular来绘制表格,对斜线表头查询了相当多的资料,现成的宏包都有许多局限,一般用makecell来绘制斜线,具体可以参见其文档(eg: texdoc makecell),在texlive2011更新后,其中有一个diagbox宏包可以绘制双斜线表头,不过还有一些双斜线是其无法完成的。

在查资料后,觉得采用tikz宏包用画线和添字的方式来单独处理需要绘制斜线表头的单元格可以完成要求,其优点是可以精确控制斜线和文字的位置,其缺点是针对不同的表格,随着表间距的变大变小,或表格文字大小的调整,需要手动调整斜线的起始和终点位置,一个可取的办法是先将表格其他部分绘制完毕后,再回头单独对斜线单元格进行绘制。

给出一个具体例子:
\begin{table}
\centering
\subtable[\LARGE{学生成绩记录表一}]{
\begin{tabular}{|c|c|p{0.45cm}<{\centering}|p{0.45cm}<{\centering}|}
\hline
\multirowcell{2}{学\\\\\\号} & \multirowcell{2}{
$\vcenter{\hbox{%绘制斜线
\begin{tikzpicture}
\path[use as bounding box] (\tabcolsep,0) rectangle (3cm-\tabcolsep,3.4cm);
\draw (0,3.4cm) — (3cm,2.35cm);
\draw (0,3.4cm) — (3cm,0.18cm);
\path (2.5,3) node(a) {次数};
\path (2.1,2) node(a) {项目};
\path (2.3,1.5) node(a) {名称};
\path (1.3,0.5) node(a) {学生姓名};
\end{tikzpicture}%
}}$%
} & 1 & 2 \\ \cline{3-4}
&  & \MH{第一单元} & \MH{第二单元} \\
&&&\\
\hline
\end{tabular}
}
\qquad
\qquad
\subtable[\LARGE{学生成绩记录表二}]{
\begin{tabular}
…………
\end{tabular}
}
\end{table}

 

本例中还牵扯到两表格并排和文字直排的情况,在该例中这样处理:

a. \usepackage{subfigure} %表格横排宏包
\usepackage{graphicx} %文字旋转宏包

b. \setCJKfamilyfont{vs}[RawFeature={vertical: vert: cpct}]{SimHei} %自定义竖排文字字体

c. 自定义命令
文字旋转后,估计是由于文字基线的问题,使旋转后的文字难以居中,并且向下偏移,故用\multirow命令将旋转后的文字提升4pt,具体可以调整,并且在将宽度设为{0cm}后,编绎后的文档可以将直排文字左右居中。
\newcommand{\MH}[1]{\multirow{1}{0cm}[4pt]{\rotatebox{-90}{\CJKfamily{vs}#1}}}

d. 表格的间距设定
\renewcommand{\arraystretch}{1.6} % 將表格行間距加大為原來的 1.2 倍
\tabcolsep=7pt                   % 調整欄間距為 24pt

e. 由于用\multirow命令后,直排文字的行变窄,具体问题不明,解决的办法是在其下单独加一空行,只用\\换行,却没有竖线了,没办法,只有用”&&&&\\”来加一行。

还有一个办法是用\rule命令来填充指定行的某个单元格,这样子就可以指定那一行的行高:
例如:
    & \rule{0pt}{9ex}& \MH{第一单元} & \MH{第二单元} \\
当然这样一来,需要将\MH旋转的文字用\multirow命令再提升一些。

Avatar_small
cleaning company dub 说:
2021年8月03日 19:05

The family-owned cleansing company is going to be happy and very happy to provide a complete range associated with services to match all your requirements. We have several years of encounter in delivering professional household and workplace cleaning throughout London. Our passionate and dependable team will give you you higher standard services because the first go to. We provide End associated with Tenancy Cleansing, After Contractors Cleaning, Following Party Cleansing, One away deep cleansing, Carpet, Bed mattress and Upholstery Cleansing, Office, College and Baby's room, Shop Cleansing.

Avatar_small
commercial cleaning 说:
2021年9月04日 16:03

A lot of us cannot digest the possibility that expert chemicals can finish the in for the reason that less for the reason that 2 hours although you used to take your entire leisure time in vacuuming your address. This is really because it might be their job so they follow some systematic methodology, advanced hardware, and progressed cleaning services for cleaning your household. You should check out the amount from work done without having to time used up when deciding easy.

Avatar_small
monthly maid service 说:
2023年10月17日 17:44

his stands out as the main an area of the hiring practice as money is crucial for together, you and also maid or simply the maintenance service, which means that discuss the matter rather clearly. One of these too liberal in anticipation, as it is important to consider your budget also. Overall it leads to problems on your behalf and also you shouldn't very stringent also, you may lose the best maid or simply cleaning provider.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter