1

I want all the text in a tikzpicture environment to be sans serif by using a every node/.style={font=\sffamily} command:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{backgrounds,fit,decorations.pathreplacing,calligraphy}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[inner sep = 0pt,
every node/.style={font=\sffamily}]

\node[regular polygon, regular polygon sides=6, draw, inner sep=1.2cm, shape border rotate=30] (q) at (0,0) {};
\node at (q.corner 1) (q1) {}; 
\node at (q.corner 4) (q4) {}; 
\node[font=\small,fill=white,align=center,minimum size=1.4cm,shift={(-.2,0)}] at (q.east) {subset \\ 2};

\node[regular polygon, regular polygon sides=6, draw, inner sep=2cm, shape border rotate=30] (p) at (0,0) {};
\node at (p.corner 1) (p1) {}; \node at (p.corner 2) (p2) {};
\node at (p.corner 3) (p3) {}; \node at (p.corner 4) (p4) {}; 
\node at (p.corner 5) (p5) {}; \node at (p.corner 6) (p6) {};

\draw (p2) -- (p5); \draw (p3) -- (p6);
\draw (p1) -- (q1); \draw (p4) -- (q4);

\node[circle,fill=white,draw=black,align=center,minimum size=.5cm] at (p1) {1}; 
\node[circle,fill=none,align=center,above] at (p1) {category 1};
\node[circle,fill=none,align=center,left] at (p3) {category 2};

\end{tikzpicture}

\end{document}

But not all parts of the resulting figure use sans serif font. Why does this happen and what do I need to add? (I want to use sffamily for just this tikzpicture environment in my report, so I can't do this)

enter image description here

1
  • The value font=\sffamily gets overwritten with font=\small. A straight-forward way would be to place \sffamily before the tikzpicture (and wrap everything in a group). Nov 14, 2022 at 20:48

1 Answer 1

4

You set font=\sffamily for the tikzpicture, but later you overwrite this value using font=\small. You can use the option execute at begin node to execute arbitrary code at the beginning of the node, such as

every node/.style={execute at begin node={\sffamily}}

Use this instead of every node/.style={font=\sffamily} and you should be fine:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}[inner sep=0pt, every node/.style={execute at begin node={\sffamily}}]

\node[regular polygon, regular polygon sides=6, draw, inner sep=1.2cm, shape border rotate=30] (q) at (0,0) {};
\node at (q.corner 1) (q1) {}; 
\node at (q.corner 4) (q4) {}; 
\node[font=\small, fill=white, align=center, minimum size=1.4cm, shift={(-.2,0)}] at (q.east) {subset \\ 2};

\node[regular polygon, regular polygon sides=6, draw, inner sep=2cm, shape border rotate=30] (p) at (0,0) {};
\node at (p.corner 1) (p1) {}; \node at (p.corner 2) (p2) {};
\node at (p.corner 3) (p3) {}; \node at (p.corner 4) (p4) {}; 
\node at (p.corner 5) (p5) {}; \node at (p.corner 6) (p6) {};

\draw (p2) -- (p5); \draw (p3) -- (p6);
\draw (p1) -- (q1); \draw (p4) -- (q4);

\node[circle, fill=white, draw=black, align=center, minimum size=.5cm] at (p1) {1}; 
\node[circle, fill=none, align=center, above] at (p1) {category 1};
\node[circle, fill=none, align=center, left] at (p3) {category 2};

\end{tikzpicture}
\end{document}

enter image description here

Of course, you could also just select \sffamily for the whole tikzpicture using {\sffamily\begin{tikzpicture} ... \end{tikzpicture}}.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .