[Tex/LaTex] Adjusting text size in Tikz

fontsizetikz-pgf

I want to adjust my text size in the following code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{plotmarks}

\begin{document}
\tikzset{fontsize=20}
\begin{tikzpicture}
\draw (20pt,20pt) rectangle ++(100pt,100pt);
\filldraw (70pt,70pt) circle (3pt);
\draw (20pt,20pt)--(120pt,120pt);
\node(text) at (10pt,70pt) {$\theta_1$};
\node(text) at (70pt,10pt) {$\theta_2$};
\end{tikzpicture}

\end{document}

I couldn't find anything by searching.

Best Answer

Instead of repeating font size operations in the code of each node, I recommend defining a style. Either globally, via \tikzset, or locally, as option to the tikzpicturefor example. I would never change font sizes within the text. Also in classic LaTeX documents, sizes should be set via macros defined in the preamble, for consistency and allowing changes.

You can inherit and combine styles, to further avoid repeating and to keep things consistent.

\tikzset{%
  bignode/.style     = {font=\fontsize{20}{22.4}\selectfont},
  mathnode/.style    = {execute at begin node=$,
                        execute at end node=$},
  bigmathnode/.style = {bignode, mathnode}}
 ...
\node [bigmathnode] (text) at (10pt,70pt) {\theta_1};
\node [bigmathnode] (text) at (70pt,10pt) {\theta_1};