10

I am using pgf/tikz graphics and I'm wondering how one can control the scaling of font sizes in the graphics when using them in minipage/subfig environments?

Is there a way to manually set a permanent font size for pgf/tikz graphics or in latex in general so as to make font sizing invariant to scaling?

Ideally I'd like to be able to manually specify a font size per graphic or for all graphics or subfig/minipage environments?

Here is an example of the usage as suggested. Thanks for the help.

\begin{figure}[h]
\centering
\subfloat[Graph 1]{
    \begin{minipage}[h]{0.7\linewidth}
        \centering\beginpgfgraphicnamed{graph1}
        \input{graph1.tex}
        \endpgfgraphicnamed
        \label{fig:graph1}
    \end{minipage}}
\hspace{5pt}
\subfloat[Graph 2]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering\beginpgfgraphicnamed{graph2}
        \input{graph2.tex}
        \endpgfgraphicnamed
        \label{fig:graph2}
    \end{minipage}}
\subfloat[Graph 3]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering\beginpgfgraphicnamed{graph3}
        \input{graph3.tex}
        \endpgfgraphicnamed
        \label{fig:graph3}
    \end{minipage}}
\caption{Three Graphs}
\end{figure}

Perhaps outside of minipage/subfig I can use the suggestions from the other posting to make the font large since the graphic is scaled with the page width? What I was going for in the example was the first image on it's own, larger, and then two smallimages right below side by side with their own captions in one figure.

I saw some R tags in your profile Mica. The graphics are generated using tikzDevice and are picked up in my latex doc.

So I'm generating the files without the tikzpicture environment so that I can manually set options there myself. When I use the \begin{tikzpicture} \end{tikzpicture} I get the error "Dimension too large I can't work with sizes bigger than about 19 feet. Continue and I'll use the largest value I can.". I need to use \beginpgfgraphicnamed{} .. \endpgfgraphicnamed{} to get it to work? Not sure what the impact is exactly.

Here is a sample of the auto-generated file:

\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}

........

\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{fillColor}{rgb}{1.00,1.00,1.00}

\draw[fill=fillColor,draw opacity=0.00,] (  0.00,  0.00) rectangle (794.97,614.29);
\end{scope}

........

\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}

\node[rotate= 90.00,color=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 15.92,310.59) {Mackenzie Net Sales};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}

Hopefully that is helpful, over all the file is ~1,000 lines so I tried to cut out a representation of the unique bits. Please let me know if you need anything else.

Many thanks,

Jay

Jay
  • 2,917
  • 3
  • 18
  • 13
  • the actual code would still be useful. why are you scaling a tikz/pgf drawing? why not just draw it to the proper size? – Mica Feb 10 '10 at 23:21

1 Answers1

16

I am not exactly sure what your aim is. To change the font size or the size of the Rest of the picture? There are multiple possibilities to reach any of these:

My example box with a 1cm x 1cm large box:

\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

Scale the graphical elements, but NOT the text:

\begin{tikzpicture}[scale=0.5]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

\begin{tikzpicture}[scale=0.5]
    \draw (0,0) rectangle (1cm,1cm) -- +(-1,-1);
    \node(text) at (0.5cm,0.5cm) {Text};
\end{tikzpicture}

Scale the coordinates only (That is, if no unit is specified, it used multiplies of the specified x, y and z vector):

\begin{tikzpicture}[x=5mm,y=5mm]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

Explicit lengths are not changed with this:

\begin{tikzpicture}[x=5mm,y=5mm]
    \draw (0,0) rectangle (1cm,1cm) -- +(-1cm,-1cm);
    \node(text) at (0.5cm,0.5cm) {Text};
\end{tikzpicture}

Scale everything, even the text (according to the pgfmanual, this is not recommended):

\begin{tikzpicture}[transform canvas={scale=0.5}]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

Same effect using LaTeX commands:

\scalebox{0.5}{
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}
}

Change the font size locally, but the size of graphical elements are not changed:

\begin{tikzpicture}[font=\scriptsize]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

Change the font size in all subsequent tikzpicture environments (\tikzset can be used to set the options above, too):

\tikzset{font=\scriptsize}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

\tikzset remains local in groups:

\begin{minipage}{\linewidth}
\tikzset{font=\scriptsize}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}
\end{minipage}

{
\tikzset{font=\scriptsize}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}
}

\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

I don't know whether you can edit the files graph?.tex, or are these generated? Maybe you can pass options to the program that generates the tikzpicture environment. Otherwise, just set the desired option in your desired scope using \tikzset.

Hope, that helps.

EDIT: If the options (like font=) are defined locally in the graph?.tex, then these get precedence over the options defined outside. If this is the case, you just can't overwrite them from the outside. You'd have to edit the files.

EDIT: This "minimal" example works for me (showing a really big "Mackenzie Net Sales" that exceeds the subfigure's width)

\documentclass{article}

\usepackage{fix-cm}
\usepackage{subfig}
\usepackage{tikz}

\begin{document}
\tikzset{every picture/.append style={font=\fontsize{100}{120}\selectfont}}

\begin{figure}[h]
\centering
\subfloat[Graph 1]{
    \begin{minipage}[h]{0.7\linewidth}
        \centering\beginpgfgraphicnamed{graph1}
%        \input{graph1.tex}
        \endpgfgraphicnamed
        \label{fig:graph1}
    \end{minipage}}
\hspace{5pt}
\subfloat[Graph 2]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering 
        \resizebox{\textwidth}{!}{

            %\beginpgfgraphicnamed{graph2}  
\begin{tikzpicture}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{fillColor}{rgb}{1.00,1.00,1.00}
\draw[fill=fillColor,draw opacity=0.00,] (  0.00,  0.00) rectangle (79.497,61.429);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
\node[rotate= 90.00,color=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 1.592,31.059) {Mackenzie Net Sales};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\end{tikzpicture}
}
        %\endpgfgraphicnamed

        \label{fig:graph2}
    \end{minipage}}
\subfloat[Graph 3]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering\beginpgfgraphicnamed{graph3}
%        \input{graph3.tex}
        \endpgfgraphicnamed
        \label{fig:graph3}
    \end{minipage}}
\caption{Three Graphs}
\end{figure}

\end{document}

Please test whether this works for you, too. If it does, then try to modify this one until it doesn't work any more. What's the breaking change?

Meinersbur
  • 7,881
  • 1
  • 27
  • 29
  • Thanks for all the information Meinersbur, that's great. There are some options which can be controlled such as I can create the files so that I manually specify the tikzpicture environment but this throws an error "Dimension too large I can't work with sizes bigger than about 19 feet.". – Jay Feb 11 '10 at 15:01
  • It would be preferable to not edit internal parts of the auto generated graphic files. There are no "font=" in the files but setting \tikzset{font=\scriptsize} doesn't seem to have an effect? – Jay Feb 11 '10 at 15:02
  • My aim is to have the font size 10p lets say for arugment, regardless of how hte tikz graphic is recaled (subfig, minipage, ...). Specifically in the setup I posted the font is larger in the top graphic and small (and unreadable) in the side-by-side lower graphics... – Jay Feb 11 '10 at 15:03
  • 1
    It would be helpful if you could post such an `input?.tex` file. Possibly you can set the size using styles. – Meinersbur Feb 11 '10 at 15:47
  • 1
    try `\tikzset{every picture/.append style={font=\scriptsize}}` does this work? – Meinersbur Feb 11 '10 at 15:49
  • I will try your example now. I don't think I can attach anything here? They are quite long so in the post won't work. Any ideas? I'm happy to send one, thank you very much for your help. – Jay Feb 11 '10 at 16:01
  • 1
    It doesn't need to be the complete file. Since it is generated, a lot of things is just a repetition of snippets. Just show an excerpt of the most important parts (including the beginning). – Meinersbur Feb 11 '10 at 17:01
  • No effect from the second \tikzset option, posting code in the question now – Jay Feb 11 '10 at 19:42
  • 1
    How did you manage to typeset that? I just get "dimension too large". However, after dividing all coordinates by 10, it worked. – Meinersbur Feb 12 '10 at 01:09
  • 1
    And actually after that, everything worked fine for me, including the resizes; ...but did you delete/regenerate the `graph?.pdf` so the image is updated? If you updated them, remember that everything outside `\beginpgfgraphicnamed` and `\endpgfgraphicnamed` is ignored, including `\tikzset`-commands. Try to comment out `\beginpgfgraphicnamed` and `\endpgfgraphicnamed`. – Meinersbur Feb 12 '10 at 01:16
  • Not sure? Could somethink else in the doc be doing that? How did you divide all the coordinates? I have tried \tikzset inside there with no effect? – Jay Feb 12 '10 at 14:23
  • They are static files generated outside the latex file. Let me give it a try again and I'll report back. Thank you! – Jay Feb 12 '10 at 14:25
  • 1
    I moved the dot one digit to left (that is, I did it manually) – Meinersbur Feb 12 '10 at 14:53
  • I still have to try a few things, maybe there is a place I can post the whole file so you can give it a try? Are you trying them when they are scaled in some way y the document itself? – Jay Feb 14 '10 at 15:13
  • Upload it at some one-click hoster (ex. rapidshare.com) and post the link. – Meinersbur Feb 14 '10 at 16:16
  • 3
    A little late to the party, but the "dimension too large" errors are due to TikZ defaulting to units of 1cm for coordianates while tikzDevice output assumes 1pt. To fix things without doing any crazy division, use `\begin{tikzpicture}[x=1pt, y=1pt]` or `\begin{scope}[x=1pt, y=1pt]` whenever handling tikzDevice output. – Sharpie May 04 '11 at 20:53