1

I'm trying to make a table with the headers bottom justified, and the rest top justified. I can get the headers right, but when I try to top justify any of the remaining rows, it messes up the headers. I'd like to do it in Lyx, because the actual table I'm using is rather large with long text, and it is much easier in a table editor. Here's a MWE:

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
\usepackage{makecell,}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadalign{lb}

\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}

\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\newcolumntype{M}{>{\varwidth[t]{3cm}}l<{\endvarwidth}}
\end_preamble
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 0in
\topmargin 0.5in
\rightmargin 0in
\bottommargin 0.5in
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
begin{centering}
\backslash
ra{1.3}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Tabular
<lyxtabular version="3" rows="2" columns="8">
<features booktabs="true" tabularvalignment="middle">
<column alignment="left" valignment="top" width="1.5in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="left" valignment="top" width="1.5in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<row>
<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
One Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
Three Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
Three Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
2 Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
One Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
2 Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
2 Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
Three Line Heading
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Two line text that is top aligned
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Three line text that is top aligned that wraps around and keeps going
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Three Lines of Text
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Two Lines
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
end{centering}
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\end_layout

\end_body
\end_document

Here's the result:

enter image description here

Note that the two wider columns are left-justified. In one version of the document, on one table, I was able to top justify everything, and hit <Ctrl-Enter> above headings that needed moving down, but currently, it just eats those characters :/. Putting a vertical space above the titles didn't yield the right result either. Here's somebody doing the same thing, but not in Lyx:

tables - Tabular individual vertical alignment in header row with varwidth columns - TeX - LaTeX Stack Exchange

However, if I add the following to the preamble:

\usepackage{makecell,}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadalign{lb}

\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}

\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\newcolumntype{M}{>{\varwidth[t]{3cm}}l<{\endvarwidth}}

and add the ERT \ra{1.3} just above the table, and top-justify the data row, the header row is top-justified, too. This probably has to do with the fact that Lyx doesn't mark headers with the \thead environment. It is not possible to add ERT before and after a single row in Lyx (without specifying the thole table as ERT). It is not a good general solution to bottom-justify the tallest cells, as suggested on their wiki: LyX wiki | LyX / Tables, since 1) the tallest cells alone aren't enough, and one must bottom justify the one and two line cells to bottom justify the whole row; and 2) by the time you bottom justify the one and two line header cells you need to, and top justify the one and two line cells in the rest of the table you need to, you've specified different vertical alignments for the same column - thereby messing up the header row.

Since some people, such as myself, will be happy to have headers on all tables, ideally, someone might find a solution that applies to all tables. I would also be happy to add code to each table to make this happen. It would be nice to have a document-wide and a table-specific solution, if both can be readily worked out, for both types of usages; but a table-specific solution alone would be great, in and of itself.

1 Answer 1

1

Here's one answer, but it's a hack, and doesn't display fully right. You can break your table up into two tables, and make them exactly abut. Sometimes when I've tried to do this, I wound up with a weird indentation of one of the tables I couldn't clear, but undoing and redoing it again, carefully checking that the paragraph indentation was cleared at each point, allowed me to do it. Here's a MWE:

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 0in
\topmargin 0.5in
\rightmargin 0in
\bottommargin 0.5in
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
begin{centering}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Tabular
<lyxtabular version="3" rows="1" columns="8">
<features booktabs="true" tabularvalignment="middle">
<column alignment="left" valignment="bottom" width="1.5in">
<column alignment="center" valignment="bottom" width="0.6in">
<column alignment="center" valignment="bottom" width="0.6in">
<column alignment="center" valignment="bottom" width="0.6in">
<column alignment="left" valignment="bottom" width="1.5in">
<column alignment="center" valignment="bottom" width="0.6in">
<column alignment="center" valignment="bottom" width="0.6in">
<column alignment="center" valignment="bottom" width="0.6in">
<row>
<cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
One Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
Three Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
Three Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
2 Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
One Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
2 Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
2 Line Heading
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
\noindent

\series bold
Three Line Heading
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Tabular
<lyxtabular version="3" rows="1" columns="8">
<features booktabs="true" tabularvalignment="middle">
<column alignment="left" valignment="top" width="1.5in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="left" valignment="top" width="1.5in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<column alignment="center" valignment="top" width="0.6in">
<row>
<cell alignment="left" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Two line text that is top aligned
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="left" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Three line text that is top aligned that wraps around and keeps going
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Three Lines of Text
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
One
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" bottomline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Two Lines
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
end{centering}
\end_layout

\end_inset


\end_layout

\end_body
\end_document

Here's the result:

Table Vertical Alignment One Solution.png

Note that the only difference from the desired result, is that the mid line below the header is as heavy as the top lines, whereas it should be a little lighter. Livable, but not optimal. If you add a \midrule control sequence between the tables, it gives you an warning, from which you must display the PDF anyway, and then produces a result - but I also haven't got the midrule to be the right width and position. You cannot set the heaviness of a border in Lyx.

Also note that the \centering environment is necessary for this solution, because if you choose Paragraph Settings | Center for the whole table, the \center tag gratuitously adds some non-optional whitespace between the two tables.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .