0

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

  • Please post a compilable document, not disrupted pieces of code – user31729 Oct 8 '17 at 22:01
  • @ChristianHupfer done. see the edit. best regards – himynameis Oct 8 '17 at 22:49
  • in main document you use 11pt font size, but in file, in which you develop your picture, you use default font size, which is 10 pt. – Zarko Oct 8 '17 at 23:05
2

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

| improve this answer | |
  • Thank you. I seems to work in the minimum examples. Do i need to to set \xpretocmd\tikzpicture{\KOMAoptions{fontsize=10pt}}{}{\PatchFailed}in front of every tikzpicture or only once in a header-file, where i include all my usepackages? – himynameis Oct 9 '17 at 8:40
  • You have to set it only once in header. It affects all tikzpicture environments. – esdd Oct 9 '17 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.