LaTeX学习摘记(四):表格

 

增大行距:

\renewcommand{\arraystretch}{1.5}

 

表格居中:解决方案

1. 每个单元格前面加\centering\arraybackslash,为了简化,可以增加新命令

\begin{table}\label{tab:1}

\centering

\captionsetup{width = 88mm}

\caption{This is caption.}

\newcommand{\ceab}[1]{\centering\arraybackslash#1}

\renewcommand{\arraystretch}{1.5}

\begin{tabular}{|c|*{3}{p{6mm}|}}\hline

xx & \ceab{yy} & \ceab{yy} & \ceab{yy}  \\\hline

zz & \ceab{yy} & \ceab{yy} & \ceab{yy}  \\\hline

\end{tabular}

\end{table}

2. 使用tabularx包:来源http://bbs.ctex.org/viewthread.php?tid=4183

\usepackage{tabularx}
\begin{table}
\begin{center}
\scriptsize
\renewcommand{\arraystretch}{1.3}
\caption{Quasi-normal frequencies for the scalar perturbation in
the stationary Schwarzschild background. \label{tab:1}}
\begin{tabularx}{380pt}{*{5}{>{\centering\arraybackslash}X|}>{\centering\arraybackslash}X}
\hline &&\multicolumn{2}{c|}
{\textbf{Exact solution}}&\multicolumn{2}{c}{\textbf{Numerical solution}}\\
\hline
$\sqrt{M}$&$m$&$\omega_R$&$\omega_I$&$\omega_R$&$\omega_I$\\
\hline
0.2&1&1&-0.4&1.002&-0.400 \\
0.4&1&1&-0.8&0.965&-0.799 \\
0.4&2&2&-0.8&2.003&-0.800 \\
0.4&3&3&-0.8&3.004&-0.800 \\
0.4&4&4&-0.8&4.005&-0.800 \\
0.5&2&2&-1&1.999&-1.000 \\
0.5&3&3&-1&2.993&-1.000 \\
0.5&4&4&-1&4.007&-1.000 \\
1&4&4&-2&4.004&-2.001 \\
2&10&10&-4&10.014&-4.001 \\
3&10&10&-6&10.028&-6.011 \\
4&10&10&-8&9.973&-7.983 \\
\hline
\end{tabularx}
\end{center}
\end{table}

改变标题的宽度及与图标之间的距离

使用caption包

加载包时使用参数aboveskip= 5pt或在在表格里设置

\captionsetup{width = 95mm}

\abovecaptionskip = 5pt

 

表格横置

\usepackage[figuresright]{rotating}% figuresright表示逆时针旋转90度

\begin{sidewaystable}

\belowcaptionskip = 100mm %改变与左侧的距离

\caption{ A transverse table}

\begin{tabular}

\end{tabular}

\end{sidewaystable}

还可用下面命令(未尝试)

\begin{center}\rotatebox{度数} {\begin{tabular}{…}…\end{tabular}}\end{center}

线条宽度

来源:http://bbs.ctex.org/viewthread.php?tid=38363

booktab宏包可以控制线条宽度

\toprule[10pt]

\midrule[5pt]

\bottomrule[10pt]

线条附加的空白高度

下面指令改变线条(\toprule,\midrule,\cmidrule,\bottomrule)附加的上下空白高度

\abovetopsep = 0.1ex;顶线上方

\aboverulesep = 0.1ex;其他

\belowrulesep = 0.1ex;其他

\belowbottomsep = 0.1ex;顶线下方

 

多个\multirow连着

& \multirow{2}*{aa} &\multirow{2}*{bb} & \multicolumn{2}{c}{dd} & \multicolumn{2}{c}{ee}& \multirow{2}*{ff}  \\

&{} &{} & gg & hh & ii& jj & {}

表格太大的处理方法

1.     横置

2.     字体变小

3.     减少空白,例如使用\begin{tabular}{*{4}{@{\hspace{4pt}}c}}\toprule

 

表格太长的处理方法

使用supertabular包

\begin{center}

\newcounter{Rownumber}

\newcommand{\Rown}{\stepcounter{Rownumber}\arabic{Rownumber}}

\begin{supertabular}{|c|c|}\hline

\Rown\label{mod:1} &\begin{minipage}[c]{0.33\textwidth}

aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaa aaaaaaaa aaaaaaaaaa aaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa

\end{minipage} \\\hline

\Rown & bb \\\hline

\end{supertabular}

\end{center}

表格中斜线绘制

第一种方案:

来源:http://blog.sina.com.cn/s/blog_5e16f1770100g59k.html

\usepackage{slashbox}

\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}

第二种方案:

来源:http://blog.sina.com.cn/s/blog_5e16f1770100n2an.html

\usepackage{ makecell}

\begin{tabularx}{.62\hsize}{|X|c|c|}\hline

\diaghead(-4,1){\hskip\hsize}%%参见此处,第一个花括号表示长度

{Diag \\Column Head I}{Diag Column \\HeadII}&

\thead{Second\\column}&\thead{Third\\column}\\

\hline

\end{tabularx}

设置单元格左右的空白长度

@{\hspace{4.5pt}}>{\centering\arraybackslash}c@{\hspace{4.5pt}

设置编号并交叉引用

\newcounter{rownumber}

\newcommand{\currentrow}{\refstepcounter{rownumber}\therownumber{}.}

使用方法:

\currentrow{} \label{0:1}

引用方法:

\ref{0:1}

表格跨页

使用supertabular包

\begin{center}

\newcounter{rownumber}

\newcommand{\currentrow}{\refstepcounter{rownumber}\therownumber{}.}

\tablefirsthead{\hline No. & \centering\arraybackslash{Description}\\\hline}

\tablehead{}

\tabletail{\hline}

\tablelasttail{}

\begin{supertabular}{|p{0.5cm}|p{13cm}|}

\multicolumn{2}{|l|}{\textbf{In Abstract}}  \\\hline

\currentrow{}\label{0:1} & Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction Introduction \\\hline

\multicolumn{2}{|l|}{\textbf{In Section 1. Introduction}}  \\\hline

\multicolumn{2}{|l|}{\textbf{In Section 6. The succinctness of ROBDD}$\bm{[\AND_{\widehat{i}}]_{\C}}$\textbf{ and ROBDD}$\bm{[\AND_{\widehat{\T}, i}]_{\T}}$}  \\\hline

\currentrow{}\label{6:1} & We discarded the discussion of succinctness relation between \ROBDDC{\widehat{i}}{\C} and \ROBDDC{\widehat{\T},j}{\T} ($i\not=j$). That is,  \\\hline

%\noalign{\smallskip}\hline

\end{supertabular}

\end{center}

单元格内换行

首先,声明\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}};然后,按照如下方式使用“& \tabincell{c}{abc\\ def\\ hij} \\”

你可能感兴趣的:(工具使用)