Patrick Drechsler
2005-Jan-06 22:56 UTC
[R] autoscaling plot font size in Sweave output possible?
Hi, I was wondering if it's possible to have fonts in plots to be autoscaled to the same font size used by LaTeX in a surrounding Sweave document. Here's a short example in which the fonts of the first plot are barely readable: --8<------------------------schnipp------------------------->8--- \documentclass{article} \usepackage{graphicx} \newcommand{\mytext}{Some normal sized text. Some normal sized text. Some normal sized text. Some normal sized text.} \begin{document} \SweaveOpts{prefix.string=pics/miniexample} \mytext\par %% small plot: \setkeys{Gin}{width=.45\linewidth} @ <<test0,echo=F,fig=T>>x <- 1:10 y <- sin(x) plot(x,y, xlab="some x label", ylab="some y label" ) @ %def \par\mytext \mytext %% normal sized plot: \setkeys{Gin}{width=.9\linewidth} @ <<test1,echo=F,fig=T>>plot(x,y, xlab="some x label", ylab="some y label" ) @ %def \par\mytext \end{document} --8<------------------------schnapp------------------------->8--- Do I have to tweak the font size manually (as dicussed f.ex. in [1] a while back) or is there a more general way to avoid this problem? Thankful for any pointers, Patrick ,----[ R version: ] | platform i686-pc-linux-gnu | arch i686 | os linux-gnu | system i686, linux-gnu | status | major 2 | minor 0.0 | year 2004 | month 10 | day 04 | language R `---- Footnotes: [1] <URL:http://thread.gmane.org/gmane.comp.lang.r.general/20304> -- Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon. -- Susan Ertz
Uwe Ligges
2005-Jan-07 08:16 UTC
[R] autoscaling plot font size in Sweave output possible?
Patrick Drechsler wrote:> Hi, > > I was wondering if it's possible to have fonts in plots to be > autoscaled to the same font size used by LaTeX in a surrounding > Sweave document.See ?strwidth which might help for the required calculations. Uwe Ligges> Here's a short example in which the fonts of the first plot are > barely readable: > > --8<------------------------schnipp------------------------->8--- > \documentclass{article} > \usepackage{graphicx} > > \newcommand{\mytext}{Some normal sized text. Some normal sized > text. Some normal sized text. Some normal sized text.} > > \begin{document} > \SweaveOpts{prefix.string=pics/miniexample} > > \mytext\par > > %% small plot: > \setkeys{Gin}{width=.45\linewidth} > @ > <<test0,echo=F,fig=T>>> x <- 1:10 > y <- sin(x) > plot(x,y, > xlab="some x label", > ylab="some y label" > ) > @ %def > > \par\mytext \mytext > > %% normal sized plot: > \setkeys{Gin}{width=.9\linewidth} > @ > <<test1,echo=F,fig=T>>> plot(x,y, > xlab="some x label", > ylab="some y label" > ) > @ %def > > \par\mytext > > \end{document} > --8<------------------------schnapp------------------------->8--- > > Do I have to tweak the font size manually (as dicussed f.ex. in > [1] a while back) or is there a more general way to avoid this > problem? > > Thankful for any pointers, > > Patrick > > ,----[ R version: ] > | platform i686-pc-linux-gnu > | arch i686 > | os linux-gnu > | system i686, linux-gnu > | status > | major 2 > | minor 0.0 > | year 2004 > | month 10 > | day 04 > | language R > `---- > > > Footnotes: > [1] <URL:http://thread.gmane.org/gmane.comp.lang.r.general/20304> >
Friedrich.Leisch@tuwien.ac.at
2005-Jan-07 08:49 UTC
[R] autoscaling plot font size in Sweave output possible?
>>>>> On Thu, 06 Jan 2005 23:56:31 +0100, >>>>> Patrick Drechsler (PD) wrote:> Hi, > I was wondering if it's possible to have fonts in plots to be > autoscaled to the same font size used by LaTeX in a surrounding > Sweave document. Not using the standard mechanism, because there figures are rescaled *after* they are created, and the font is rescaled together with the rest. What yoy have to do is: 1) Create your own Sweave.sty file, say MySweave.sty which is a copy of the ofiginal one *without* the \setkeys{Gin} line and insert a \usepackage{MySweave} in the .Rnw document. 2) Explicitly set height and width of each figure chunk to what it should be in the final document. Unfortunately you cannot use any fractions of \textwidth or the like because Sweawe has no means to know what that might be. 3) Set the font size to what you use in the tex document using ps.options(). It is because of 2) that I didn't follow this route for the current defaults, and I haven't found a really convincing alternative which works in "most" situations ... Hth, Fritz -- ------------------------------------------------------------------- Friedrich Leisch Institut f?r Statistik Tel: (+43 1) 58801 10715 Technische Universit?t Wien Fax: (+43 1) 58801 10798 Wiedner Hauptstra?e 8-10/1071 A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch