更改字体粗细

更改字体粗细

我想\newfontfamily{\rb}{Roboto}从这里创建一个新的字体系列:
https://fonts.google.com/specimen/Roboto?subset=latin&preview.text=Hello&preview.text_type=custom#standard-styles

我想写几个字,比如说字重300,可以吗?
我看到了这个问题:设置“字体粗细:较浅/较粗”

但有两件事:

  1. 我想根据特定的词语进行更改,而不是全部更改......
    所以我在寻找类似的命令\textbf或类似的东西。
  2. 我想使用数字(重量的数字)。

谢谢你!

答案1

重量命令演示

Roboto 重量 300 被称为Roboto-Light.ttf,因此,使用推荐的标准重量系列名称(参见),您可以使用作为系列texdoc fntguide加载它,然后设置命令来使用它。fontspec{l}\textl{}

机器人重量

至于在命令名称中使用数字,您可以使用罗马数字(\textiii):

重量

或者,设置一个采用数字选项的通用命令,该命令反过来\text...在后台调用匹配的命令。

重量选项

平均能量损失

\documentclass[12pt]{article}
\newcommand\myfontname{Roboto}
\usepackage[table]{xcolor}
\usepackage{fontspec}
\setmainfont[
    Path = c:/windows/fonts/, 
         Extension = .ttf,
    UprightFont     = *-Regular,
%    BoldFont = *-Bold,
    ItalicFont = *-Italic,
%    BoldItalicFont = *-BoldItalic,
    FontFace = {ul}{\shapedefault}{*-Thin},
    FontFace = {ul}{it}{*-ThinItalic},
%    FontFace = {el}{\shapedefault}{*-ExtraLight},
%    FontFace = {el}{it}{*-ExtraLightItalic},
    FontFace = {l}{\shapedefault}{*-Light},
    FontFace = {l}{it}{*-LightItalic},
    FontFace = {sl}{\shapedefault}{*-Regular},
    FontFace = {sl}{it}{*-Italic},
    FontFace = {m}{\shapedefault}{*-Medium},
    FontFace = {m}{it}{*-MediumItalic},
%    FontFace = {sb}{\shapedefault}{*-SemiBold},
%    FontFace = {sb}{it}{*-SemiBoldItalic},
    FontFace = {b}{\shapedefault}{*-Bold},
    FontFace = {b}{it}{*-BoldItalic},
%    FontFace = {eb}{\shapedefault}{*-ExtraBold},
%    FontFace = {eb}{it}{*-ExtraBoldItalic},
    FontFace = {ub}{\shapedefault}{*-Black},
    FontFace = {ub}{it}{*-BlackItalic},
]{\myfontname}

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
\DeclareRobustCommand{\ulseries}{\fontseries{ul}\selectfont}    \DeclareTextFontCommand{\textul}{\ulseries}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}  \DeclareTextFontCommand{\textl}{\lseries}
\DeclareRobustCommand{\slseries}{\fontseries{sl}\selectfont}    \DeclareTextFontCommand{\textsl}{\slseries}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}  \DeclareTextFontCommand{\textm}{\mseries}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}  \DeclareTextFontCommand{\textb}{\bseries}
    
\DeclareRobustCommand{\ubseries}{\fontseries{ub}\selectfont}    \DeclareTextFontCommand{\textub}{\ubseries}

\newcommand{\texti}[1]{\textul{#1}}
\newcommand{\textiii}[1]{\textl{#1}}
\newcommand{\textiv}[1]{\textsl{#1}}
\newcommand{\textv}[1]{\textm{#1}}
\newcommand{\textvii}[1]{\textb{#1}}
\newcommand{\textix}[1]{\textub{#1}}

\expandafter\newcommand\csname text100\endcsname[1]{\textul{#1}}
\expandafter\newcommand\csname text300\endcsname[1]{\textl{#1}}
\expandafter\newcommand\csname text400\endcsname[1]{\textsl{#1}}
\expandafter\newcommand\csname text500\endcsname[1]{\textm{#1}}
\expandafter\newcommand\csname text700\endcsname[1]{\textb{#1}}
\expandafter\newcommand\csname text900\endcsname[1]{\textub{#1}}

\newcommand\textw[2][400]{\csname text#1\endcsname{#2}}




\newcommand\testtext{{\large abc qwerty}}%  \fontname\font}

\begin{document}

{\Large\bfseries\myfontname}

%\end{tabular}
%------------------------------
\begin{tabular}{llll}
\hline
\rowcolor{blue!12}
Font & Series & Upright & Italic \\
100 ultralight & 
ul  & 
\fontseries{ul}\selectfont\testtext  &
\fontseries{ul}\fontshape{it}\selectfont\testtext  \\
%%
%extralight & 
%el & 
%\fontseries{el}\selectfont\testtext  &
%\fontseries{el}\fontshape{it}\selectfont\testtext  \\
%%
300 light & 
l & 
\fontseries{l}\selectfont\testtext  &
\fontseries{l}\fontshape{it}\selectfont\testtext  \\
%
400 semilight & 
sl & 
\fontseries{sl}\selectfont\testtext  &
\fontseries{sl}\fontshape{it}\selectfont\testtext  \\
%
500 medium & 
m & 
\fontseries{m}\selectfont\testtext  &
\fontseries{m}\fontshape{it}\selectfont\testtext  \\
%%
%semibold & 
%sb & 
%\fontseries{sb}\selectfont\testtext  &
%\fontseries{sb}\fontshape{it}\selectfont\testtext  \\
%%
700 bold & 
b & 
\fontseries{b}\selectfont\testtext  &
\fontseries{b}\fontshape{it}\selectfont\testtext  \\
%
%extrabold & 
%eb & 
%\fontseries{eb}\selectfont\testtext  &
%\fontseries{eb}\fontshape{it}\selectfont\testtext  \\
%%
900 ultrabold & 
ub & 
\fontseries{ub}\selectfont\testtext  &
\fontseries{ub}\fontshape{it}\selectfont\testtext  \\
\hline
\end{tabular}

\bigskip
\scshape
%------------------------------
\begin{tabular}{llll}
\hline
\rowcolor{blue!12}
Font & Series & Upright & Italic \\
ultralight & 
ul  & 
\fontseries{ul}\selectfont\testtext  &
\fontseries{ul}\fontshape{it}\selectfont\testtext  \\
%
%extralight & 
%el & 
%\fontseries{el}\selectfont\testtext  &
%\fontseries{el}\fontshape{it}\selectfont\testtext  \\
%%
light & 
l & 
\fontseries{l}\selectfont\testtext  &
\fontseries{l}\fontshape{it}\selectfont\testtext  \\
%
semilight & 
sl & 
\fontseries{sl}\selectfont\testtext  &
\fontseries{sl}\fontshape{it}\selectfont\testtext  \\
%
medium & 
m & 
\fontseries{m}\selectfont\testtext  &
\fontseries{m}\fontshape{it}\selectfont\testtext  \\
%
%semibold & 
%sb & 
%\fontseries{sb}\selectfont\testtext  &
%\fontseries{sb}\fontshape{it}\selectfont\testtext  \\
%%
bold & 
b & 
\fontseries{b}\selectfont\testtext  &
\fontseries{b}\fontshape{it}\selectfont\testtext  \\
%
%extrabold & 
%eb & 
%\fontseries{eb}\selectfont\testtext  &
%\fontseries{eb}\fontshape{it}\selectfont\testtext  \\
%%
ultrabold & 
ub & 
\fontseries{ub}\selectfont\testtext  &
\fontseries{ub}\fontshape{it}\selectfont\testtext  \\
\hline
\end{tabular}

\bigskip
\textl{This is 300 weight.}
\upshape
\textl{This is 300 weight.} \textbackslash textl\{\}


\bigskip
\scshape
\textiii{This is 300 weight.}
\upshape

\texti{This is 100 weight.} \textbackslash texti\{\}

\textiii{This is 300 weight.} \textbackslash textiii\{\}

\textiv{This is 400 weight.} \textbackslash textiv\{\}

\textv{This is 500 weight.} \textbackslash textv\{\}

\textvii{This is 700 weight.} \textbackslash textvii\{\}

\textix{This is 900 weight.} \textbackslash textix\{\}

\bigskip
xyz \texti{abcde} \textiii{abcde} \textiv{abcde} \textv{abcde} 
\textvii{abcde} \textix{abcde} xyz

\bigskip
\textw[900]{fghijk} = \verb|\textw[900]{fghijk}|

\textw[300]{fghijk} = \verb|\textw[300]{fghijk}|


\end{document}




相关内容