Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell width of kable when hyperlinks are included #2147

Closed
3 tasks done
jacobbien opened this issue Jul 8, 2022 · 1 comment · Fixed by #2148
Closed
3 tasks done

Cell width of kable when hyperlinks are included #2147

jacobbien opened this issue Jul 8, 2022 · 1 comment · Fixed by #2148

Comments

@jacobbien
Copy link
Contributor

When we use kable(tbl, format = "pipe") and our table has one or more hyperlinks, written as [label](my-url), the width of the column will be based on nchar("[label](my-url)") rather than on nchar("label"). I've noticed this can be problematic when my-url is extremely long. Here's an example:

very_long_url <- paste(c("a", rep("very", 20), "long-url"), collapse = "-")
tbl <- data.frame(
  flavor = sprintf("[Mint chip](%s)", very_long_url),
  description = "Of all the many flavors of ice cream, this is my favorite."
  )
knitr::kable(tbl, format = "pipe")
| flavor                                                                                                                      | description                                                |
|:----------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------|
| [Mint chip](a-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-url) | Of all the many flavors of ice cream, this is my favorite. |

The problem is that when one uses rmarkdown::render() on a Markdown file with such a table, the resulting html squeezes the second column unnecessarily:

Screen Shot 2022-07-07 at 11 04 19 PM

To reproduce the screenshot, one can download example.zip, which has example.Rmd in it, and then run the following two lines:

knitr::knit("example.Rmd", output = "example.md")
rmarkdown::render("example.md")
> xfun::session_info("knitr")
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6.7, RStudio 2022.2.3.492

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  evaluate_0.15   glue_1.6.2      graphics_4.2.1  grDevices_4.2.1 highr_0.9      
  knitr_1.39.5    magrittr_2.0.3  methods_4.2.1   stats_4.2.1     stringi_1.7.6  
  stringr_1.4.0   tools_4.2.1     utils_4.2.1     xfun_0.31       yaml_2.3.5     

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant