5

Here is a minimal problem example

\ProvidesClass{cvMinimal}[2012/04/30 CV class]
\NeedsTeXFormat{LaTeX2e}

\LoadClass{article}


%%%%%%%%%%
% Colors %
%%%%%%%%%%

\RequirePackage{xcolor}
\definecolor{green}{HTML}{C2E15F}
\definecolor{gray}{HTML}{4D4D4D}

%%%%%%%%%
% Fonts %
%%%%%%%%%

\RequirePackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=gray]{Helvetica Neue Light}

%%%%%%%%%%
% Header %
%%%%%%%%%%

\RequirePackage{tikz}
    \usetikzlibrary{positioning}

\newcommand{\header}[0]{%
    \begin{tikzpicture}[remember picture, overlay]
        \node[](name){\fontsize{24pt}{72pt}\selectfont\color{green}{My Name}};  %
    \end{tikzpicture}  
    }

produces a gray "My name" wheras I would expect to produce a green one. Commenting the line setmainfont solves the problem.

Can someone explain me what do I do wrong ? And how to get what I want without commenting the setmainfontline which is important in the rest of my document?

I know it is possible since it is achieved in the cv here.

2

As I suggested in my comment, the 'manual' way would be to call \addfontfeature where you want it. Another solution would be to use the SizeFeatures option for fontspec. Both are illustrated below. (I used Adobe's Source Sans Pro since I don't have Helvetica.)

\documentclass{article}

\usepackage{xcolor}
\definecolor{green}{HTML}{C2E15F}
\definecolor{gray}{HTML}{4D4D4D}

%%%%%%%%%
% Fonts %
%%%%%%%%%

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[ Mapping=tex-text,
  SizeFeatures={
   {Size={-24}, Color=gray},
   {Size={24-}, Color=green}}
 ]{Source Sans Pro}

%%%%%%%%%%
% Header %
%%%%%%%%%%

\usepackage{tikz}
    \usetikzlibrary{positioning}

\newcommand{\header}[0]{%
    \begin{tikzpicture}[remember picture, overlay]
         % \node[](name){%                       <-- manual solution
         %   \fontsize{24pt}{72pt}\selectfont%
         %   {\addfontfeatures{Color=green}{My Name}}};
         %
         \node[](name2){%                       <-- uses SizeFeatures
           \fontsize{24pt}{72pt}\selectfont {My Name2}};
    \end{tikzpicture}
    }

\begin{document}

\header


my name;

\fontsize{24pt}{72pt}\selectfont my name;

\end{document}
6

In my opinion it's better to define separate font families: one for the main text font, another one for the special items. Here's an example.

\documentclass{article}
\usepackage{xcolor}
\definecolor{cvgreen}{HTML}{C2E15F} % give distinctive names to colors
\definecolor{cvgray}{HTML}{4D4D4D}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX,Color=cvgray]{Helvetica Neue Light}
\newfontfamily{\greenHelv}[Ligatures=TeX,Color=cvgreen]{Helvetica Neue Light}

\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand{\header}[1]{%
  \begin{tikzpicture}[remember picture, overlay]
  \node[](name){\fontsize{24pt}{72pt}\greenHelv #1};
  \end{tikzpicture}
}

\begin{document}
\header{My Name}

\bigskip

\noindent Some text following
\end{document}

enter image description here

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.