如何使用 LaTeX 解释器创建 two-line 标题?

How can I create two-line titles using the LaTeX interpreter?

我在 MATLAB 中画了一个图,标题很长所以我决定把它分成两行。但是,当我使用 LaTeX 解释器时它不起作用。

标题代码行如下所示:

title('{Monte-Carlo For Both Linear and Non-Linear Models Using N=300 and An Adjoint Simulation;Frequency = 100Hz $\sigma_{T}=\sigma_{D}=10^{-5}$}','Interpreter','latex')

如何让它显示在 2 行上,同时以 LaTeX 字体显示?

将字符串分成 cell array 似乎工作得很好:

title({'Monte-Carlo For Both Linear and Non-Linear Models Using N=300' ...
       'and An Adjoint Simulation; Frequency = 100Hz $\sigma_{T}=\sigma_{D}=10^{-5}$'}, ...
      'Interpreter', 'latex');

这是它的样子:

这将使每行左对齐。如果您需要它们居中对齐,最简单的方法可能是使用 tabular environment as suggested by :

title(['\begin{tabular}{c} Monte-Carlo For Both Linear and Non-Linear ' ...
       'Models Using N=300 \ and An Adjoint Simulation; Frequency = 100Hz ' ...
       '$\sigma_{T}=\sigma_{D}=10^{-5}$ \end{tabular}'], ...
      'Interpreter', 'latex');

如果您发现自己主要处理数学方程式而几乎没有文本,matrix 可能更可取(如果需要,使用 \textrm{...} 转义文本):

title('$\matrix{\textrm{Some text} \cr \sigma_{T}=\sigma_{D}=10^{-5}}$', ...
      'Interpreter', 'latex');

你可以这样写:

title({['best solution: ' num2str(1)]... 
[' Cost: ' num2str(20)]})

通过使用 {},您可以将标题写成多行。 请注意,通过使用 [],您可以在同一行中写入。