> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/18-latex-error-there-s-no-line-here-to-end.md).

# LaTeX 错误：此处没有可结束的行

如果你使用诸如以下的换行命令： **`\\`** 或 **`\newline`** 在 LaTeX 没有预期它的时候使用它，你将会产生如下所示的错误：

main.tex，第 12 行

LaTeX 错误：这里没有可结束的行。。

请参阅 LaTeX 手册或 LaTeX Companion 以获取解释。输入 H 可立即获得帮助。... l.8 \\\ 你的命令已被忽略。输入 I 可用另一个命令替换它，或继续而不使用它。

## 常见原因

**在不适当的时候使用换行符 \\\：**

此错误的一个常见原因是使用了诸如以下的换行命令： **`\\`** 或 **`\newline`** 如果使用不当。当 LaTeX 在未构建段落时遇到换行命令，它就会生成错误。下面展示了这一错误的一个示例：

```latex
\\ 我们把换行放在了错误的位置
```

在上面的例子中，换行符被插入在前面没有文本的位置。由于 LaTeX 无法断开一条并不存在的行，所以它不知道该如何处理，从而返回错误。

**在列表环境之后放置换行符：**

如果你尝试像下面这样在列表环境之后放置换行符，也会出现此错误

```latex
\begin{itemize}
    \item 这是一个列表项
    \item 这是另一个列表项
\end{itemize}\newline
```

LaTeX 并不将这个列表视为一个段落，而是视为一个单独的对象分组，因此它找不到可供换行的地方。如果你希望在所有列表下方留出更多空白，最好在你的前导部分或类文件中重新定义 **`itemize`** 不过，如果只是一次性的情况，可以通过写入以下内容来避免此错误 **`\leavevmode`** 放在换行命令前面，如下所示：

```latex
\begin{itemize}
    \item 这是一个列表项
    \item 这是另一个列表项
\end{itemize}\leavevmode\newline
```

**尝试将列表项标签单独写在一行：**

导致此错误出现的另一个常见原因是，你尝试使用以下内容编写带标签的列表： **`说明`** 环境，并且你希望标签单独占一行。下面展示了在这里如何会犯这个错误的一个示例：

```latex
\begin{description}
\item[This is our label] \\
     我们希望这段文本单独占一行。
\end{description}
```

这将生成一个错误，因为 LaTeX 会将标签条目视为以下命令的一个参数： **`\item`** 命令，而不是文本段落的一部分。如果你希望列表中的标签与列表项分成不同的行，你就必须重新定义 **`说明`** 环境。实现这一点最简单的方法是使用 **`enumitem`** 宏包，并加入 **`\setlist[description]{style=nextline}`** 到你的前导部分中，如下所示：

```latex
% 在导言区中

\usepackage{enumitem}
\setlist[description]{style=nextline}

% 在文档正文中

\begin{description}
\item[这是我们的标签]
     我们希望这段文本单独占一行。
\end{description}
```

![Enumitem.PNG](/files/73d2ff186202958e1cb9aa4b03047d1220bfc7ce)

这样就能得到期望的结果，使所有标签都单独显示在列表项的另一行。

如果你只希望只有一个标签单独占一行，可以通过使用以下命令来实现： **`\leavevmode`** 命令，如下所示：

```latex
\begin{description}
\item[这是一个标签] \leavevmode \\
     这段文本将单独显示在一行
\item[这是另一个标签] 这段文本将与标签在同一行。
\end{description}
```

![Leavevmode.PNG](/files/654524f341d27c112df1a0d45eee4b0db264ebf6)

这是因为 LaTeX 在尝试在垂直模式下跳过行时会遇到此类错误。 **`\leavevmode`** 该命令会使编译器临时离开垂直模式，因此可以避免该错误。

**在使用 center、flushleft 或 flushright 环境时创建空白：**

导致此错误出现的另一个原因是，你尝试通过写入以下内容来包含多个换行符：

* **`\\\\`**
* **`\\\\newline`**
* **`\newline\newline`**
* 等。

而当它处于 **`center`**, **`flushleft`** 或 **`flushright`** 环境中时，如下所示

```latex
\begin{center}
  我们希望这行与下一行之间留有一行的间隔 \\\\
  以及这行
\end{center}
```

这在 LaTeX 中是不允许的，并会生成错误。在这里加入多个换行符的正确方法是写： **`\\[length]`** 其中 **`长度`** 是你希望行与行之间的距离。下面给出一个示例：

```latex
\begin{center}
  我们希望这行与下一行之间留有一行的间隔 \\[2\baselineskip]
  以及这行
\end{center}
```

![Centerskip.PNG](/files/aff6901179a3a984c519228ef90686592ce6b790)

这里， **`\\[2\baselineskip]`** 命令告诉 LaTeX 在该处跳过两行。你可以在以下选项中输入的距离有不同的度量选项： **`长度`** 列在其中 [此处](/latex/zh-cn/ge-shi-hua/01-lengths-in-latex.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/18-latex-error-there-s-no-line-here-to-end.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
