6

I usually embed numerous R plots in my TeX documents. knitr is very handy in helping me producing plots using the same font family of the TeX document. But a different problem of consistency is given by the font size: still I haven't found a way to maintain the same font size independently from the size of the containing box. For instance I might have a plot that extends horizontally over 90 percent of the paper width and then another that will only extends over 45 percent; usually this will result in plots with different font sizes. I can of course go back to the R script and tweak the size values until I get the right size but I wonder if there's a smarter solution to set the font size of the plots for the whole document without modifying the plots' source scripts.

3

1 Answer 1

3

Have you considered the tikzDevice-Package for R?

It lets you create *.tex files to import into latex like this:

library(tikzDevice)

options(tikzMetricPackages = c("\\usepackage[utf8]{inputenc}", 
                               "\\usepackage{amssymb,amsmath,amsfonts}"))
tikz("your directory/graph.tex", width=3,height=3)
plot(runif(10))
legend("topright","this text should not scale")
dev.off()

Then you can input it in your latex-code, using the package "tikz", where you can use \tikzset to scale the picture. The fontsize stays the same.

\usepackage{tikz}

\begin{figure}
   \centering
   \tikzset{every picture/.append style={scale=0.4}}
    \include{graph}
     \caption{a nice graph}
     \label{graph}
   \end{figure}

`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .