nrennie / nrennie.github.io-comments

Repository to host Utterances for blog.
2 stars 0 forks source link

blog/making-pretty-pdf-quarto/ #5

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Making Pretty PDFs with Quarto | Nicola Rennie

Adding custom styling to documents makes them look more professional. This blog post will take you through the process of making a Quarto extension to create a reusable custom template for good-looking PDFs.

https://nrennie.rbind.io/blog/making-pretty-pdf-quarto/

collioud commented 1 year ago

Hello Nicola, Thanks for this pretty PrettyPDFs extension, which looks really nice! Just a quick note : I think you have to switch the "quarto use template nrennie/PrettyPDF" and the "quarto install extension nrennie/PrettyPDF" code lines to fit to the text... Cheers, Arnaud

nrennie commented 1 year ago

Thanks Arnaud! I'm not quite sure what you mean by "fit to the text"? Using the install extension copies the _extensions folder, whereas use template does the same thing but additionally copies the template.qmd folder into a new directory for you.

collioud commented 1 year ago

My mistake... I thought that "quarto install" was for (globally) installing a template/extension and "quarto use" for using it in a project. Now your text makes perfectly sense to me!

ibecav commented 1 year ago

Just a quick thanks for a great post and a great extension. The sincerest form of flattery -- I was able to follow along put it to use and then modify a version for my own tastes!

nrennie commented 1 year ago

I'm glad it was useful!

fjodor commented 1 year ago

Thanks, very helpful and appreciated! Are you also printing reveal.js slides to PDF using R and quarto? I enthusiastically switched from xaringan to quarto presentations and really liked reveal.js in html format. However, I need a PDF version as well, and had too many ugly slides (e. g. some images missing in an html table in PDF, others shown) that I decided to move back to xaringan for the time being, until quarto and reveal.js will hopefully play more nicely to PDF. Any thoughts / experiences?

nrennie commented 1 year ago

Thanks @fjodor! Yes, I do quite often make a PDF version of HTML slides (always useful to have an backup!). I've found some issues converting to PDF when I have self-contained/embed-resources set to true (unsure why), so might be worth toggling between true/false to see if that helps. Another thing I've found useful is using a fixed width/height for revealjs presentations.

jstrappa commented 1 year ago

Thank you for this extension and for the easy-to-follow explanation. The default style for PDFs is just ugly. :) I can't understand why Quarto doesn't have themes for the PDF output, maybe it has to do with the accessibility issues? Is it that PDFs are falling into disuse in favor of HTML? But I'm not sure how I'd use HTML for documents that need to be self-contained. I tried that once and the recipients were unable to open the file.

nrennie commented 1 year ago

Thanks! It might be a combination of accessibility, interactivity, and perhaps that PDF output was maybe originally aimed at academics?

You can set self-contained: true (or the slightly newer embed-resources: true) in the YAML to make your HTML document self contained. They don't usually preview well in email apps, but if recipients download the file it should open in a web browser. I haven't had any issues sharing self-contained HTML files with Quarto yet

chonasson commented 1 year ago

This is really helpful, thank you Nicola. I was wondering how I would have to proceed if I were to create a template for a multi-page document, such as a report. Do you have any tips or a link to more advanced resources?

nrennie commented 1 year ago

Thanks! This template will also work for multipage documents - it will apply the same styling to each page. There are LaTeX functions that can change to styling for odd and even pages if you want put e.g., the page number on different sides - this would be a reasonably small change to this template. The other thing that's common is to also include a differently styled title page - there's some examples here: https://www.overleaf.com/gallery/tagged/title-page that you can look at the source code for.

myaseen208 commented 1 year ago

Thank you for the helpful template. I have two questions: firstly, I would like to know how to have separate page numbers for the frontmatter and mainmatter sections; and secondly, I am interested in learning how to increase the spacing between the chapter number and chapter title. I appreciate your assistance.

aito123 commented 1 year ago

Hi Nicola, thanks so much for the explanation and the resources at the end. You really make the data science path more fun! Take care.

nrennie commented 1 year ago

@myaseen208 Thanks! For the different page numbering, you could use something like \pagenumbering{roman} for the frontmatter, and then switch to a different type for your main document. There's some more details here: https://www.overleaf.com/learn/latex/Page_numbering

For the chapter number spacing, I'm not too sure. You probably want to do something like \titleformat{\chapter}[hang]{\thechapter\hspace{3pt}} You could maybe adapt this code for styling chapter numbers: https://tex.stackexchange.com/questions/139366/chapter-header-with-super-huge-numbers

dmpimentel commented 10 months ago

Hi! This template is so pretty! Thank you for sharing. I'm going to use your explanations and try to make one my own. Thank you :)

MarkHanly commented 8 months ago

So useful, thank you for sharing!

DavidPatShuiFong commented 8 months ago

Thanks Nicola! this is a really nice template, and I am planning to use them as a basis for monitoring/evaluation reports for a non-profit child development organisation.

Is there a way to add author affiliations details? I tried to modify/add the code of PrettyPDF.tex using authblk as per Why do affiliations not show up anywhere in the pdf output of quarto?, but I wasn't successful!

nrennie commented 7 months ago

Thanks @DavidPatShuiFong! You would need to add that in a separate .tex file and pass it into the yaml as:

template-partials: 
      - title.tex

The PrettyPDF.tex file isn't a LaTeX template file so it goes in the yaml as:

include-in-header: 
       - PrettyPDF.tex

Hope that helps!

sebastianmarinc commented 5 months ago

HI Nicole, thanks so much for creating this extension! I'm actually having trouble with installation on my Windows machine. For some reason when trying to knit my doc, there's a latex error: it can't find `eso-pic.sty'. Have you encountered this issue? Any help would be much appreciated!

nrennie commented 4 months ago

Sorry for taking so long to get back to you (easier if you raise an issue in the extension repository, rather than on the blog post).

How did you install LaTeX? This suggests that the eso-pic package needs to be installed. You can use tinytex to install missing packages. See https://bookdown.org/yihui/rmarkdown-cookbook/install-latex-pkgs.html for details.