# problem with Vertical alignment of text and images in long table when using tex4ht

With the help of experts in Yet another images in tables question alignment. Want text to start at top of cell. Not cetered I can now get text to show in correct place with images in a long table, when using lualatex.

But the same solution does not work when I compile to HTML using make4ht. So this question is asking what to do to make the result show the same in HTML as in PDF. Here is a MWE. The issue seems to be that valign=t from adjustbox has no effect in tex4ht as it does in pdf.

\documentclass[12pt]{article}
\usepackage{longtable}
\begin{document}

\begin{longtable}[c]{|p{1in}|p{3in}|p{1in}|}\hline
Test A&\vspace{0pt}\includegraphics[width=3in,valign=t]{example-image-a}&TestB\\\hline
\end{longtable}
\end{document}


Compiled using lualatex foo4.tex gives expected output

Compiling the same file with make4ht foo4.tex gives this

I want the text to be at the top, like it shows in PDF.

Since clearly valign=t does not work in tex4ht, what other options are there to do the same in tex4ht? How to best resolve this issue? Do I need some CSS special configuration?

The HTML code generated is

<!DOCTYPE html>
<html lang="en-US" xml:lang="en-US" >
<meta  charset="iso-8859-1" />
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" type="text/css" href="foo4.css" />
<meta name="src" content="foo4.tex" />
>
<a
id="x1-2r1"></a>   <!--l. 8--><div class="longtable"> <table id="TBL-1" class="longtable"
><colgroup id="TBL-1-1g"><col
id="TBL-1-1" /></colgroup><colgroup id="TBL-1-2g"><col
id="TBL-1-2" /></colgroup><colgroup id="TBL-1-3g"><col
id="TBL-1-3" /></colgroup>
<tr
class="hline"><td><hr /></td><td><hr /></td><td><hr /></td></tr><tr
style="vertical-align:baseline;" id="TBL-1-1-"><td  style="white-space:normal; text-align:left;" id="TBL-1-1-1"
class="td11">
<!--l. 8--><p class="noindent" >Test A          </p></td><td  style="white-space:normal; text-align:left;" id="TBL-1-1-2"
class="td11">
<!--l. 8--><p class="noindent" ><img
src="example-image-a.png" alt="PIC"
width="216" height="162"  />                                                  </p></td><td  style="white-space:normal; text-align:left;" id="TBL-1-1-3"
class="td11">
<!--l. 8--><p class="noindent" >TestB           </p></td>
</tr><tr
class="hline"><td><hr /></td><td><hr /></td><td><hr /></td></tr><tr
style="vertical-align:baseline;" id="TBL-1-2-"><td  style="white-space:normal; text-align:left;" id="TBL-1-2-1"
class="td11">            </td>
</tr><tr
style="vertical-align:baseline;" id="TBL-1-3-"><td  style="white-space:normal; text-align:left;" id="TBL-1-3-1"
class="td11">            </td>
</tr><tr
style="vertical-align:baseline;" id="TBL-1-4-"><td  style="white-space:normal; text-align:left;" id="TBL-1-4-1"
class="td11">
<!--l. 9--><p class="noindent" >            </p></td>
</tr><tr
style="vertical-align:baseline;" id="TBL-1-5-"><td  style="white-space:normal; text-align:left;" id="TBL-1-5-1"
class="td11">
<!--l. 9--><p class="noindent" >            </p></td>
</tr><tr
style="vertical-align:baseline;" id="TBL-1-6-"><td  style="white-space:normal; text-align:left;" id="TBL-1-6-1"
class="td11">              </td><td  style="white-space:normal; text-align:left;" id="TBL-1-6-2"
class="td11">                                         </td><td  style="white-space:normal; text-align:left;" id="TBL-1-6-3"
class="td11"></td></tr>
</table></div>

</body>
</html>


Update

I found that if I manually edit the HTML and replace

 <tr  style="vertical-align:baseline;"


With

  <tr   style="vertical-align: top;"


Then it works!

However, I am not able to figure out the correct CSS to add to my .cfg in order to tell tex4ht to use this style for tr. So I just need to figure this part out.

  \Css{tr {vertical-align:top;}}


to my .cfg, but it has no effect. The generated HTML still shows <tr style="vertical-align:baseline;". So I have no idea now how to overwrite this and do not know where tex4ht sets vertical-align:baseline to change it!

This is very complicated business modifying CSS style in tex4ht since there are so many classes and I am never sure which one to modify.

TL 2019

In this case, we need to get rid of the default vertical-align inserted in the style attribute of all table rows, and then insert the correct vertical alignment for the current row in the CSS.

We can patch the commands adjustbox uses for the vertical alignment of the rows. We will use these to insert the necessary CSS code. The file adjustbox.4ht:

\NewConfigure{AdjustboxValignTop}{1}


The CSS instructions can be inserted in the .cfg file:

\Preamble{xhtml}

\Configure{halignTR}{}
\begin{document}
\EndPreamble


The \Configure{halignTR}{} disables insertion of the style attribute for <tr> elements. The

\Configure{AdjustboxValignTop}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:top;}}}


and variants of this configuration are used for the CSS declaration. \#TBL-\TableNo-\HRow- contains id of the current row.

The following sample:

% https://tex.stackexchange.com/q/490873/2891
\documentclass[12pt]{article}
\usepackage{longtable}
\begin{document}

\begin{longtable}[c]{|p{1in}|p{3in}|p{1in}|}\hline
Test A&\vspace{0pt}\includegraphics[width=3in,valign=t]{example-image-a}&TestB\\\hline
test d & \includegraphics[width=3in]{example-image-a}& test f\\\hline
test d & \includegraphics[width=3in,valign=b]{example-image-a}& test f\\\hline
\end{longtable}
\end{document}


produces a following result:

• Thank you. I want to try it. But it is not clear where should I copy the file adjustbox.4ht that you show above to? which folder? should it go to /usr/local/texlive/2019/texmf-dist/tex/generic/tex4ht/ ? or somewhere else? Will this file be included in official source code so next time I update it be there? I did kpsewhich adjustbox.4ht but there was no current file with this name now there. So I assume this is new file. – Nasser May 15 '19 at 18:40
• ps. I also need to merge/add to adjustbox.4ht the content of your other fix as shown here tex.stackexchange.com/questions/316979/… but not sure if it should go above or below what you have here. I am actually a little confused now about this file.. – Nasser May 15 '19 at 19:03
• fyi. It works. I put your adjustbox.4ht for now in my \$HOME folder and edits my .cfg with your code. All is working. – Nasser May 15 '19 at 19:24
• @Nasser ah, I totally forgot about my old answer. I have some code also for your \includegraphics problem, so I will put it to the sources once everything works – michal.h21 May 15 '19 at 21:11
• @Nasser try something like ~/texmf/tex/latex/adjustbox/adjustbox.4ht – michal.h21 May 16 '19 at 8:35