我想将 Matplotlib 图形的标题居中,其中在渲染 LaTeX 样式时包含换行符返回 (\)
在标题中间插入 Latex \\ 的简单返回代码可以工作,但不会使其居中,从而导致换行符从第一行尴尬地移动。
from matplotlib import pyplot as plt
plt.rc('text', usetex=True)
plt.title(r"\center{\textbf{Some title \\ with with a newline}}")
Run Code Online (Sandbox Code Playgroud)
或者
plt.title(r"\begin{centering}{\textbf{Some title \\ with a newline}\end{centering}")
Run Code Online (Sandbox Code Playgroud)
行不通
当我输入前面引用的行时,我在图中根本没有得到任何标题输出。不过,我在 python 命令解释器上没有出现 LaTeX 错误。