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

Table headers top aligned instead of bottom aligned #7347

Closed
frederik-elwert opened this issue Jun 3, 2021 · 6 comments
Closed

Table headers top aligned instead of bottom aligned #7347

frederik-elwert opened this issue Jun 3, 2021 · 6 comments

Comments

@frederik-elwert
Copy link
Contributor

The change in #6883 leads to nicer output, but it has a side-effect that might be undesired (or at least unexpected for users): Previously, the minipage for table header cells would use a bottom vertical alignment [b] (while using top vertical alignment [t] for regular cells):

+----------------------------+---------------------------------------+----------------------------+
| A                          | B                                     | A                          |
+============================+=======================================+============================+
| sdasdasda                  | asdasdasdasd                          | sdasdasda                  |
|                            |                                       |                            |
+----------------------------+---------------------------------------+----------------------------+

Table: Title
\begin{longtable}[]{@{}lll@{}}
\caption{Title}\tabularnewline
\toprule
\begin{minipage}[b]{0.27\columnwidth}\raggedright
A\strut
\end{minipage} & \begin{minipage}[b]{0.37\columnwidth}\raggedright
B\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\raggedright
A\strut
\end{minipage}\tabularnewline
\midrule
\endfirsthead
\toprule
\begin{minipage}[b]{0.27\columnwidth}\raggedright
A\strut
\end{minipage} & \begin{minipage}[b]{0.37\columnwidth}\raggedright
B\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\raggedright
A\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.27\columnwidth}\raggedright
sdasdasda\strut
\end{minipage} & \begin{minipage}[t]{0.37\columnwidth}\raggedright
asdasdasdasd\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\raggedright
sdasdasda\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

The new output no longer produces minipages in most cases. However, this changes the alignment of table header cells from bottom to top.

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.30}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.41}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.30}}@{}}
\caption{Title}\tabularnewline
\toprule
A & B & A \\
\midrule
\endfirsthead
\toprule
A & B & A \\
\midrule
\endhead
sdasdasda & asdasdasdasd & sdasdasda \\
\bottomrule
\end{longtable}

In my personal opinion, the previous behaviour leads to nicer output. But more importantly, the change alters the output in an unexpected way.

From what I understood, pandoc still uses minipages where necessary. Would it be possible to output minipages also for table headers and restore the previous behaviour of bottom alignment?

@jgm
Copy link
Owner

jgm commented Jun 3, 2021

Is there way a way to get bottom alignment without using minipages?

@jgm
Copy link
Owner

jgm commented Jun 3, 2021

I think it might work to enclose the contents of each heading cell in a \vbox{...}.
EDIT: No, it doesn't.

Question: is bottom alignment or center (vertical) alignment better? The latter is default for HTML headers.

@frederik-elwert
Copy link
Contributor Author

For me, \vbox actually did the trick:

\begin{longtable}[]{@{}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.20}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.15}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.15}}
  >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.50}}@{}}
\caption{A test table \label{tbl:tab1}}\tabularnewline
\toprule
\vbox{\textsc{Auspicious Statue/deities}} & \vbox{\textsc{Moved from}} & \vbox{\textsc{Moved
to/resides in}} & \vbox{\textsc{Sources/remarks}} \\
\midrule
\endfirsthead
\toprule
\vbox{\textsc{Auspicious Statue/deities}} & \vbox{\textsc{Moved from}} & \vbox{\textsc{Moved
to/resides in}} & \vbox{\textsc{Sources/remarks}} \\
\midrule
\endhead
\end{longtable}

What issues did you notice?

Similarly, \vcenter should work for vertical centering, but it complained about missing $ in my case.

I actually think bottom alignment is nice, but I see that some people prefer vertical centering. My idea was mainly to restore the previous behaviour.

@jgm
Copy link
Owner

jgm commented Jun 4, 2021

\vbox fails when the content gets longer.
(the cells become too wide)

@frederik-elwert
Copy link
Contributor Author

Oh, yes, I see. Unfortunately, I couldn’t find an easier non-minipage solution. (Some seem to use a fake one-cell \multicolumn, but that also didn’t work for me.)

Are there major problems with minipage in this case? (I agree the current code is simpler/prettier, but it’s also a significant change in behaviour.)

@jgm
Copy link
Owner

jgm commented Jun 5, 2021

I don't think there's a big problem using minipage.
That's probably the thing to do if there is no alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants