3MW (Writing a {gt} book)

Guten Tag!

Many greetings from Ulm, Germany.

This week, I announced a project I've been working on for a couple of weeks now. In this project I collect everything I've learned about table creation with {gt} in a Quarto book.

The first draft of the first two chapter is already online at gt.albert-rapp.de. I'm currently in the midst of wrapping up this project until Friday. That's when the RStudio Posit table contests end. And I want to make this book a submission.

Thus, today we're going to take a short tour of what you can expect from this book.

Basic table guidelines and fancy visual elements

A couple of weeks ago, I have shown you many guidelines for better tables. These guidelines ranged from simple stuff like "Avoid vertical lines" to "Incorporate eye catchers like plots, icons or images".

All of these guidelines are now available with code in Chapter 1 and Chapter 2 of the book. Of course, the code is accompanied by explanations.

Formatting and Theming

Chapters 3 and 4 talk about the painstaking details. You're going to learn how transform your data into a better format or how to change the theme of your table. We have not really talked about these things on this newsletter. That's because the newsletter format does not let me show you the code that well.

But I'll publish these two chapters probably tomorrow or on Friday by the latest (you know, because of the deadline). These chapters were really hard to write because they require so much focus on little details and their execution via code. Once the chapters are online, Feedback is highly appreciated.

Case studies

The last regular chapter of the book puts it all together. We will create pretty elaborate tables like this one here. It's a recreation of a table that Tanya Shapiro created with {ggplot2}. For the full size image, just follow the link.

Quarto

The last chapter of the book is kind of a bonus chapter. It teaches readers how to incorporate their tables in Quarto document. Sounds simple but it really isn't. The problem is that Quarto will overwrite your table theme if you're not careful.

The gist of how to solve this problem requires two parts (details will be in the book by Friday).

  • as_raw_html() + initial HTML styles: This ensures that table styling isn't overwritten by Quarto.

  • Overwrite knit_print(): This can automatically apply as_raw_html() and initial HTML styles to any chunk that prints a {gt} table. Otherwise, you will have to apply step 1 manually every. single. time. And you do not want that. Believe me, writing a {gt} book has taught me that much.

All of this is summarized in this code snippet:

That's a wrap! As always, I'm happy to hear your feedback about this week's issue. Feel free to write me on Twitter or reply to this mail.

Enjoy the rest of your day!Albert

Did you like this post and want to support more content like this? Whenever you feel like it, you can support me with a coffee or a membership.

Need help visualizing your data? Or need to build a Shiny app? I'm open to freelance work. You can book a free 30-minute Zoom meeting with me and we can find out if I'm a good match for your project.

Reply

or to participate.