[Tex/LaTex] Set font size for multi line tikz node

tikz-pgf

When I try to set the font size for a tikz node that contains a line break ("\\ ") the font size is only set for the first line:

\documentclass{article}
\usepackage{tikz}
\usepackage{fontspec}
\setmainfont{Arial}

\begin{document}
    \begin{tikzpicture}
        \begin{scope}
            \node[align=left] at (0,0) {\fontsize{5pt}{5pt}\selectfont first line\\ second line};
        \end{scope}
    \end{tikzpicture}
\end{document}

example

How can I set the font size for the whole node?

Best Answer

Use font=\fontsize{5pt}{5pt}\selectfont in the node options.

output of code

\documentclass{article}
\usepackage{tikz}
%\usepackage{fontspec} %commented because it's not really relevant
%\setmainfont{Arial}

\begin{document}
    \begin{tikzpicture}
        \begin{scope}
            \node[align=left,font=\fontsize{5pt}{5pt}\selectfont] at (0,0) {first line\\ second line};
        \end{scope}
    \end{tikzpicture}
\end{document}