LaTeX学习摘记(四):表格

本文介绍了一系列在LaTeX中制作高质量表格的方法,包括调整行距、居中对齐、使用不同包来优化表格布局、跨页表格处理等。此外,还提供了如何在表格中绘制斜线、设置单元格空白长度及实现单元格内换行等实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

增大行距:

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

虚线

The arydshln package offers you the \hdashline and \cdashline commands which are the dashed counterparts of \hline and \cline, respectively.

线条宽度

来源: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} \\”

连续使用\cmidrule断开一定间距

若使用\cmidrule{2-6}\cmidrule{7-10},则第2到10列是完整直线

改成\cmidrule(lr){2-6}\cmidrule(lr){7-10},则第6列和第7列之间会断开

### 创建和设置复杂的LaTeX表格 为了创建和格式化复杂的LaTeX表格,可以利用`tabular`环境以及一些增强功能的宏包。对于更高级的需求,推荐使用`booktabs`宏包来改善表格外观[^1]。 #### 使用 `tabular` 环境构建基本结构 最基础的方式是通过`tabular`环境定义列属性并输入数据: ```latex \begin{table}[htbp] \centering \caption{简单示例表} \label{tab:simple_example} \begin{tabular}{|c|c|c|} \hline 列A & 列B & 列C \\ \hline 数据1 & 数据2 & 数据3 \\ 数据4 & 数据5 & 数据6 \\ \hline \end{tabular} \end{table} ``` 此代码片段展示了带有三列表格的基本框架,并且每一行之间都有水平线分隔开。 #### 应用 `booktabs` 宏包提升美观度 引入`booktabs`能够提供更加专业的线条样式,使文档中的表格看起来更为整洁专业: ```latex \usepackage{booktabs} % 加入到导言区 ... \begin{table}[htbp] \centering \caption{应用 booktabs 的例子} \label{tab:example_with_booktabs} \begin{tabular}{ccc} \toprule 列A & 列B & 列C \\ \midrule 数据1 & 数据2 & 数据3 \\ 数据4 & 数据5 & 数据6 \\ \bottomrule \end{tabular} \end{table} ``` 这里采用了顶部(`\toprule`)、中部(`\midrule`) 和底部 (`\bottomrule`)三种不同类型的横线代替传统的单一线条,从而提高了可读性和视觉效果。 #### 处理多页长表格 当遇到跨越多个页面的大规模表格时,应该考虑采用`longtable`宏包支持跨页显示: ```latex \usepackage{longtable} ... \begin{longtable}{lll} \caption{一个多页表格}\\ \toprule 列A & 列B & 列C\\ \midrule \endfirsthead \multicolumn{3}{c}% {{续前页}} \\ \toprule 列A & 列B & 列C\\ \midrule \endhead \midrule \multicolumn{3}{r}{{继续下一页}} \endfoot \bottomrule \endlastfoot 数据1 & 数据2 & 数据3 \\ ... (更多行) ... \end{longtable} ``` 这段代码实现了自动分割过长表格至下一页面的功能,在每一页开头重复标题栏,并在最后一页结束处加上完整的底线标记。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值