Confused on PDF output format.

Apologies if this has been directly answered before, I might be asking the ;"wrong" question. (nOOb)

I'll try to explain as best as possible - new user to Rstudio (and absolutely LOVE it)
I'm having trouble understanding what controls the look and feel of the final pdf output.

When i first installed RSTUDIO it gave me a very nice format - now it's using different fonts and alignment ... I cannot sort out what is causing it, I've pent the better part of 4 hours looking for a solution to control the pdf style - with no luck - everyone just talks about tinytex, mitex etc... but doesn't matter what i do the format is always the same...

1 Like

Hi, and welcome to a safe place for beginner questions. R is so vast that I'm constantly finding myself trying to figure out new things.

The basic workflow for a pdf document starts with File | New File | RMarkdown | PDF, which will give you a template and some example text:


title: "PdfTemplate"
author: "Richard Careaga"
date: "10/25/2019"
output: pdf_document

knitr::opts_chunk$set(echo = TRUE)

R Markdown

This is an R Markdown document. ...

To use it, you have to have a \LaTeX environment installed on your host. Google for your platform and you will find tons of guidance on how to do that, such as one from Wellesley

rmarkdown uses pandoc, the Swiss Army knife of format converters to go from your document to the pdf by way of the \LaTeX engine.

The defaults are decent. If, however, you want fine-grained control over the layout, font, appearance, etc., of the final document, you have to take holy orders in LaTeX syntax and features.

It's a substantial investment in time.

With that explainer done, my suggestion for your immediate problem is to knit the initial template to see if you have the same problem. If so, let everyone know. If not, add some of your own material until the strangeness pops up

2 Likes

Thank-you so much for the informative reply.

The first learning path with Markdown was VSC, and some extensions - this gave me a very nice PDF in github format, in a side by side view - then when using the Markdownpdf extension pack - this renders to a nice looking pdf.

Started using RStudio - and knitting to pdf gives me a format with Serif fonts and centered title.
(some screenshots) - Somewhere inside my thick skull there is an idea that these two programs are using the same engine to generate the pdf ...i might just be getting confused at what is going on behind the scenes (my assumptions are rarely correct)

The main reference for all things RMarkdown is https://bookdown.org/yihui/rmarkdown/

For output format specific information, consider https://bookdown.org/yihui/rmarkdown/pdf-document.html

In general, when you write RMarkdown, you then render that document to some format. In RStudio, that involved knitting the document (knit/knitr/compose notebook adn other names you may see for it). That takes the .Rmd, extracts the plain text to a .md file and the .R code to scripts. The R code is executed and the resulting output is merged into the .md file. That .md file is then handed to pandoc, a near-universal document converter that takes a given format as input and produces any one of hundreds of formats as output, including PDF (using a style template), HTML, MS Word (using OOXML), etc.

So, any particular style issue one might see could be a matter of how knitr processes the .Rmd, how R executes the .R code, how pandoc converts .md to .pdf or .docx or .html, or how the application you use to view the resulting document decides to render the file.

2 Likes

thanks Wil - much appreciated

The MarkdownPdf extension docs say

its large size (~ 170Mb Mac, ~ 282Mb Linux, ~ 280Mb Win)

which strongly suggests to me that it runs its own rendering engine, rather than Pandoc. It also appears to provide more control than you can get in RStudio without going under the LaTeX hood.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.