在 LaTeX 中实现换行,可通过以下方法实现:
一、表格单元格内换行
使用 `\tabincell` 命令 在表格单元格中插入内容后,按 `Tab` 键或输入 `\tabincell{c}{内容}` 即可自动换行。例如:
```latex
\begin{tabular}{|c|c|}
\hline
\tabincell{c}{第一行内容 \\
第二行内容} & \tabincell{c}{单行内容} \\
\hline
\end{tabular}
```
该方法需在导言区定义 `\tabincell` 命令:
```latex
\newcommand{\tabincell}{
\begin{tabular}{@{}1@{}}2
}
```
使用 `tabular` 环境
在单元格内手动输入 `\n`(换行符)或使用 `& \tabincell{c}{内容}` 结合 `Tab` 键换行。例如:
```latex
\begin{tabular}{|c|c|}
\hline
第一行内容 & 第二行内容 \\
\hline
\tabincell{c}{内容1 \\
内容2} & 单行内容 \\
\end{tabular}
```
二、长公式换行
手动换行
在 `array` 环境中,使用 `&` 符号手动分隔公式行。例如:
```latex
\begin{aligned}
\alpha^v &= \chi^v \phi_v \\
\alpha^m &= \chi^c \phi_m \\
\chi^v &= -\left(\frac{\tau}{3}\right)\left\langle u \cdot \nabla \times u \right\rangle
\end{aligned}
```
注意:此方法仅适用于简单换行,复杂公式需使用其他工具(如 MathType)编辑后导入。
使用 `amsmath` 宏包
通过 `align` 环境实现自动换行:
```latex
\begin{aligned}
a &= \left( a + b + c \right. \\
& \left. + c + e \right) \\
\end{aligned}
```
编译后显示为:$a=(a+b+c+d+e)$
三、其他场景
多行注释: 使用 `%` 开始注释,可跨越多行 分节符
建议优先使用 `\tabincell` 命令简化表格换行操作,公式换行则结合 `array` 或 `amsmath` 宏包处理。