# Bounding box on plotting files inserted into a LaTeX document

 Classic List Threaded
3 messages
Reply | Threaded
Open this post in threaded view
|

## Bounding box on plotting files inserted into a LaTeX document

 I'm trying to write basic latex code to insert a pdf graphic into a document.  I can use Rstudio to knit an Rmd file successfully inserting the plot into the document.  I can get the latex code if the "save tex" box is ticked, so I get the correct syntax used.   I don't need all the fancy things that .Rmd files can handle.  I just want a simple .tex file.  However, if I try to use a pdf file normally produced by using the pdf device, I get a message about a missing bounding box.  So I thought it might work to use R to make an eps file, which pdflatex automatically converts to a pdf.  It does import the graphic, but it takes up a whole page, which indicates that it ignores the bounding box. What does work is to use Rstudio interactively to export the graphic to a pdf file which pdflatex handles correctly.  But that's a clunky procedure which I'd like to avoid.  It must be possible since graphs were included in LaTeX documents for decades before there was Rstudio. TIA -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.      ___    Patrick Connolly    {~._.~}                   Great minds discuss ideas      _( Y )_           Average minds discuss events (:_~*~_:)                  Small minds discuss people    (_)-(_)                        ..... Eleanor Roosevelt           ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

## Re: Bounding box on plotting files inserted into a LaTeX document

 > On May 16, 2019, at 7:04 PM, Patrick Connolly <[hidden email]> wrote: > > I'm trying to write basic latex code to insert a pdf graphic into a > document.  I can use Rstudio to knit an Rmd file successfully > inserting the plot into the document.  I can get the latex code if the > "save tex" box is ticked, so I get the correct syntax used.   > > I don't need all the fancy things that .Rmd files can handle.  I just > want a simple .tex file.  However, if I try to use a pdf file normally > produced by using the pdf device, I get a message about a missing > bounding box.  So I thought it might work to use R to make an eps > file, which pdflatex automatically converts to a pdf.  It does import > the graphic, but it takes up a whole page, which indicates that it > ignores the bounding box. > > What does work is to use Rstudio interactively to export the graphic > to a pdf file which pdflatex handles correctly.  But that's a clunky > procedure which I'd like to avoid.  It must be possible since graphs > were included in LaTeX documents for decades before there was Rstudio. > > TIA Patrick, Are you explicitly calling postscript() in an R session to create the figure? If so, see the Details section of ?postscript, which notes the following: The postscript produced for a single R plot is EPS (Encapsulated PostScript) compatible, and can be included into other documents, e.g., into LaTeX, using \includegraphics{}. For use in this way you will probably want to use setEPS() to set the defaults as horizontal = FALSE, onefile = FALSE, paper = "special". Note that the bounding box is for the device region: if you find the white space around the plot region excessive, reduce the margins of the figure region via par(mar = ). So essentially: postscript("YourPlot.eps", width = 6.0, height = 6.0,            horizontal = FALSE, onefile = FALSE, paper = "special") Plot code here... dev.off() Note that instead of pdflatex, you can also use latex, followed by dvips and then ps2pdf, if you want to go that way with the CLI workflow. Might depend upon whether or not you use other PS specific markup in the .tex file, like pstricks. For example: latex YourTeXFile.tex dvips YourTeXFile -o YourTexFile.ps ps2pdf YourTeXFile.ps YourTeXFile.pdf Regards, Marc Schwartz ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

## Re: Bounding box on plotting files inserted into a LaTeX document

 On Thu, 16-May-2019 at 07:52PM -0400, Marc Schwartz wrote: |> |> |> > On May 16, 2019, at 7:04 PM, Patrick Connolly <[hidden email]> wrote: |> > [...] |> |> |> Patrick, |> |> Are you explicitly calling postscript() in an R session to create the figure? |> |> If so, see the Details section of ?postscript, which notes the following: |> |> The postscript produced for a single R plot is EPS (Encapsulated |> PostScript) compatible, and can be included into other documents, |> e.g., into LaTeX, using \includegraphics{}. For use in |> this way you will probably want to use setEPS() to set the defaults |> as horizontal = FALSE, onefile = FALSE, paper = "special". Note |> that the bounding box is for the device region: if you find the |> white space around the plot region excessive, reduce the margins of |> the figure region via par(mar = ). |> So essentially: |> |> postscript("YourPlot.eps", width = 6.0, height = 6.0, |>            horizontal = FALSE, onefile = FALSE, paper = "special") I failed to understand what the 'onefile' argument was about.  I thought I needed it to be TRUE because I was making a single plot in a single file. :-( I knew there was something simple I was missing.  I would have noticed it if I'd read that Details section properly. |> |> Plot code here... |> |> dev.off() |> |> |> |> Note that instead of pdflatex, you can also use latex, followed by |> dvips and then ps2pdf, if you want to go that way with the CLI |> workflow. Might depend upon whether or not you use other PS |> specific markup in the .tex file, like pstricks. For example: I used to have a little shell script that did the dvips and ps2pdf but I recently found that pdflatex seems to do that anyway, so I thought that was easier and more transportable. Thanks, Marc. |> latex YourTeXFile.tex |> dvips YourTeXFile -o YourTexFile.ps |> ps2pdf YourTeXFile.ps YourTeXFile.pdf |> |> |> Regards, |> |> Marc Schwartz |> -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.      ___    Patrick Connolly    {~._.~}                   Great minds discuss ideas      _( Y )_           Average minds discuss events (:_~*~_:)                  Small minds discuss people    (_)-(_)                        ..... Eleanor Roosevelt           ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.