1

I have defined the color of my fonts in the preamble. What I am trying to accomplish is to change the color of just one word within the document, but I am unable to do this.

Usually, within the body of the document I would use:

\begin{document}

{\color{blue} This sentence is blue}

\end{document}

But for some reason this method does not work. Any thoughts would be much appreciated.

Here is my preamble:

\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}
6

You can use \addfontfeature to change the font color:

\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}

Result:

enter image description here

4

The Answer by Ralf works with XeLaTeX alternatively using LuaLaTeX you can continue using \color{blue}

Preamble

\usepackage{luacolor}  

\begin{document}
This sentence is primary color
{\color{blue} This sentence is blue}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.