[Tex/LaTex] How to change font in class diagrams by tikz-uml

tikz-uml

The doc of tikz-uml package says that the font size in diagrams could be changed by \tikzumlset{font=\footnotesize}, yet the font itself is not changed. I would like to change the font (in diagrams, not globally) from default style into mono style, say, monaco. Thanks!

BTW: I use XeLaTeX and \setmonofont{Monaco} to set global mono font.

Best Answer

Simply add the font family command (here, \ttfamily) to the value of the font key along with the size command \footnotesize:

\documentclass{standalone}
\usepackage{tikz-uml}
\tikzumlset{font=\footnotesize\ttfamily}

\begin{document}
\begin{tikzpicture}
\umlclass{Test}{n = 1;}{}
\end{tikzpicture}
\end{document}

enter image description here

This solution is independent of how you select a particular monospaced font, whether by fontspec or by standard methods. \ttfamily will use whichever fixed-width font is selected by the rest of the code.

The reference page LaTeX font commands lists all available font commands for LaTeX. See the "activated by" column in the table there. In general, font families can be selected using a switch command that remains in effect for the entire group (such as \ttfamily here), or using a macro with an argument (such as \texttt{<text>}). In your use case, we use the switch command since TikZ will place these commands inside a group with the node contents.

Related Question