4

I have a bunch of figures that I am compiling using the standalone class in which I load two font packages mathpazo for the serif fonts and cabin for the sans serif fonts. The problem is that when I load in the cabin package, neither font gets used in the output pdf, everything reverts to the default fonts. Is there a way to load these packages but only apply mathpazo to the serif/math fonts and cabin to the sans serif fonts?

EDIT: I should note that I am using LuaLaTeX to compile. EDIT: I want the entire figure to be the normal serif fonts and only the \textsf{} node that I have shown to be sans serif.

MWE:

\documentclass[class=minimal,border=0pt]{standalone}

\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{>=latex}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.13}
\usepackage{mathpazo}
\usepackage[condensed]{cabin}   

\begin{document}

\begin{tikzpicture}
\pgfplotsset{every axis/.append style={width=2.0in,height=2.0in,scale only axis}}
\pgfplotsset{every axis/.append style={view={0}{90},ymin=0,ymax=0.3048,xmin=-0.1524,xmax=0.1524,minor tick num=4,point meta min=0,point meta max=1.5}}

\begin{axis}[colorbar,colormap/jet,xlabel={$x$-Position, [m]},ylabel={$y$-Position, [m]},
colorbar style={at={(1.03,0.5)},y tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=1,/tikz/.cd},
anchor=west,ylabel={Velocity, [m/s]},minor tick num=4,ylabel style={rotate=180}}]
    \node[draw=none,anchor=south west,inner sep=0] at (rel axis cs:0,0) {\includegraphics[width=2.0in]{example-image-a}};           
    \draw[black,->,thick] (rel axis cs:0.98,0.98) -- ++(-135:0.30in);
    \draw[black,-,thick,densely dashed]  (0,0) -- (0,0.3048);
    \node[draw=none,anchor=south west] at (rel axis cs:0,0) {\textsf{SansSerif Text}};
\end{axis}
\begin{axis}[xticklabels={},yticklabels={}]   
    %Empty axis for plotting ticks on top of contour
\end{axis}

\end{tikzpicture}

\end{document}
  • The line \pgfplotsset{compat=1.13} is causing errors for me. Can you update the MWE so that it actually compiles exactly as is? – Jason Zentz May 25 '16 at 18:43
  • @JasonZentz It compiles just fine on my computer. You probably just need to update to the latest version of PGFPlots. – Kyle Jones May 25 '16 at 18:51
  • 1
    Can you compile with pdflatex or xelatex? There's no problem with them. Other than that, it seems to be a pgf bug and the proposed solution on sourceforge doesn't work on my system. – Bernard May 25 '16 at 19:22
  • @Bernard I cannot use another compiler because some of the other packages I use are lualatex only. I have tried xelatex before but never seems to work for me. This MWE is missing some of the complexities that I have in the actual figure. – Kyle Jones May 25 '16 at 19:27
  • Please don't use minimal for examples. It is not designed for this and is not suitable. – cfr May 25 '16 at 21:23
3

Here are a few possible solutions:

1. Use pdfLaTeX

The fonts come out correctly if you compile your MWE using pdfLaTeX.

2. Use fontspec with LuaLaTeX or XeLaTeX

LuaLaTeX and XeLaTeX will allow you to use fontspec to load any .ttf or .otf font in your system's font folder or your TeX distribution.*

Here, I have used fontspec to load Palatino Linotype (a system font) and Cabin (part of the TeX distribution) as the main and sans serif fonts, respectively. If you want to use a Palatino variant that comes with the TeX distribution, you can use TeX Gyre Pagella instead. Loading mathpazo before the fontspec declaration (with the no-math option) allows you to keep using that for your math font.

\documentclass[border=0pt]{standalone} % removed class=minimal option from the MWE per cfr's comment belowl

\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{>=latex}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.13}

\usepackage{mathpazo}
\usepackage[no-math]{fontspec}
\setmainfont{TeX Gyre Pagella}
\setsansfont{Cabin Condensed Regular}

\begin{document}

\begin{tikzpicture}
\pgfplotsset{every axis/.append style={width=2.0in,height=2.0in,scale only axis}}
\pgfplotsset{every axis/.append style={view={0}{90},ymin=0,ymax=0.3048,xmin=-0.1524,xmax=0.1524,minor tick num=4,point meta min=0,point meta max=1.5}}

\begin{axis}[colorbar,colormap/jet,xlabel={$x$-Position, [m]},ylabel={$y$-Position, [m]},
colorbar style={at={(1.03,0.5)},y tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=1,/tikz/.cd},
anchor=west,ylabel={Velocity, [m/s]},minor tick num=4,ylabel style={rotate=180}}]
    \node[draw=none,anchor=south west,inner sep=0] at (rel axis cs:0,0) {\includegraphics[width=2.0in]{example-image-a}};           
    \draw[black,->,thick] (rel axis cs:0.98,0.98) -- ++(-135:0.30in);
    \draw[black,-,thick,densely dashed]  (0,0) -- (0,0.3048);
    \node[draw=none,anchor=south west] at (rel axis cs:0,0) {\textsf{SansSerif Text}};
\end{axis}
\begin{axis}[xticklabels={},yticklabels={}]   
    %Empty axis for plotting ticks on top of contour
\end{axis}

\end{tikzpicture}

\end{document}

enter image description here

*According to pp. 8-10 of the fontspec documentation (v2.5a), both XeLaTeX and LuaLaTeX allow you to load system fonts using either the font's name or filename. The documentation states that both engines also allow you to load any .ttf or .otf font that is part of your TeX distribution; LuaLaTeX lets you do this with the font's name or filename, but XeLaTeX requires you do to this with the font's filename. However, I wasn't able to replicate this difference between XeLaTeX and LuaLaTeX; on my machine, both were able to use just the font name to load fonts, regardless of whether they were in my system font folder or my TeX distribution. In other words, the example I provide here compiled successfully with both engines.

  • This is a good solution, however, I'm not the only one that will be using these figures so having to download/install a font package just to be able to get the same image isn't a very useful solution. Is there any way to do the same thing without having to install the font I want to use? – Kyle Jones May 25 '16 at 19:02
  • I should also note that the no-math option on the fontspec package doesn't work. Looked around and it seems to be an error in the current release (v2.5a) and can be corrected by using this instead \PassOptionsToPackage{no-math}{fontspec} \usepackage{fontspec} – Kyle Jones May 25 '16 at 19:13
  • I've updated the answer to reflect the fact that it's not necessary to put the Cabin font files in your system font directory (XeLaTeX and LuaLaTeX are slightly different in this respect -- see pp. 8-10 of the fontspec documentation). – Jason Zentz May 25 '16 at 20:29
  • It is not possible to load the mathpazo text font using fontspec (or unicode-math, which builds on fontspec). So I have added the option of compiling with XeLaTeX or pdfLaTeX if you are really wedded to using the mathpazo text font as the main document font rather than some other Palatino variant like TeX Gyre Pagella, which comes with standard TeX distributions and can be loaded with fontspec. – Jason Zentz May 25 '16 at 20:31
  • Please do not use minimal for examples. It is not suitable. \PassOptionsToPackage{<options>}{<package>} \usepackage{<package>} is pointlessly complicated. It makes no sense to use \PassOptions... here. You make it sound as if fontspec is specific to LuaLaTeX but it is not. You can equally use it with XeLaTeX and equally not use it with LuaLaTeX. – cfr May 25 '16 at 21:19
1

Use the TeX Gyre fonts they are part of any TeX distribution.

\documentclass[class=minimal,border=0pt]{standalone}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{>=latex}
\usepackage{pgfplots}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setsansfont{TeX Gyre Heros}
\setmathfont{texgyrepagella-math.otf}

\begin{document}

    \begin{tikzpicture}
    \pgfplotsset{every axis/.append style={width=2.0in,height=2.0in,scale only axis}}
    \pgfplotsset{every axis/.append style={view={0}{90},ymin=0,ymax=0.3048,xmin=-0.1524,xmax=0.1524,minor tick num=4,point meta min=0,point meta max=1.5}}

    \begin{axis}[colorbar,colormap/jet,xlabel={$x$-Position, [m]},ylabel={$y$-Position, [m]},
    colorbar style={at={(1.03,0.5)},y tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=1,/tikz/.cd},
        anchor=west,ylabel={Velocity, [m/s]},minor tick num=4,ylabel style={rotate=180}}]
    \node[draw=none,anchor=south west,inner sep=0] at (rel axis cs:0,0) {\includegraphics[width=2.0in]{example-image-a}};           
    \draw[black,->,thick] (rel axis cs:0.98,0.98) -- ++(-135:0.30in);
    \draw[black,-,thick,densely dashed]  (0,0) -- (0,0.3048);
    \node[draw=none,anchor=south west] at (rel axis cs:0,0) {\textsf{SansSerif Text}};
    \end{axis}
    \begin{axis}[xticklabels={},yticklabels={}]   
    %Empty axis for plotting ticks on top of contour
    \end{axis}

    \end{tikzpicture}

\end{document}

enter image description here

  • This is also a viable solution but would not work in this case. These figures are part of a larger document and, for consistency, needs to use the same font. There are slight differences between the TeX fonts and the fonts I used. – Kyle Jones May 25 '16 at 19:17
  • then replace \setsansfont{TeX Gyre Heros} with \setsansfont{Cabin} – user2478 May 25 '16 at 19:21
  • That's basically what Jason suggested in his answer. – Kyle Jones May 25 '16 at 19:28
  • yes, but he's using Type 1 math fonts instead of OpenType math – user2478 May 25 '16 at 19:30
  • Please don't use minimal for examples. – cfr May 25 '16 at 21:23

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.