When creating graphics or graphs with TikZ and/or pgfplots, one can put several commands to format the text to his likings.
My question is: what are sound possibilities to format the elements in said graphics created with TikZ or pgfplots?
I an old project of mine I manually edited every single character in any math expression in the graphics/graphs to make it sans serif which was quite tiresome. So I am wondering: maybe there are more clever ways to do it? Maybe there are less elaborate format decisions?
MWE picture
MWE code
\documentclass[
a4paper
]{scrartcl}
\usepackage{
newtxtext,
tikz,
amsmath,
subcaption,
capt-of
}
\usepackage[T1]{fontenc}
\begin{document}
\begin{center}
\begin{minipage}{0.3\textwidth}
\begin{tikzpicture}[font=\sffamily\small]
%
\draw[thick] (0,0) rectangle (25mm, 50mm) node[below,xshift=-12.5mm] {All sans.};
%
\filldraw[thick, fill=black] (12.5mm,25mm) coordinate (A) circle (2pt) node[below right=2pt] {A} node[above=10pt, text width=2cm] {Some more text which is needed!};
%
%x
\draw[thick, ->] (A) -- ++(2,0) node[right=2pt] {\(\text{F}_{\text{x}}\)};
%z
\draw[thick, ->] (A) -- ++(0,-1.5) node[below=2pt] {\(\text{F}_{\text{y}}\)};
\end{tikzpicture}
\captionof{figure}{Text Text word.}
\end{minipage}
\hfill
\begin{minipage}{0.3\textwidth}
\begin{tikzpicture}[font=\small]
%
\draw[thick] (0,0) rectangle (25mm, 50mm) node[below,xshift=-12.5mm] {All serif.};
%
\filldraw[thick, fill=black] (12.5mm,25mm) coordinate (A) circle (2pt) node[below right=2pt] {A} node[above=10pt, text width=2cm] {Some more text which is needed!};
%
%x
\draw[thick, ->] (A) -- ++(2,0) node[right=2pt] {\(\text{F}_{\text{x}}\)};
%z
\draw[thick, ->] (A) -- ++(0,-1.5) node[below=2pt] {\(\text{F}_{\text{y}}\)};
\end{tikzpicture}
\captionof{figure}{And yet another.}
\end{minipage}
\hfill
\begin{minipage}{0.3\textwidth}
\begin{tikzpicture}[font=\small]
%
\draw[thick] (0,0) rectangle (25mm, 50mm) node[below,xshift=-12.5mm] {All serif.};
%
\filldraw[thick, fill=black] (12.5mm,25mm) coordinate (A) circle (2pt) node[below right=2pt] {A} node[above=10pt, text width=2cm] {Some more text which is needed!};
%
%x
\draw[thick, ->] (A) -- ++(2,0) node[right=2pt] {\(F_{x}\)};
%z
\draw[thick, ->] (A) -- ++(0,-1.5) node[below=2pt] {\(F_{y}\)};
\end{tikzpicture}
\captionof{figure}{Word word text.}
\end{minipage}
\end{center}
\end{document}
Best Answer
You mentioned that you hand-edited all math to sans text. I don't recommend doing this: it violates the separation of
church and statecontent and style.1 If you want/need sans-serif math, use a sans-serif math font. They are few, far between, and somewhat limited in terms of glyphs/symbols, but they do exist. For simplicity, I have usedsansmath
here, but better options do exist in some cases. See the answers of these questions for examples of some possibilities:The "right answer" here depends on your field. You can refer to a discussion in our chat where some thoughts on this topic were shared. Some fields typically present all text and maths in figures matching the serif body text/maths fonts, while others use sans-serif for text in figures while maths fonts are the same as those in the body text. Still others recommend everything (text and maths) to be sans-serif in figures.
The last option is the most dubious in my opinion, because the same equation will look different depending on if it's presented in a figure or in the body. Furthermore, the typeface used for a particular math symbol is overloaded to impart certain meanings to the mathematics. This can be confusing if it changes through the document and might conflict with some convention used to impart meaning.
In any case, which style is "right" for your document, as I said, depends on your field. Look at high-quality, respected journals and books in your area to determine the best choice.
The styling can be done in a way that it can be easily changed later to reflect changing preferences on the part of the author or requirements of working with a new publisher, for example. Here is a simple way to do this:
This was a bit of a toy example just to quickly show the options.
For a real document, I'd set it up using a package like
floatrow
to make it easy to change for the whole document in the future. For example:Or, to add sans-serif math without changing the document body's source one bit:
Just for completeness, here's one with a
pgfplots
axis
environment:TL;DR
So, the bottom line: whatever style you decide is best for your work/field, implement it in a way that separates content from style. This way, you can be flexible if you change your mind or need to work with a person/publisher with different ideas about the style sometime in the future.
The
floatrow
package provides good ways to make this a reality, or you can roll your own patches of the environments if you can't usefloatrow
for some reason. Also note that some classes may provide this capability built-in. If this is the case, use the classes built-in facilities for better compatibility. In the case of the KOMA-Script classes, no built-in facility is provided, butfloatrow
is modified for compatibility with some other tools provided by the class. So styling the floats withfloatrow
still works as expected:1 Yes, I know, we all do it sometimes (me too), but this example is particularly extreme and the impact in one document is enormous.