在 Lyx 中,怎样才能使表格标题下对齐,其余部分上对齐?

在 Lyx 中,怎样才能使表格标题下对齐,其余部分上对齐?

我正在尝试制作一个表格,其中标题下对齐,其余部分上对齐。我可以正确设置标题,但是当我尝试将任何剩余行上对齐时,标题会变得混乱。我想在 Lyx 中执行此操作,因为我使用的实际表格相当大,并且文本很长,在表格编辑器中执行此操作要容易得多。以下是 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

结果如下:

在此处输入图片描述

请注意,两个较宽的列是左对齐的。在文档的一个版本中,在一个表格上,我能够将所有内容对齐,并在需要向下移动的标题上方按 <Ctrl-Enter>,但目前,它只会吃掉这些字符 :/。在标题上方放置垂直空间也没有产生正确的结果。这里有人做同样的事情,但不是在 Lyx 中:

表格 - 带有可变宽度列的标题行中的表格单独垂直对齐

但是,如果我在序言中添加以下内容:

\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}}

并在表格上方添加 ERT \ra{1.3},并使数据行顶部对齐,标题行也会顶部对齐。这可能与 Lyx 不使用\thead。在 Lyx 中,无法在单行之前和之后添加 ERT(不将整个表格指定为 ERT)。将最高的单元格底部对齐并不是一个好的通用解决方案,正如他们的 wiki 上所建议的那样:LyX 维基百科 | LyX / 表格,因为 1)最高的单元格本身是不够的,必须从底部对齐两行单元格使整行底部对齐;2)当您底部对齐您需要的一行和两行标题单元格,并顶部对齐您需要的其余表格中的一行和两行单元格时,您已经为同一列指定了不同的垂直对齐方式 - 从而弄乱了标题行。

因为有些人(比如我自己)很乐意在所有表格上添加标题,所以理想情况下,有人可能会找到适用于所有表格的解决方案。我也很乐意向每个表格添加代码来实现这一点。如果两者都可以轻松解决,那么最好有一个文档范围的解决方案和一个表格特定的解决方案,用于这两种用途;但仅表格特定的解决方案本身就很棒了。

答案1

这是一个答案,但它是一种黑客行为,并且无法完全正确显示。您可以将表格分成两个表格,并使它们完全相邻。有时当我尝试这样做时,我会得到一个我无法清除的表格的奇怪缩进,但撤消并重新执行它,仔细检查每个点的段落缩进是否被清除,让我能够做到这一点。这是一个 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

结果如下:

表格垂直对齐一解.png

请注意,与期望结果的唯一区别是,标题下方的中间线与顶部线一样粗,而实际上应该稍微细一点。可以接受,但不是最佳选择。如果您\midrule在表格之间添加控制序列,它会向您发出警告,您必须从中显示 PDF,然后生成结果 - 但我还没有得到正确的宽度和位置的中间规则。您无法在 Lyx 中设置边框的粗细。

还要注意,\centering环境对于此解决方案是必需的,因为如果您为整个表格选择“段落设置”|“中心”,则标签\center会在两个表格之间免费添加一些非可选的空白。

相关内容