逐字未正确对齐 - XeLaTeX

逐字未正确对齐 - XeLaTeX

我尝试过:

\documentclass{article}

\usepackage{fontspec}%
\usepackage[bold-style=TeX]{unicode-math}%
\setmainfont[Ligatures=TeX, Path = ./ ,
UprightFont= MinionPro-Regular.otf,
BoldFont= MinionPro-Bold.otf,
ItalicFont= MinionPro-It.otf,
BoldItalicFont= MinionPro-BoldIt.otf,
]{MinionPro}%
\setmathfont{XITS Math}
\setmathfont[Numbers=Lining,range=\mathup/{num,latin,Latin,}]{MinionPro-Regular}%greek,Greek
\setmathfont[Numbers=Lining,range=\mathit/{num,latin,Latin}]{MinionPro-It}%,greek,Greek
\setmathfont[Numbers=Lining,range=bfup/{num,latin,Latin}]{MinionPro-Bold}%,greek,Greek
\setmathfont[Numbers=Lining,range=bfit/{num,latin,Latin}]{MinionPro-BoldIt}%,greek,Greek
\usepackage{MnSymbol}
\setmonofont[Scale=MatchLowercase]{Courier New}%

\begin{document}

\begin{verbatim}
model_4bead = function(t,y,pars){
  # model_4bead = function(t,y,pars)
  # RFT dynamics for a three-link swimmer
  # y -> bx, by, theta, vbx, vby, vtheta, alpha1, alpha2
  # An eight-coordinate dynamic, only six of which are considered here
  # The other two are prescribed by the initernal gait dynamics
  # Coords
\end{verbatim}

\end{document}

生成的输出为:

在此处输入图片描述

我已经在TeX文件中正确对齐了所有内容,但在PDF输出中未正确对齐,请指教,如何正确对齐。

我正在使用Win10MikTeX V2.9 - XeLaTeX获取输出

我有很多这样的程序代码,请指教。

答案1

不知道为什么,但显然unicode-math在等宽字体的单词间距中引入了灵活性,当发现超额行时就会启动。

解决方法:使用该WordSpace功能。

\documentclass{article}

\usepackage[bold-style=TeX]{unicode-math}
\usepackage{MnSymbol}

\setmainfont{MinionPro}[
  Path=/Library/Fonts/,
  UprightFont= *-Regular.otf,
  BoldFont= *-Bold.otf,
  ItalicFont= *-It.otf,
  BoldItalicFont= *-BoldIt.otf,
]
\setmathfont{XITS Math}
\setmathfont{XITS Math}
\setmathfont{MinionPro-Regular}[
  Numbers=Lining,
  range=\mathup/{num,latin,Latin,}
]
\setmathfont{MinionPro-It}[
  Numbers=Lining,
  range=\mathit/{num,latin,Latin}
]
\setmathfont{MinionPro-Bold}[
  Numbers=Lining,
  range=bfup/{num,latin,Latin}
]
\setmathfont{MinionPro-BoldIt}[
  Numbers=Lining,
  range=bfit/{num,latin,Latin}
]
\setmonofont{Courier New}[
  Scale=MatchLowercase,
  WordSpace={1,0,0},
]

\begin{document}

\begin{verbatim}
model_4bead = function(t,y,pars){
  # model_4bead = function(t,y,pars)
  # RFT dynamics for a three-link swimmer
  # y -> bx, by, theta, vbx, vby, vtheta, alpha1, alpha2
  # An eight-coordinate dynamic, only six of which are considered here
  # The other two are prescribed by the initernal gait dynamics
  # Coords
\end{verbatim}

\end{document}

在此处输入图片描述

答案2

您可以在没有 MinionPro(我没有)的情况下演示这一点,因为终端上警告这两行太满,与经典的 cmtt Courier New 不同,它设置了可收缩的空白,因此这些行上的空格会收缩。

在加载 unicode-math 之前设置 mono 字体

\documentclass{article}

\usepackage{fontspec}%


\setmonofont[Scale=MatchLowercase]{Courier New}%

\usepackage[bold-style=TeX]{unicode-math}%

\begin{document}

\begin{verbatim}
model_4bead = function(t,y,pars){
  # model_4bead = function(t,y,pars)
  # RFT dynamics for a three-link swimmer
  # y -> bx, by, theta, vbx, vby, vtheta, alpha1, alpha2
  # An eight-coordinate dynamic, only six of which are considered here
  # The other two are prescribed by the initernal gait
  # Coords
\end{verbatim}

\end{document}

在此处输入图片描述

相关内容