如何使用 sourcesanspro 字体在同一个文档中使用浅色、普通、半粗和粗体字体类型?如果我指定默认选项,我可以获得普通和粗体,但不能获得浅色或半粗体。如果我使用浅色选项,我可以获得浅色和半粗体,但不能获得普通或粗体。
下面是一个 MWE。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage[default% with default, I can get normal and bold, but not light and semibold
%, light% If I add this line, I can get light and semibold, but not normal and bold
]{sourcesanspro}
\begin{document}
How do I get all these types of text in one document on demand?
\begin{itemize}
\item light %how?
\item \textmd{normal}
\item semibold %how?
\item \textbf{bold}
\end{itemize}
\end{document}
答案1
该sourcesanspro
包(见文档)还提供了选择特定字体集的命令以方便使用:
\sourcesanspro
适用于常规和粗体字重\sourcesansprolight
适用于浅色和半粗体\sourcesansproextreme
获得额外的亮度和黑色
以下也会产生您想要的结果:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage[default]{sourcesanspro}
\begin{document}
How do I get all these types of text in one document on demand?
\begin{itemize}
\item \textmd{\sourcesansproextreme extra light}
\item \textmd{\sourcesansprolight light}
\item \textmd{\sourcesanspro normal}
\item \textbf{\sourcesansprolight semibold}
\item \textbf{\sourcesanspro bold}
\item \textbf{\sourcesansproextreme black}
\end{itemize}
\end{document}
\sourcesanspro
当然,这实际上没有必要。
答案2
谢谢特蕾莎,我找到了答案这里。作为新手,我没有意识到\usepackage{sourcesanspro}
下载字体到它们是可调用的,如下面的工作代码所示。我还必须删除调用时定义的选项\usepackage
。工作代码如下:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\usepackage[%default% including default overrides the \setmainfont below.
%, light%
]{sourcesanspro}
% Found answer in https://tex.stackexchange.com/questions/264265/defining-subfamilies-for-a-font/264275#264275
\setmainfont{SourceSansPro}[ %list of fonts included in sourcesanspro package are listed here: http://mirrors.ctan.org/fonts/sourcesanspro/doc/sourcesanspro.tex
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-RegularIt,
BoldFont=*-Bold,
BoldItalicFont=*-BoldIt,
FontFace={xl}{n}{*-ExtraLight},
FontFace={xl}{it}{*-ExtraLightIt},
FontFace={l}{n}{*-Light},
FontFace={l}{it}{*-LightIt},
FontFace={mb}{n}{*-Semibold},
FontFace={mb}{it}{*-SemiboldIt},
FontFace={k}{n}{*-Black},
FontFace={k}{it}{*-BlackIt},
]
\newcommand{\test}[2]{%
#1: {\fontseries{#2}\selectfont This is upright. \itshape This is italic}\par
}
\begin{document}
I can now get all these types of text in one document on demand.
\vspace{\baselineskip}
\test{ExtraLight}{xl}
\test{Light}{l}
\test{Regular}{m}
\test{Medium}{mb}
\test{Bold}{bx}
\test{Black}{k}
\end{document}
结果: