Latex笔记
# 创建表格
# 创建固定宽度的表格
您可以使用tabular* 环境来创建一个固定宽度的表格。例如,\begin{tabular*}{0.8\textwidth}{@{\extracolsep{\fill}}|c|c|} 表示创建一个宽度为0.8\textwidth的表格,表格有两列,每一列都居中对齐。
# 使整个表格居中
使用\centering
\begin{center}
\begin{tabular}{|c|c|}
\hline
A & B \\
\hline
C & D \\
\hline
\end{tabular}
\end{center}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
或者\begin{center}
\centering
\begin{tabular}{|c|c|}
\hline
A & B \\
\hline
C & D \\
\hline
\end{tabular}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 分割线
| 语法 | 含义 |
|---|---|
\toprule | 顶部分割线 |
\midrule | 中部分割线 |
\bottomrule | 底部分割线 |
示例:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{cc}
\toprule
A & B \\
\midrule
C & D \\
\bottomrule
\end{tabular}
\end{document}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 取消表格浮动
表格table默认是浮动的,要取消浮动,可以使用宏包\usepackage{float},然后设置:
\documentclass{article}
\usepackage{float}
\begin{document}
Some text before the table.
\begin{table}[H]
\centering
\begin{tabular}{|c|c|}
\hline
A & B \\
\hline
C & D \\
\hline
\end{tabular}
\caption{This is a table.}
\label{tab:mytable}
\end{table}
Some text after the table.
\end{document}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
上次更新: 2023/12/16, 09:22:46