Code Monkey home page Code Monkey logo

Comments (10)

jrgant avatar jrgant commented on August 19, 2024 9

I'm still having this issue with table captions using the following:

knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
df <- data.frame(x = rep(1:2, each = 5),
                 y = rnorm(10))

df %>%
  knitr::kable(., caption = "Good caption (no chunk label)")
df %>%
  knitr::kable(., caption = "Bad caption (chunk label with period)")
df %>%
  knitr::kable(., caption = "Bad caption (chunk label with underscore)")

The bad captions:

rendered_captions.jpg

radix_bug.txt

from distill.

haozhu233 avatar haozhu233 commented on August 19, 2024 3

https://haozhu233.github.io/kableExtra/using_kableExtra_in_radix.html

I just added a quick example of how to use kableExtra in radix. @MarcioFCMartins I hope it helps you feel better. :)

I really love the design of radix!

from distill.

a-bro-0227 avatar a-bro-0227 commented on August 19, 2024 3

o man! @jrgant thank you. I've been stuck on this issue and could not figure out why my captions were rendering (#tab:caption). Only populates correctly with a - for spaces. No periods or underscores.

from distill.

jjallaire avatar jjallaire commented on August 19, 2024 1

Yeah, it's difficult to run down every table formatting package and imbue all of their output with correct behavior. So far we've focused on pagedtable and plain kable. We'd welcome contributions to help support others so long as they don't make our core codebase too complicated and/or fragile.

from distill.

meghandownes avatar meghandownes commented on August 19, 2024 1

Thank you for this post and the discussion. Changing my chunk label allowed the bookdown kable_extra rendered as PDF to correctly add table headings. You have helped my day so much. Thanks!

from distill.

jjallaire avatar jjallaire commented on August 19, 2024

Okay, I've modified the CSS for table captions to appear as follows:

screen shot 2018-10-10 at 9 06 19 am

Note that for kable the caption always appears above the table by design: yihui/knitr#1189

In terms of the other cross references, this is a known limitation of bookdown cross-references: https://bookdown.org/yihui/bookdown/figures.html

I'll add a note about that to the documentation.

from distill.

MarcioFCMartins avatar MarcioFCMartins commented on August 19, 2024

kable captions are now working, but adding extra formatting via kableExtra::kable_styling still breaks it. Actually, simply loading the package breaks it unless the user setsoptions(kableExtra.auto_format = FALSE). This makes me believe that the issue is when the format is set to 'html' via this function.

I have no idea how pratical it is to ensure this formatting works for all package combinations (formattable comes to mind, since it works with kableExtra - https://haozhu233.github.io/kableExtra/use_kableExtra_with_formattable.html), but since kableExtra is recommended in the documentation (https://bookdown.org/yihui/rmarkdown/r-code.html#tables) I think it's worth ensuring it works.

The caption apearing above the table is proper scientific writing behaviour (atleast in most fields and from my experience) so that makes sense and it's exactly as I expect it.

I never realized that bookdown had that issue as well - thank you for the heads up and for the super quick fix - I will simply avoid extra table formatting until everything can be worked out.

from distill.

MarcioFCMartins avatar MarcioFCMartins commented on August 19, 2024

EDIT: I just submitted my proposed change as a pull request.

I noticed that you can actually break the caption formatting with the base kable function if you set format to html rather than pandoc.

This is because in distill.html you are setting the caption style for the pandoc table class individually. This means you need to ensure all tables have pandoc-table class to correctly format their caption - and this has to be done for every package.

Wouldn't it be more efficient to set the style for the table>caption element? This element is used to create the captions for all tables, regardless of their class (and the same is true for images, but you might want the ability to control the styles separatly).

I tried changing line 835 - currently $('.pandoc-table>caption').addClass("figcaption");. Changing it to $('caption').parent('table').addClass("figcaption") changes all table captions (regardless of being tagged as pandoc tables) to the same style as figcaption.

You could also just set style for all captions, regardless of where they are used by removing the parent. If you have no need for differently formatted captions this might be the best.

from distill.

mapostolides avatar mapostolides commented on August 19, 2024

How do I change things like the caption colour and size, etc? There seems to be no documentation on this

from distill.

cderv avatar cderv commented on August 19, 2024

How do I change things like the caption colour and size, etc? There seems to be no documentation on this

You could probably use CSS for this - the exact CSS could depend on which format of table you are using. CSS and distill is documented in https://rstudio.github.io/distill/basics.html#theming and https://rstudio.github.io/distill/website.html#custom-style and https://rstudio.github.io/distill/website.html#theming

We don't have built in way to change this using variable, you need to use custom CSS for this.

Hope it helps

from distill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.