views:

939

answers:

1

Hi,

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

+3  A: 

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
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
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
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
It would be helpful if you could post such an `input?.tex` file. Possibly you can set the size using styles.
Meinersbur
try `\tikzset{every picture/.append style={font=\scriptsize}}`does this work?
Meinersbur
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
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
No effect from the second \tikzset option, posting code in the question now
Jay
How did you manage to typeset that? I just get "dimension too large". However, after dividing all coordinates by 10, it worked.
Meinersbur
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
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
They are static files generated outside the latex file. Let me give it a try again and I'll report back. Thank you!
Jay
I moved the dot one digit to left (that is, I did it manually)
Meinersbur
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
Upload it at some one-click hoster (ex. rapidshare.com) and post the link.
Meinersbur