更改 tikz 中的字体

更改 tikz 中的字体

你能帮我用这个文档类来编译这个饼图吗?

主文本

\documentclass[]{cv-style}

%-------------------------------------------------------------------------------------
% Diagram
%-------------------------------------------------------------------------------------
\begin{document}

\begin{tikzpicture}[text=white, border/.style={line width=14mm}]
  \foreach \angle/\col [remember=\angle as \last (initially 1)] in 
    {90/blue, 162/red, 234/green, 288/purple, 342/orange, 360/aquamarine}{
      \draw[\col, border] (\last:2cm) 
          arc[start angle=\last, end angle=\angle, radius=2cm];
      \draw[white, line width=1mm] (\last:1.3)--++(\last:1.4);
  }
  \node[line width=1mm, draw, circle, white, minimum width=2.5cm, fill=lightgray] {\large C/C++};
  \node[text width=1cm, align=center] at (50:2cm) {C\# (.NET)};
  \node[text width=1cm, align=center] at (130:2cm) {Java};
  \node[text width=1cm, align=center] at (195:2cm) {JS};
  \node[text width=1cm, align=center] at (260:2cm) {PHP HTML CSS};
  \node[text width=1cm, align=center] at (315:2cm) {SQL};
  \node[text width=1cm, align=center] at (353:2cm) {Scripts};
\end{tikzpicture}

\end{document}

cv-style.cls

\ProvidesClass{cv-style}[2015/02/27 CV class]
\NeedsTeXFormat{LaTeX2e}

\ProcessOptions\relax
\LoadClass{article}

\RequirePackage{tikz}

%-------------------------------------------------------------------------------------
% Définition des couleurs
%-------------------------------------------------------------------------------------
\RequirePackage{xcolor}

\definecolor{white}{RGB}{255,255,255}

\definecolor{lightgray}{HTML}{C0C0C0}
\definecolor{gray}{HTML}{303030}
\definecolor{darkgray}{HTML}{333333}

\definecolor{blue}{HTML}{1DB1FC}
\definecolor{red}{HTML}{DC3912}
\definecolor{orange}{HTML}{FF9900}
\definecolor{green}{HTML}{109618}
\definecolor{purple}{HTML}{9358FE}
\definecolor{aquamarine}{HTML}{0C343D}

\definecolor{date}{HTML}{A4A4A4}

\colorlet{fillheader}{white}
\colorlet{namecolor}{black}
\colorlet{headercolor}{black}
\colorlet{headerSub}{darkgray}
\colorlet{textcolor}{gray}


%-------------------------------------------------------------------------------------
% Définition des polices
%-------------------------------------------------------------------------------------
\RequirePackage[quiet]{fontspec}
\RequirePackage[math-style=TeX,vargreek-shape=unicode]{unicode-math}

\newfontfamily\bodyfont
[BoldFont=texgyreheros-bold.otf,
ItalicFont=texgyreheros-italic.otf,
BoldItalicFont=texgyreheros-bolditalic.otf]
{texgyreheros-regular.otf}
\newfontfamily\bodyfont{Roboto-Regular}[Path=fonts/]
\newfontfamily\bodyfontit{Roboto-LightItalic}[Path=fonts/]
\newfontfamily\thinfont{Roboto-Thin}[Path=fonts/]
\newfontfamily\headingfont{RobotoCondensed-Bold}[Path=fonts/]

\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=textcolor, Path = fonts/]{Roboto-Light}

\renewcommand{\bfseries}{\fontsize{11pt}{11pt}\headingfont\color{headerSub}}

\newcommand{\italica}[1]{%
    {\color{gray}\bodyfontit #1}%
}

你可以找到它这里

答案1

您需要将字体选项传递给您的tikzpicture,使用font=方括号内的某个位置。

我没有 Roboto 字体,所以我使用 Baskerville 来演示。

在此处输入图片描述

\begin{filecontents}{cv-style.cls}
\ProvidesClass{cv-style}[2015/02/27 CV class]
\NeedsTeXFormat{LaTeX2e}

\ProcessOptions\relax
\LoadClass{article}

\RequirePackage{tikz}

%-------------------------------------------------------------------------------------
% Définition des couleurs
%-------------------------------------------------------------------------------------
\RequirePackage{xcolor}

\definecolor{white}{RGB}{255,255,255}

\definecolor{lightgray}{HTML}{C0C0C0}
\definecolor{gray}{HTML}{303030}
\definecolor{darkgray}{HTML}{333333}

\definecolor{blue}{HTML}{1DB1FC}
\definecolor{red}{HTML}{DC3912}
\definecolor{orange}{HTML}{FF9900}
\definecolor{green}{HTML}{109618}
\definecolor{purple}{HTML}{9358FE}
\definecolor{aquamarine}{HTML}{0C343D}

\definecolor{date}{HTML}{A4A4A4}

\colorlet{fillheader}{white}
\colorlet{namecolor}{black}
\colorlet{headercolor}{black}
\colorlet{headerSub}{darkgray}
\colorlet{textcolor}{gray}


%-------------------------------------------------------------------------------------
% Définition des polices
%-------------------------------------------------------------------------------------
\RequirePackage[quiet]{fontspec}
\RequirePackage[math-style=TeX,vargreek-shape=unicode]{unicode-math}

\newfontfamily\bodyfont
[BoldFont=texgyreheros-bold.otf,
ItalicFont=texgyreheros-italic.otf,
BoldItalicFont=texgyreheros-bolditalic.otf]
{texgyreheros-regular.otf}
\newfontfamily\bodyfont{Baskerville}
\newfontfamily\bodyfontit{Baskerville Italic}
\newfontfamily\thinfont{Baskerville}
\newfontfamily\headingfont{Baskerville SemiBold}

\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=textcolor]{Avenir Next}

\renewcommand{\bfseries}{\fontsize{11pt}{11pt}\headingfont\color{headerSub}}

\newcommand{\italica}[1]{%
    {\color{gray}\bodyfontit #1}%
}
\end{filecontents}

\documentclass[]{cv-style}

%-------------------------------------------------------------------------------------
% Diagram
%-------------------------------------------------------------------------------------
\begin{document}

\begin{tikzpicture}[text=white, border/.style={line width=14mm},font=\bodyfontit]
  \foreach \angle/\col [remember=\angle as \last (initially 1)] in 
    {90/blue, 162/red, 234/green, 288/purple, 342/orange, 360/aquamarine}{
      \draw[\col, border] (\last:2cm) 
          arc[start angle=\last, end angle=\angle, radius=2cm];
      \draw[white, line width=1mm] (\last:1.3)--++(\last:1.4);
  }
  \node[line width=1mm, draw, circle, white, minimum width=2.5cm, fill=lightgray] {\large C/C++};
  \node[text width=1cm, align=center] at (50:2cm) {C\# (.NET)};
  \node[text width=1cm, align=center] at (130:2cm) {Java};
  \node[text width=1cm, align=center] at (195:2cm) {JS};
  \node[text width=1cm, align=center] at (260:2cm) {PHP HTML CSS};
  \node[text width=1cm, align=center] at (315:2cm) {SQL};
  \node[text width=1cm, align=center] at (353:2cm) {Scripts};
\end{tikzpicture}

\end{document}

相关内容