column.width issue when using img refs
dcomtois opened this issue · comments
The column widths are affected by the length of the path to images, which should not happen... For instance, if a cell contains:
![](C:\\Users\\usr1234\\AppData\\Local\\Temp\\RtmpQhs2I7\\file3a745a6e4f4f.png)
The width will try to accomodate for all these characters.
Here's a .Rmd demo:
---
title: "Untitled"
output: html_document
---
```{r, results='asis'}
devtools::install_github("dcomtois/summarytools", ref="colwidth-issue")
library(summarytools)
dfSummary(tobacco, plain.ascii = FALSE, style = "grid",
graph.magnif = 0.82, valid.col = FALSE)
```
I think this is a limitation of pandoc
and not a pander
issue, so please check with the devs there with a minimal example of a markdown file including a grid table with an image (markup) in a cell. Once we know how to do that properly in markdown, pander
will be able to kick in as well.
Just a little update, in case someone encounters the same situation: I asked the question on the pandoc discussion group, and it is indeed a limitation in pandoc. There is an easy workaround when the column containing the images is the last one:
+-------+---------------+
| color | Img |
+=======+===============+
| Blue | ![](tiny-blue-square-with-a-ridiculously-long-file-name.png) |
+-------+---------------+
... but if it's not the last column, it doesn't work.
Otherwise, here are the suggestions I got from the Pandoc discussion board:
- use reference links (with knitr, I think this is only possible with images what were created in the .Rmd document itself)
- use pipe tables (not possible since the tables I generate are multi-line)
- use a filter like pandoc-fignos but it's not supported in knitr (see this feature request
- encapsulate the table in a <div>, as explained here
Only the last solution seems appropriate, at least for the moment (Edit: as it turns out, it also requires the use of a pandoc filter, so there is no obvious solution AFAIK.)
And it doesn't seem like there's a lot of appetite for change at this point.
Thanks, @dcomtois, these points are really useful 👍
You're welcome! Unfortunately the workaround I was putting my faith in a non-solution since it also requires a pandoc filter. Maybe an advanced Web developer could see a solution (involving Javascript, most probably), but I had to do something far from ideal to make things work: copy the images in a subdirectory and save them using short names. That way I can put in the cells something like this:
![]img/ds001.png
...and it makes the widths perfectly fine. Only (quite annoying) problem is that it leaves garbage behind.