一、基础表格入门
1.1 最简单的表格
\begin{tabular}{ccc}
Name & Age & Score \\
Alice & 20 & 85 \\
Bob & 21 & 92 \\
\end{tabular}
效果:
Name Age Score
Alice 20 85
Bob 21 92
语法说明:
{ccc}定义3列,都居中对齐&分隔列\\结束一行
1.2 三种表格环境
| 环境 | 用途 | 是否浮动 |
|---|---|---|
tabular |
纯表格内容 | 否 |
table |
带标题和标签的表格 | 是 |
tabularx |
自动调整列宽 | 否 |
示例对比:
% 1. tabular - 直接插入文本中
The data: \begin{tabular}{cc} A & B \\ 1 & 2 \\ \end{tabular} shows...
% 2. table - 独立浮动表格
\begin{table}[htbp]
\centering
\begin{tabular}{cc}
Method & Accuracy \\
Baseline & 85.3 \\
Proposed & 92.7 \\
\end{tabular}
\caption{Performance Comparison}
\label{tab:comparison}
\end{table}
% 3. tabularx - 自适应宽度
\usepackage{tabularx}
\begin{tabularx}{\textwidth}{lXX}
ID & Description & Note \\
001 & Long text will automatically wrap within column & Another long text \\
\end{tabularx}
二、列对齐详解
2.1 基本对齐方式
% l = left, c = center, r = right
\begin{tabular}{lcr}
Left & Center & Right \\
Apple & Banana & Cherry \\
Dog & Elephant & Fox \\
100 & 200 & 300 \\
\end{tabular}
对齐效果说明:
l:文本左对齐,适合文字内容c:居中对齐,适合标题和短文本r:右对齐,适合数字
2.2 固定列宽
% p{width} - fixed width with auto line break
\begin{tabular}{|p{3cm}|p{5cm}|}
\hline
Title & Content \\
\hline
Short & This is a very long sentence that will automatically wrap within the specified column width without exceeding boundaries \\
\hline
\end{tabular}
使用场景:
- 处理长文本内容
- 需要精确控制表格宽度
- 避免表格超出页面边界
2.3 混合对齐
\begin{tabular}{|l|c|r|p{4cm}|}
\hline
Left & Center & Right & Fixed Width \\
\hline
Text & 123 & 99.9 & Long text with automatic wrapping \\
\hline
\end{tabular}
三、表格线条控制
3.1 横线命令
\begin{tabular}{ccc}
\hline % Full horizontal line
A & B & C \\
\hline\hline % Double horizontal line
D & E & F \\
\cline{1-2} % Partial line (columns 1-2)
G & H & I \\
\hline
\end{tabular}
命令说明:
\hline:完整横线,跨越所有列\hline\hline:双横线\cline{m-n}:部分横线,从第m列到第n列
3.2 竖线设置
% Add | in column definition
\begin{tabular}{|c|c|c|} % Vertical line between each column
\begin{tabular}{c|c|c} % Vertical lines in middle
\begin{tabular}{||c||c||c||} % Double vertical lines
3.3 专业三线表(强烈推荐)
\usepackage{booktabs}
\begin{table}[htbp]
\centering
\begin{tabular}{lcc}
\toprule % Top thick line
Method & Accuracy (\%) & Speed (ms) \\
\midrule % Middle thin line
Baseline & 85.3 & 120 \\
Method A & 89.7 & 105 \\
Method B & 92.4 & 98 \\
\bottomrule % Bottom thick line
\end{tabular}
\caption{Experimental Results}
\end{table}
传统表格 vs 三线表对比:
% ❌ Traditional table (Not recommended)
\begin{tabular}{|c|c|c|}
\hline
Method & Acc & Time \\
\hline
A & 85 & 100 \\
\hline
B & 90 & 110 \\
\hline
\end{tabular}
% ✅ Three-line table (Recommended)
\begin{tabular}{lcc}
\toprule
Method & Acc & Time \\
\midrule
A & 85 & 100 \\
B & 90 & 110 \\
\bottomrule
\end{tabular}
为什么推荐三线表:
- 更专业、更清晰
- 符合学术期刊规范
- 视觉效果更好
- 国际通用标准

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



