Text Formatting ⇒ math text in caption in sf font - how to do it?
math text in caption in sf font - how to do it?
Hi all.
I have captions in sf font. In some, there is some math text. But the math text renders the same way as all math texts in equations.
Is there a way to tell the math texts that are inside a caption to render in mathsf in an automatic way?
Thanks
I have captions in sf font. In some, there is some math text. But the math text renders the same way as all math texts in equations.
Is there a way to tell the math texts that are inside a caption to render in mathsf in an automatic way?
Thanks
NEW: TikZ book now 40% off at Amazon.com for a short time.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
math text in caption in sf font - how to do it?
I think there is a better way to set captions optically apart from the normal text.
This looks nice and wouldn't cause any issues with math expressions in captions.
Best regards and welcome to the board
Thorsten¹
Code: Select all
\usepackage[font=small,labelfont=bf]{caption}
Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: math text in caption in sf font - how to do it?
I've been willing to use sans-serifs captions for long time, well more than willing to use, kind of willing to know how to do it. If I recall correctly, I read somewhere that once math fonts are declared they're fixed for the rest of the document. I don't know it for sure, but I'm sure there are people in here who can tell us easily if this is correct or not.
If that's true, one solution could be to write code which first writes the caption to an external file, then processes that file with the desired options, and finally includes the output as a pdf or eps. Kind of how the examples where created in The LaTeX Companion book -- if I understood well the making process. I'm far from knowing how to do that, but there are real experts around here who might give us some useful hints.
If that's true, one solution could be to write code which first writes the caption to an external file, then processes that file with the desired options, and finally includes the output as a pdf or eps. Kind of how the examples where created in The LaTeX Companion book -- if I understood well the making process. I'm far from knowing how to do that, but there are real experts around here who might give us some useful hints.
math text in caption in sf font - how to do it?
It is possible, but very involved, to change the family automatically according to the text font family.
It is easier to declare a new math version. Here is an example using the Computer Modern fonts. Note that you get a warning because the sans-serif font doesn't use the correct encoding. Thus it is better to use the CM-Bright fonts. The following code shows both possibilities:
It is easier to declare a new math version. Here is an example using the Computer Modern fonts. Note that you get a warning because the sans-serif font doesn't use the correct encoding. Thus it is better to use the CM-Bright fonts. The following code shows both possibilities:
Code: Select all
\documentclass{article}
\DeclareMathVersion{sans}
\SetSymbolFont{operators}{sans}{OT1}{cmss}{m}{n}
\SetSymbolFont{letters}{sans}{OT1}{cmss}{m}{sl}
\SetMathAlphabet\mathbf{sans}{OT1}{cmss}{bx}{n}
\SetMathAlphabet\mathsf{sans}{OT1}{cmss}{m}{n}
\SetMathAlphabet\mathit{sans}{OT1}{cmss}{m}{sl}
\DeclareMathVersion{sansbright}
\SetSymbolFont{operators}{sansbright}{OT1}{cmbr}{m}{n}
\SetSymbolFont{letters}{sansbright}{OML}{cmbrm}{m}{it}
\SetSymbolFont{symbols}{sansbright}{OMS}{cmbrs}{m}{n}
\SetMathAlphabet\mathbf{sansbright}{OT1}{cmbr}{bx}{n}
\SetMathAlphabet\mathsf{sansbright}{OT1}{cmbr}{m}{n}
\SetMathAlphabet\mathit{sansbright}{OT1}{cmbr}{m}{it}
\SetMathAlphabet\mathtt{sansbright}{OT1}{cmtl}{m}{n}
\begin{document}
\tableofcontents
\section{\sffamily\mathversion{sans}abc $a^2 + b^2 = c^2 \sum \prod \int$}
\section{\sffamily\mathversion{sansbright}abc $a^2 + b^2 = c^2 \sum \prod \int$}
\end{document}
Re: math text in caption in sf font - how to do it?
That was awesome phi, love it!
I won't use it right now, but I'll save this thread as reference for the future. Thanks! 



math text in caption in sf font - how to do it?
An alternative solution:
Regards,
Axel
Code: Select all
\documentclass{article}
\usepackage{caption,sansmath}
\DeclareCaptionFont{sansmath}{\sansmath}
\captionsetup{textfont={sf,sansmath}}
\begin{document}
\begin{figure}
\caption{Some text and a formular: $E = mc^2$}
\end{figure}
\end{document}
Axel
math text in caption in sf font - how to do it?
Axel, this is not an alternative solution. This is THE solution. Thanks a lot.sommerfee wrote:An alternative solution:
...
Regards,
Axel
Ondra