How to control font sizes in pgf/tikz graphics in latex?

128,615

Solution 1

\begin{tikzpicture}

    \tikzstyle{every node}=[font=\small]

\end{tikzpicture}

will give you font size control on every node.

Solution 2

I found the better control would be using scalefnt package:

\usepackage{scalefnt}
...
{\scalefont{0.5}
\begin{tikzpicture}
...
\end{tikzpicture}
}

Solution 3

I believe Mica's way deserves the rank of answer, since is not visible enough as a comment:

\begin{tikzpicture}[font=\small]

Solution 4

\begin{tikzpicture}
    \tikzstyle{every node}=[font=\fontsize{30}{30}\selectfont]
\end{tikzpicture}

Solution 5

You can also use:

\usepackage{anyfontsize}

The huge advantage of the anyfontsize package over scalefnt is that one does not need to enclose the entire {tikzpicture} within a \scalefont environment.

Just adding \usepackage{anyfontsize} to the preamble is all that is required for the font scaling magic to happen.

Share:
128,615
Jay
Author by

Jay

Updated on July 05, 2022

Comments

  • Jay
    Jay almost 2 years

    I'm creating graphs in pgf/tikz. When I use these in my document they are scaled, several are in minipage/subfig like environments. When this happens the font sizes are scaled with the graphics making them very small or unreadable. I've been through the manual but have so far been unsuccessful in my attempts to control this.

    Is there a way to set the font size directly? What options are there?

    One aswer given below shows how to how to use the \tikzstyle font option to specify the font size within the tikzpicture environment.

    Right now I am using:

    \beginppgfgraphicnamed{graph}
    \input{graph.tex}
    \endpgfgraphicnamed
    

    The tikzpicture environment is used in the input file. Are there anyways to specify font size in the setup I'm using? Is this perhaps the issue? The graph.tex file is generated automatically via another program.

    In addition to setting font size for individual graphics it would be ideal to have a parameter to globally set font size for all tikz graphics? I guess the issue is the scaling in minipage or subfig.

    Many thanks,

    Jay

  • Jay
    Jay over 14 years
    Thanks for the quick answer. I have my \input{graph.tex} enclosed in \beginpgfgraphicnamed{graph} ... \endpgfgraphicnamed as when I use the tikzpicture environment as you did above a get an error about the size being exeeded. When I place the tikzstyle command in there it doesn't seem to have an affect?
  • Jay
    Jay over 14 years
    I'm using another tool to convert my graphics to pgf...I just looked at the file more closely and the \begin\end {tikzpicture} is used in my input file.
  • Jay
    Jay over 14 years
    I changed the output aroudn so that I could manually specify the tikzpicture environment. It give hte the error "Dimension too large I can't work with sizes bigger than about 19 feet." and fails to compile with trying it with \small as above.
  • Mica
    Mica over 14 years
    It would be useful if you posted the code that is giving your problems.
  • Mica
    Mica over 14 years
    you may also want to try: \begin{tikzpicture}[font=\small]
  • Martin Thoma
    Martin Thoma almost 12 years
    Also interesting: font=\tiny, font=\scriptsize
  • chinnychinchin
    chinnychinchin almost 6 years
    Thank you, a useful solution! Very valuable, since it is independent of changing the actual tikzpicture contents.
  • bitmask
    bitmask over 5 years
    This is the only thing that works on a text along path if you need the font to be very large.
  • Tomasz Gandor
    Tomasz Gandor almost 3 years
    I think you need to use a package for that.
  • Tomasz Gandor
    Tomasz Gandor almost 3 years
    You could demonstrate this magic. (I think it's in Gavin Gao's answer)