public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Images in tables
@ 2019-10-27 19:45 ChrisD
       [not found] ` <9c0fa901-7b66-e34e-1218-c4ff87d22bb3-4SSc53hpTiu9TMao6EloiEEOCMrvLtNR@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: ChrisD @ 2019-10-27 19:45 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

I have some tables where I have an image in the first column, and text in the second column. For example

````md
---------------------- ---------------------------------------------------------------------------
![](ButtonZ.png)       The Z button will do ...

![](ButtonX.png)       The X button will do ...
---------------------- ---------------------------------------------------------------------------
````

For HTML output, the buttons and text are vertically centered in their cells. For PDF output, it appears that the text is aligned so the bottom of the first line of text lines up with the bottom of the image.

I would like to have the table contents top aligned -- the top of the text is aligned with the top of the image. Is there any way to do that?

I found the image-in-table filter (https://github.com/zommerfelds/pandoc-image-in-table), which makes an adjustment for pdf output. The result is similar to HTML, in that the bottom of the text is aligned with the center of the image. Perhaps I could modify this filter (or convert it to a lua filter), but how would I calculate the amount to move up? And how would I duplicate this effect in html?

Thanks,

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/9c0fa901-7b66-e34e-1218-c4ff87d22bb3%40intielectronics.com.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Images in tables
       [not found] ` <9c0fa901-7b66-e34e-1218-c4ff87d22bb3-4SSc53hpTiu9TMao6EloiEEOCMrvLtNR@public.gmane.org>
@ 2020-02-09  0:33   ` Dominic Comtois
       [not found]     ` <7dfc160b-b1b7-4535-bfa5-e2863961dc4e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Dominic Comtois @ 2020-02-09  0:33 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3771 bytes --]


I am struggling with the same problem... Any luck finding a way to 
top-align everything?

I wrote an *R* package <https://github.com/dcomtois/summarytools>that 
generates multiple-line grid tables with images. Converting to *html* or 
*Word* works well, but I haven't found a way to make it work for *pdf. *Here 
is a simplified example:

+-----------+--------------+----------------+
| Color     | Counts       | Chart          |
+===========+==============+================+
| 1\. Red\  | 410 (41.0%)\ | ![](chart.png) |
| 2\. Blue\ | 320 (32.0%)\ |                |
| 3\. Other | 270 (27.0%)  |                |
+-----------+--------------+----------------+

Rendered pdf looks like this:

[image: SumatraPDF_ti8GE9lt63.png] <about:invalid#zClosurez>

Clearly there is no obvious solution. Moreover, I have to work withing the 
constraints inherent to R packages; post-processing tweaks (like the python 
script mentioned in the original post) is not really an option. The 
solutions I can foresee involve one or several of the following (I could be 
missing something, too):

   1. adding inline latex to the markdown table (not sure that's possible 
   without bad side-effects on column widths)
   2. finding the right combination of Pandoc parameters (I can't find 
   anything in the documentation, but maybe I've missed something)
   3. using an R package that allows enhanced latex control: *markdown*, 
   *rmarkdown*, or maybe some other package I haven't come across
   
I'm fully aware that R programming is not within the scope of this group. 
What I'm hoping for is some feedback or guidance regarding the first two 
points above. If there is no way to make it work, then I'll start working 
on the 3rd option.

So far the best workaround I have is using wkhtmltopdf, but in terms of R 
Markdown integration, it's not looking too good.

I'm including the example chart here for the sake of reproducibility (I 
uploaded it here <https://i.imgur.com/Tx4u55l.png> as well):
[image: chart.png]

Any help would be most welcome! Thanks

On Sunday, 27 October 2019 15:45:41 UTC-4, ChrisD wrote:

> I have some tables where I have an image in the first column, and text in 
> the second column. For example 
>
> ````md 
> ---------------------- 
> --------------------------------------------------------------------------- 
> ![](ButtonZ.png)       The Z button will do ... 
>
> ![](ButtonX.png)       The X button will do ... 
> ---------------------- 
> --------------------------------------------------------------------------- 
> ```` 
>
> For HTML output, the buttons and text are vertically centered in their 
> cells. For PDF output, it appears that the text is aligned so the bottom of 
> the first line of text lines up with the bottom of the image. 
>
> I would like to have the table contents top aligned -- the top of the text 
> is aligned with the top of the image. Is there any way to do that? 
>
> I found the image-in-table filter (
> https://github.com/zommerfelds/pandoc-image-in-table), which makes an 
> adjustment for pdf output. The result is similar to HTML, in that the 
> bottom of the text is aligned with the center of the image. Perhaps I could 
> modify this filter (or convert it to a lua filter), but how would I 
> calculate the amount to move up? And how would I duplicate this effect in 
> html? 
>
> Thanks, 
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/7dfc160b-b1b7-4535-bfa5-e2863961dc4e%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 5772 bytes --]

[-- Attachment #2: SumatraPDF_ti8GE9lt63.png --]
[-- Type: image/png, Size: 9144 bytes --]

[-- Attachment #3: chart.png --]
[-- Type: image/png, Size: 209 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Images in tables
       [not found]     ` <7dfc160b-b1b7-4535-bfa5-e2863961dc4e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2020-02-09 16:47       ` John MacFarlane
  0 siblings, 0 replies; 3+ messages in thread
From: John MacFarlane @ 2020-02-09 16:47 UTC (permalink / raw)
  To: Dominic Comtois, pandoc-discuss


This seems relevant:
https://tex.stackexchange.com/questions/30079/how-to-align-picture-top-left-in-a-table

So, this might work (untested):

1.  Add \usepackage[export]{adjustbox} to your header-includes or custom
    template.
2.  Include the image using some raw LaTeX, e.g.
    `\includegraphics[valign=t]{imagename}`{=latex}

Another option would be (I think)

    \adjustbox[valign=t]{\includegraphics{imagename}}

Perhaps one could write a lua filter that finds all
images inside tables and inserts around each one the
raw latex inlines

    "\adjustbox[valign=t]{" and "}"

The filter could also add the raw latex block
"\usepackage{adjustbox}" to the metadata "header-includes"
field.  Then ALL that would be needed to fix the issue would
be this one lua filter.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-09 16:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-27 19:45 Images in tables ChrisD
     [not found] ` <9c0fa901-7b66-e34e-1218-c4ff87d22bb3-4SSc53hpTiu9TMao6EloiEEOCMrvLtNR@public.gmane.org>
2020-02-09  0:33   ` Dominic Comtois
     [not found]     ` <7dfc160b-b1b7-4535-bfa5-e2863961dc4e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-02-09 16:47       ` John MacFarlane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).