如何给单词添加字距调整

如何给单词添加字距调整

在我的Lbend命令中,我需要在第二个单词字母之间留出更多空间。如何在字母之间留出更多空间?

\addfontfeature{LetterSpace=5.0}不想使用 \TU/lmtt/bx/n/24.88字体,我收到警告fontspec Warning: \addfontfeature(s) ignored

%%MWE
\documentclass[xetex,12pt,a4paper]{article}
\usepackage{fontspec}
\newfontfamily{\defaultfont}{Latin Modern Roman}

\newlength{\tmpw}\newlength{\tmph}
\newcommand{\Lbend}[2]{\settowidth{\tmpw}{#1}\settoheight{\tmph}{#1}%
\smash{#1{\hspace{-1.02\tmpw}\raisebox{-0.55ex}{\rule{.05\tmph}{0.8ex}\rule{.7\tmpw}{.05\tmph}}}%
\raisebox{-0.80ex}{\addfontfeature{LetterSpace=5.0}\bfseries #2}}}%

\begin{document}
{\ttfamily \bfseries\Huge{\Lbend{slackware}{\small linux}}}\\

{\ttfamily \Large{\Lbend{testtest}{\tiny test}}}\\

\end{document}
%%EOF

标识

答案1

如果您想通过 fontspec 启用字母间距(例如使用\addfontfeature),则必须通过 fontspec 加载受影响的字体。在这种情况下,您使用\ttfamily,因此您需要等宽字体(\setmonofont)。默认的等宽字体是Latin Modern Mono Light

根据您的\defaultfont代码,我假设您的系统上有 Latin Modern 作为系统字体。(顺便说一句,应该改为这样\setmainfont,否则该代码不会执行任何操作。)

\documentclass[xetex,12pt,a4paper]{article}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman} % Not necessary for this, but I guess that's what you tried to do woth the \defaultfont line?
\setmonofont{Latin Modern Mono Light} % Load Latin Modern's monospace font.

\newlength{\tmpw}\newlength{\tmph}
\newcommand{\Lbend}[2]{\settowidth{\tmpw}{#1}\settoheight{\tmph}{#1}%
\smash{#1{\hspace{-1.02\tmpw}\raisebox{-0.55ex}{\rule{.05\tmph}{0.8ex}\rule{.7\tmpw}{.05\tmph}}}%
\raisebox{-0.80ex}{\addfontfeature{LetterSpace=5.0}\bfseries #2}}}%

\begin{document}
\expandafter\show\the\font
{\ttfamily \bfseries\Huge{\Lbend{slackware}{\small linux}}}\\

{\ttfamily \Large{\Lbend{testtest}{\tiny test}}}\\

\end{document}

在此处输入图片描述

相关内容