无法使选定的字体起作用

无法使选定的字体起作用

我正在尝试让自定义字体工作,但没有成功。 fc-list显示它们已安装,但XeLaTeX没有编译文件。

stefandekraker ~ % fc-list | grep "Cabinet Grotesk"
/Users/stefandekraker/Library/Fonts/CabinetGrotesk-Extrabold.otf: Cabinet Grotesk,Cabinet Grotesk Extrabold:style=Extrabold,Regular
/Users/stefandekraker/Library/Fonts/CabinetGrotesk-Thin.otf: Cabinet Grotesk,Cabinet Grotesk Thin:style=Thin,Regular
/Users/stefandekraker/Library/Fonts/CabinetGrotesk-Medium.otf: Cabinet Grotesk,Cabinet Grotesk Medium:style=Medium,Regular

我想使用这种Cabinet Grotesk Thin风格。

\setmainfont{Rubik}

\addtokomafont{section}{\LARGE \fontspec{Cabinet Grotesk Thin}\color{Midnight}}
\addtokomafont{subsection}{\Large \fontspec{Cabinet Grotesk Thin}\color{Midnight}}
\addtokomafont{subsubsection}{\large \fontspec{Cabinet Grotesk Thin}\color{Midnight}}

但我一直得到:

Package fontspec Error: The font "Cabinet Grotesk Thin" cannot be
(fontspec)                found.

例子:

\documentclass[11pt]{article}

\renewcommand{\familydefault}{\sfdefault}
\NeedsTeXFormat{LaTeX2e}

\usepackage[paper=a4paper, top=1in, bottom=1.75in, left=1in, right=1.25in]{geometry}

\usepackage{fontspec}
% Setup the custom fonts for the headers and the text itself

\setmainfont{Rubik}

\addtokomafont{section}{\LARGE \fontspec{Cabinet Grotesk Thin}}
\addtokomafont{subsection}{\Large \fontspec{Cabinet Grotesk Thin}}
\addtokomafont{subsubsection}{\large \fontspec{Cabinet Grotesk Thin}}

\addtokomafont{disposition}{\fontspec{Rubik}}
\addtokomafont{sectionentry}{\fontspec{Rubik}}

\begin{document}
    \section{Test}
    Some text for testing the fonts of the document

\end{document}

更新

\newfontface{\cabinet}{CabinetGrotesk-Thin}抛出此错误: 在此处输入图片描述

答案1

我通过在项目根目录中包含字体文件夹来使其工作fonts。 并借助命令Path的参数向文件夹添加绝对路径\setmainfont

\setmainfont[Path=<Absolute_path>/fonts/]{Rubik-Light.ttf}[
    BoldFont       = Rubik-Medium.ttf,
    ItalicFont     = Rubik-LightItalic.ttf,
    BoldItalicFont = Rubik-MediumItalic.ttf]

相关内容