我在序言中定义了字体的颜色。我想做的是只更改文档中一个单词的颜色,但我无法做到这一点。
通常,我会在文档正文中使用:
\begin{document}
{\color{blue} This sentence is blue}
\end{document}
但不知为何,这种方法不起作用。任何想法都将不胜感激。
以下是我的序言:
\documentclass[letterpaper,10pt]{article}
\usepackage{latexsym}
\usepackage[empty]{fullpage}
\usepackage{titlesec}
\usepackage{marvosym}
\usepackage[usenames,dvipsnames]{color}
\usepackage{verbatim}
\usepackage{enumitem}
\usepackage[pdftex]{hyperref}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
% Adjust margins
\addtolength{\oddsidemargin}{-0.375in}
\addtolength{\evensidemargin}{-0.375in}
\addtolength{\textwidth}{1in}
\addtolength{\topmargin}{-.5in}
\addtolength{\textheight}{1.0in}
\urlstyle{same}
\raggedbottom
\raggedright
\setlength{\tabcolsep}{0in}
% Color definitions
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{date}{HTML}{666666}
\definecolor{primary}{HTML}{2b2b2b}
\definecolor{headings}{HTML}{6A6A6A}
\definecolor{subheadings}{HTML}{333333}
% Set main fonts
\usepackage{fontspec}
\setmainfont[Color=primary, Path = fonts/lato/,BoldItalicFont=Lato-RegIta,BoldFont=Lato-Reg,ItalicFont=Lato-LigIta]{Lato-Lig}
\setsansfont[Scale=MatchLowercase,Mapping=tex-text, Path = fonts/raleway/]{Raleway-ExtraLight}
答案1
您可以使用\addfontfeature
来更改字体颜色:
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{primary}{HTML}{2b2b2b}
\usepackage{fontspec}
\setmainfont[Color=primary]{Latin Modern Roman}
\begin{document}
This sentance is in primary color.
{\addfontfeature{Color=blue} This sentence is blue}
This sentance is in primary color.
\end{document}
结果:
答案2
Ralf 的答案适用于 XeLaTeX 或者使用 LuaLaTeX,您可以继续使用 \color{blue}
前言
\usepackage{luacolor}
\begin{document}
This sentence is primary color
{\color{blue} This sentence is blue}
\end{document}