[Tex/LaTex] change fontsize within tikzpicture

fontsizescrreprttikz-pgf

i made some tikzpicture and tested them outside of the main document cause then there's less compiling duration.

However i alway used \documentclass{article}.

I set the fonts with \begin{tikzpicture}[auto, font = {\sf \myfont}, thick].

For \myfont i used \newcommand{\myfont}{\footnotesize}.

After creating the tikzpicture i wanted to add the tikzpicture with \input{mytikzpicture.tex} in to my main document.

But somehow the change of the fontsize i set with \begin{tikzpicture}[auto, font = {\sf \myfont}, thick] has no effect now.

In my main document i set the font size using this code:

\documentclass[
    pdftex,
    a4paper,
    11pt,
    oneside,
    fleqn,
    listof=totoc,
    headlines=2.1,
    headsepline,
    numbers=noenddot,
    hyphens,
]{scrreprt}

What i already tried:

  • \tikzset{font={\fontsize{9pt}{12}\selectfont}}
    I wanted to use this to decrease the font size in a tikzpicture only. I got this solution from searching the internet (Change fontsize in TikZ figure). Unfortunately it had no effect on the fontsize in the tikzpicture at all.

  • changing the fontsize using kind of scoping (also no effect): found at
    this thread

    {\footnotesize % change the font size
      \begin{tikzpicture}[auto,  font = {\sf \myfont}, thick]
       ...
      \end{tikzpicture}
    } % end of scope of \footnotesize macro
    

What's the reason it doesn't work and what can i change?
If i didn't provide all necessary information to solve the problem feel free to tell me.

edit1:

here a minimum example of my problem.
the tex file i use for developing my tikzpictures:

\documentclass{article}
\usepackage{amsmath}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage{textgreek}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}


\newcommand{\myfont}{\footnotesize}
\tikzstyle{block} = [draw,
rounded corners]

\begin{document}

    \begin{tikzpicture}[auto,  font = {\myfont}, thick]
    % Hilfslinien
    \draw[help lines] (-5,-5) grid (5,5);
    \node[block, align=center] (isolation) {hello};
    \end{tikzpicture}

\end{document}

minimum example if i put my developed stuff into the main document:

\documentclass[
pdftex,
a4paper,
11pt,
oneside,
fleqn,
listof=totoc,
headlines=2.1,
headsepline,
numbers=noenddot,
hyphens,
]{scrreprt}
\usepackage{amsmath}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage{textgreek}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}




\newcommand{\myfont}{\footnotesize}
\tikzstyle{block} = [draw,
rounded corners]

\begin{document}

    \begin{tikzpicture}[auto,  font = {\myfont}, thick]
    % Hilfslinien
    \draw[help lines] (-5,-5) grid (5,5);


    \node[block, align=center] (isolation) {hello};
    \end{tikzpicture}

\end{document}

Outputs:
enter image description here
The left side shows the output of my 'devolopment' file. The right is the output of the main document.

As you can see if i put it into the main document the fonts are slightly bigger. This is enough to distort all my tikzpictures.
Thank in advance

Best Answer

The default font size for KOMA-Script classes is 11pt, but for standard classes it is 10pt.

Maybe you can change the font size for all tikzpictures to 10pt using

\usepackage{xpatch}
\xpretocmd\tikzpicture{\KOMAoptions{fontsize=10pt}}{}{\PatchFailed}

enter image description here

Code:

\documentclass[
  fontsize=11pt% 11pt is default for KOMA-Script classes
]{scrreprt}
\usepackage{tikz}
\newcommand{\myfont}{\sffamily\footnotesize}
\tikzset{block/.style = {draw,rounded corners}}

\usepackage{xpatch}
\xpretocmd\tikzpicture{\KOMAoptions{fontsize=10pt}}{}{\PatchFailed}

\begin{document}
\begin{tikzpicture}[auto,font = {\myfont}, thick]
% help lines
\draw[help lines,lightgray!50] (-5,-5) grid[step=2mm] (5,5);
\draw[help lines] (-5,-5) grid (5,5);

\node[block] (isolation) {hello};
\end{tikzpicture}
\end{document}

Example with article:

\documentclass{article}% default font size is 10pt
\usepackage{tikz}
\newcommand{\myfont}{\sffamily\footnotesize}
\tikzset{block/.style = {draw,rounded corners}}

\begin{document}
\begin{tikzpicture}[auto,font = {\myfont}, thick]
% help lines
\draw[help lines,lightgray!50] (-5,-5) grid[step=2mm] (5,5);
\draw[help lines] (-5,-5) grid (5,5);

\node[block] (isolation) {hello};
\end{tikzpicture}
\end{document}

Result:enter image description here