Open wilbowma opened 4 years ago
Looks like the issue is in the way picts are rendered, as includegraphic
doesn't have its box adjusted. The solutions I've found by playing with the latex and based on this article https://tex.stackexchange.com/questions/30079/how-to-align-picture-top-left-in-a-table
\usepackage[export]{adjustbox}
, and and somehow wrap the cell in \adjustbox{valign=t}{...}
. This might be undesirable if we don't want another dependency, and not sure if this can be done for all cells or if we need to detect a pict cell. This works very well in my tests and I get the same output as in the HTML. It also seems to be safe to wrap elements that have already been adjusted without doing any harm.\raisebox
in render to use \raisebox{-\height}
, if we're supposed to be top-aligned. Seems that render-content
doesn't have that information, so not exactly sure how to implement that change. This also doesn't render exactly like the HTML; there's some extra space at the top of the cell (similar to the extra space at the bottom in the PDF example above)Using adjustbox
doesn't quite get is to the same behavior on both backends. In this example, all look the same in HTML, but the first two are slightly different than the second two in PDF. Not sure who is to blame
#lang scribble/base
@tabular[
#:row-properties '((top-border top bottom-border))
(list
(list "> " @verbatim|{a very tall
cell.}|))
]
@(require pict)
@tabular[
#:row-properties '((top-border top bottom-border))
(list
(list "> " (filled-ellipse 40 40)))
]
@tabular[
#:row-properties '((top-border bottom-border))
#:cell-properties '((center top))
(list
(list "> " @verbatim|{a very tall
cell.}|))
]
@(require pict)
@tabular[
#:row-properties '((top-border bottom-border))
#:cell-properties '((center top))
(list
(list "> " (filled-ellipse 40 40)))
]
HTML:
PDF:
It looks like all cells ought to be wrapped in \begin{tabular}{@{}c@{}}
, otherwise they don't seem to have ascent/descent, and modifying their alignment pushes the top of the character, rather than the top of the ascent, to the top of the table. Visually:
In my example, the ">" is not wrapped, while the verbatim contents is wrapped.
Unfortunately, tables don't seem to align as I expect. The vertical alignment of one cell seems to depend on the other cell, at least when the cell contents is a graphic. In the below example, I try to top align the left and center align the right, then top align both:
It seems that the vertical alignment of a "cell" is actually aligned with respect to the boxes around it. I have no ability to predict this behavior:
The latex snippet (which expects to be in the document of a generate scribble template)
\setlength{\fboxsep}{0pt}
\newcommand{\wrap}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}
\newcommand{\id}[1]{#1}
\newcommand{\tablethinggraphic}[4][\id]{
\vspace{2pt}
#2 #3 #4
\vspace{2pt}
\begin{bigtabular}{@{\bigtableleftpad}l@{}l@{}l@{}}
\hline \fbox{\adjustbox{valign=#2}{#1{\hbox{$>$}}}} &
\fbox{\adjustbox{valign=#3}{{\raisebox{-0.19999999999999574bp}{\makebox[32.00000000000001bp][l]{\includegraphics[trim=2.4000000000000004 2.4000000000000004 2.4000000000000004 2.4000000000000004]{pict.pdf}}}}}}
&
\fbox{\adjustbox{valign=#4}{{\raisebox{-0.19999999999999574bp}{\makebox[48.00000000000001bp][l]{\includegraphics[scale=1.5,trim=2.4000000000000004 2.4000000000000004 2.4000000000000004 2.4000000000000004]{pict.pdf}}}}}}
\\
\hline \end{bigtabular}
}
\tablethinggraphic[\wrap]{t}{c}{t}
\tablethinggraphic[\wrap]{t}{c}{c}
\tablethinggraphic[\wrap]{t}{t}{b}
\tablethinggraphic[\wrap]{t}{b}{b}
Okay I've got an algorithm that I think might work, although so far my implementation isn't working flawlessly:
Before aligning the cells, we need to measure the height of the row, and the width of each cell. Then we manually build a vertical box around each cell that has the height of the entire row. We add vfil
to the beginning and end of the vbox
depending on how we want to align it.
\setlength{\fboxsep}{0pt}
\newcommand{\wrap}[2][c]{\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}}
\newcommand{\id}[1]{#1}
%require row height and cell
\makeatletter
\newlength{\@meowheight}
\newcommand{\setmeowheight}[1]{
\settoheight{\@meowheight}{\vbox{#1}}
}
\newcommand{\measurerowheight}[2]{%
\settoheight{\@meowheight}{\vbox{\begin{bigtabular}{#1}#2{\end{bigtabular}}}}%
\relax%
}
\newlength{\@meowwidth}
\newcommand{\alignedcell}[2]{%
\settowidth{\@meowwidth}{#2}
\vbox to \@meowheight{%
\ifthenelse{\equal{#1}{c}}{\vfil}{\ifthenelse{\equal{#1}{b}}{\vfil}{\relax}}%
\hbox to \@meowwidth{#2}%
\ifthenelse{\equal{#1}{c}}{\vfil}{\ifthenelse{\equal{#1}{t}}{\vfil}{\relax}}%
}
}
\makeatother
\setmeowheight{
\begin{bigtabular}{@{\bigtableleftpad}l@{}l@{}l@{}}
\hline
\wrap{\hbox{$>$}} &%
\wrap{\raisebox{-0.19999999999999574bp}{\makebox[32.00000000000001bp][l]{\includegraphics[trim=2.4000000000000004 2.4000000000000004 2.4000000000000004 2.4000000000000004]{pict.pdf}}}} &%
\wrap{\raisebox{-0.19999999999999574bp}{\makebox[48.00000000000001bp][l]{\includegraphics[scale=1.5,trim=2.4000000000000004 2.4000000000000004 2.4000000000000004 2.4000000000000004]{pict.pdf}}}}%
\\ \hline%
\end{bigtabular}
}
\newcommand{\tablethinggraphic}[4][\id]{
\vspace{2pt}
#2 #3 #4
\vspace{2pt}
\begin{bigtabular}{@{\bigtableleftpad}l@{}l@{}l@{}}
\hline
\fbox{\alignedcell{#2}{\wrap{\hbox{$>$}}}} &
\fbox{\alignedcell{#3}{\wrap{{\raisebox{-0.19999999999999574bp}{\makebox[32.00000000000001bp][l]{\includegraphics[trim=2.4000000000000004 2.4000000000000004 2.4000000000000004 2.4000000000000004]{pict.pdf}}}}}}}
&
\fbox{\alignedcell{#4}{\wrap{{\raisebox{-0.19999999999999574bp}{\makebox[48.00000000000001bp][l]{\includegraphics[scale=1.5,trim=2.4000000000000004 2.4000000000000004 2.4000000000000004 2.4000000000000004]{pict.pdf}}}}}}}
\\ \hline
\end{bigtabular}
}
\tablethinggraphic[\wrap]{t}{c}{t}
\tablethinggraphic[\wrap]{t}{c}{c}
\tablethinggraphic[\wrap]{b}{b}{t}
\tablethinggraphic[\wrap]{t}{b}{b}
Not really sure why the alignment seems to affect the size of the vbox
s, and I can't see to measure the height of the row while inside the table using this method.
Here's an example:
Expected output, and the output in HTML:
Actual output in PDF: