# I tried to set both font family and font size for caption, using DeclareCpationFont in XeLaTeX

I made a lot of research ins this forum, readjusted and tried all commands, but setting both font family and font size together, using DeclareCaptionFont does not work.

1st code, by me:

\usepackage{caption}
\newfontfamily\cantarell{Cantarell}
\DeclareCaptionFont{cantarell}{\cantarell\fontsize{5}{7}}
\captionsetup{font=cantarell}


2nd alt, taken from https://tex.stackexchange.com/a/225025/172831:

\usepackage{caption}
\newfontfamily\cpfont{Cantarell}
\DeclareCaptionFormat{iosfont}{\cpfont\tiny}
\captionsetup{format=iosfont,labelfont=bf,margin={0cm,0cm},justification=centering,singlelinecheck=on}

• I want to set Cantarell or any font family
• I want to set 5px or 7px. The command tiny does not work, either.

You forgot to use \selectfont, but the simplest is to switch the size declaration and the font declaration.

\documentclass{article}
\usepackage{fontspec}
\usepackage{caption}

\newfontfamily\cantarell{Futura}% sorry, no Cantarell

\DeclareCaptionFont{cantarell}{\fontsize{5}{7}\cantarell}
\captionsetup{font=cantarell}

\begin{document}

\begin{figure}

some text in the standard font for comparison
some text in the standard font for comparison
some text in the standard font for comparison
some text in the standard font for comparison

\caption{some text in the caption font for comparison
some text in the caption font for comparison
some text in the caption font for comparison
some text in the caption font for comparison
some text in the caption font for comparison
some text in the caption font for comparison}

\end{figure}

\end{document}


Since I don't have easily accessible Cantarell fonts, I just used a very distinctive one I have on my machine.