Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I always typeset bar plots (using the pgfplots package that uses math-mode for pgfplots labeling) with a sans serif font. Since I'm using LuaTeX I'm running into problems (see also Bar plots in sans serif font where I described the same problem). With PDFTeX the sansmath package and @sebschub's MyriadPro files solve the problem. But I can't get to implement those functionalities with fontspec. How can I typeset pgfplots bar plots with LuaTeX/fontspec?

Here's a MWE with the fonts I use (MinionPro and MyriadPro that ship with Adobe Reader):

\documentclass{scrartcl}
\usepackage{%
  sansmath%
} 
\usepackage{fontspec}
\setmainfont[%
  BoldFont={MinionPro-Bold}%
  ,ItalicFont={MinionPro-It}%
  ,BoldItalicFont={MinionPro-BoldIt}%
  ,Numbers=OldStyle%
]{MinionPro-Regular}

\setsansfont[%
  Scale=MatchLowercase%
  ,BoldFont={MyriadPro-Bold}%
  ,ItalicFont={MyriadPro-It}%
  ,BoldItalicFont={MyriadPro-BoldIt}%
  ,Numbers=OldStyle%
]{MyriadPro-Regular}
\setmathsf{MyriadPro-Regular}
\usepackage{pgfplots}
\pgfplotsset{%
  /tikz/font=\sansmath\sffamily
}
\usepackage{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  xbar,
  xlabel={a--d},
  symbolic y coords={a,b,c,d},
  ytick=data,
  nodes near coords, nodes near coords align={horizontal},
  ]
  \addplot coordinates {
    (45,a)
    (20,b)
    (1,c)
    (5,d)
    };
\end{axis}
\end{tikzpicture}
\end{document}

Here's the corresponding plot (I don't want italic fonts):

Bar plot with italic sans serif fonts

Here are some of the pgfplotsset options I already tried (and noted down):

\pgfplotsset{%
%  ,tick label style = {font=\sansmath\sffamily}%
%  ,tick style = {font=\sansmath\sffamily}
%  ,every axis label = {font=\sansmath\sffamily}%
%  ,every axis/.style={font=\sansmath\sffamily}%
%  ,xticklabel={$\pgfmathprintnumber{\sansmath\tick}$}%
  ,/tikz/font=\sansmath\sffamily
%  ,legend style = {font=\sansmath\sffamily}%
%  ,label style = {font=\sansmath\sffamily}%
}

If you know a better place to ask this question let me know, please. TIA

share|improve this question
1  
No need to include signature, see faq "Can I use a signature or tagline?" –  Peter Jansson Jan 2 '13 at 15:20
    
@Peter Jansson: Do you consider a complimentary close like “Best regards Christoph” as a signature? –  typokurz Jan 2 '13 at 15:48
1  
@typokurz: Greetings, thank yous, signatures, etc. are all generally discouraged on the Stackexchange sites for reasons of conciseness (see Why is “thanks” inappropriate at the end of a question? for an explanation). –  Jake Jan 2 '13 at 16:01
add comment

2 Answers

up vote 8 down vote accepted

here is a solution without using package sansmath

\documentclass{scrartcl}
\usepackage{unicode-math}
\setmainfont[%
  BoldFont={MinionPro-Bold}%
  ,ItalicFont={MinionPro-It}%
  ,BoldItalicFont={MinionPro-BoldIt}%
  ,Numbers=OldStyle%
]{MinionPro-Regular}
\setsansfont[%
  Scale=MatchLowercase%
  ,BoldFont={MyriadPro-Bold}%
  ,ItalicFont={MyriadPro-It}%
  ,BoldItalicFont={MyriadPro-BoldIt}%
  ,Numbers=OldStyle%
]{MyriadPro-Regular}  
\setmathfont{MyriadPro-Regular}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  xbar,
  xlabel={a--d},
  symbolic y coords={a,b,c,d},
  ytick=data,
  nodes near coords, nodes near coords align={horizontal},
  ]
  \addplot coordinates {
    (45,a)
    (20,b)
    (1,c)
    (5,d)
    };
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thank you, Herbert! –  typokurz Jan 2 '13 at 15:54
add comment

If all of sansmath you need is printing numbers in the sans serif typeface and not general math expressions, here's a hack:

\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX,
  Numbers=OldStyle,
]{Minion Pro}

\setsansfont[Ligatures=TeX,
  Scale=MatchLowercase,
]{Myriad Pro}
\usepackage{pgfplots}
\pgfplotsset{%
  /tikz/font=\plotsf
}

\newfam\plotsffam
\newcommand\plotsf{%
  \sffamily
  \everymath{%
    \textfont\plotsffam=\usesf
    \mathcode`0=\numexpr 256*\plotsffam+`0\relax
    \mathcode`1=\numexpr 256*\plotsffam+`1\relax
    \mathcode`2=\numexpr 256*\plotsffam+`2\relax
    \mathcode`3=\numexpr 256*\plotsffam+`3\relax
    \mathcode`4=\numexpr 256*\plotsffam+`4\relax
    \mathcode`5=\numexpr 256*\plotsffam+`5\relax
    \mathcode`6=\numexpr 256*\plotsffam+`6\relax
    \mathcode`7=\numexpr 256*\plotsffam+`7\relax
    \mathcode`8=\numexpr 256*\plotsffam+`8\relax
    \mathcode`9=\numexpr 256*\plotsffam+`9\relax
  }%
}
\AtBeginDocument{{\sffamily\xdef\usesf{\the\font}}}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  xbar,
  xlabel={a--d},
  symbolic y coords={a,b,c,d},
  ytick=data,
  nodes near coords, nodes near coords align={horizontal},
  ]
  \addplot coordinates {
    (45,a)
    (20,b)
    (1,c)
    (5,d)
    };
\end{axis}
\end{tikzpicture}
\end{document}

The idea is to change the mathcode of the digits to choose the right typeface.

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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