> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-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[这是我们的标签] \\
     我们希望这段文本单独占一行。
\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 中是不允许的，并且会生成错误。这里包含多个换行的正确方式是写作 **`\\[长度]`** 其中 **`长度`** 是你希望行与行之间的距离。下面是一个示例：

```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://overleaf-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.
