我怎样才能仅将标题行底部对齐?有没有办法使用 \rowstyle 或类似的东西来实现这一点,就像我所做的那样,让整行都对齐 \bf?
我不想使用多个表格。
(\documentclass{article}
\usepackage{varwidth}
\usepackage{booktabs}
\usepackage{array}
\usepackage[aboveskip=1pt,labelfont=bf,labelsep=period,justification=raggedright,singlelinecheck=off]{caption}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\begin{document}
\begin{table}
\caption{\newline Weight regulation: long-term clinical trials}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\ra{1.3}
\newcolumntype{M}{>{\begin{varwidth}[t]{3cm}}l<{\end{varwidth}}}
\begin{tabular}{@{}$M^M^M@{}}\toprule
\rowstyle{\bf\raggedbottom}
First Author \newline Year \newline Country & Bottom & Bottom \tabularnewline
\midrule
\rowstyle{\raggedright}
This needs to be on top as it is& Also this one& And this
\tabularnewline
\bottomrule
\end{tabular}
\begin{flushleft} Text in bottom of table.
\end{flushleft}
\label{table1}
\end{table}
\end{document}
编辑:文本没有用下面提出的解决方案换行,但这不是标题行中最重要的事情,因为可以使用 \\ 或 \cr 来解决这个问题。
答案1
我提出了一个不需要 \rowstyle
第一行的解决方案。该makecell
包允许在单元格中换行,并使用 \thead, \makecell
和其他一些命令进行通用格式化。
此外,表格底部的标题和文本将使用整个\linewidth
,这可能不是您想要的。无法检测到它们,因为它们不够长。我建议使用包threeparttable
,将其宽度限制为实际表格宽度。
\documentclass{article}
\usepackage{varwidth}
\usepackage{booktabs}
\usepackage{array}
\usepackage[aboveskip=1pt,labelfont=bf,labelsep=period, justification=raggedright,singlelinecheck=off, labelsep=newline, skip=1ex]{caption}
\usepackage{makecell,}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadalign{lb}
\usepackage[flushleft]{threeparttable}
\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}}
\begin{document}
\begin{table}
\begin{threeparttable}
\caption{Weight regulation: long-term clinical trials. Some more text}
\ra{1.3}
\begin{tabular}{@{}$M^M^M@{}}
\toprule
%\rowstyle{\bfseries\normalsize\raggedbottom}
\thead{First Author \\ Year \\ Country} &\thead{Bottom} & \thead{Bottom} \tabularnewline
\midrule
\rowstyle{\raggedright}
This needs to be on top as it is & Also this one & And this \tabularnewline
\addlinespace
\midrule[\heavyrulewidth]
\end{tabular}
\begin{tablenotes} \item[\hspace*{-\fontdimen2\font}] Text in bottom of table. Text in bottom of table. Text in bottom of table. Text in bottom of table.
\end{tablenotes}
\label{table1}
\end{threeparttable}
\end{table}
\end{document}
答案2
{NiceTabular}
这是带有 的解决方案nicematrix
(版本 ≥ 6.3,2021-10-18)。列V
是V
定义varwidth
(并受 支持的nicematrix
)的 -columns。
\documentclass{article}
\usepackage{nicematrix,booktabs,varwidth}
\usepackage[aboveskip=1pt,labelfont=bf,labelsep=period, justification=raggedright,singlelinecheck=off, labelsep=newline, skip=1ex]{caption}
\begin{document}
\begin{table}
\caption{Weight regulation: long-term clinical trials.}
\begin{NiceTabular}
[tabularnote = Text in bottom of table. Text in bottom of table.
Text in bottom of table. Text in bottom of table.]
{@{}p[l]{3cm}V{3cm}V{3cm}@{}}
\toprule
\RowStyle{\bfseries}
\Block[b]{}{First Author\\ Year\\ Country}
& Bottom & Bottom \\
\midrule
This needs to be on top as it is & Also this one & And this \\
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。
答案3
可以将所需元素放入 中\Longstack
,但我不得不添加一个额外的组,可能是因为它包含在环境中varwidth
。总而言之,我将其添加到序言中
\usepackage{stackengine}
\setstackEOL{\cr}
\renewcommand\stackalignment{l}
获得左对齐堆栈,使用\cr
作为行分隔符。然后,在 中tabular
,我将其用作条目:
{\Longstack{First Author\cr Year\cr Country}}
这是 MWE。
\documentclass{article}
\usepackage{varwidth}
\usepackage{booktabs}
\usepackage{array}
\usepackage[aboveskip=1pt,labelfont=bf,labelsep=period,justification=raggedright,singlelinecheck=off]{caption}
\usepackage{stackengine}
\setstackEOL{\cr}
\renewcommand\stackalignment{l}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\begin{document}
\begin{table}
\caption{\newline Weight regulation: long-term clinical trials}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\ra{1.3}
\newcolumntype{M}{>{\begin{varwidth}[t]{3cm}}l<{\end{varwidth}}}
\begin{tabular}{@{}$M^M^M@{}}\toprule
\rowstyle{\bf\raggedbottom}
{\Longstack{First Author\cr Year\cr Country}}& Bottom & Bottom \tabularnewline
\midrule
\rowstyle{\raggedright}
This needs to be on top as it is& Also this one& And this
\tabularnewline
\bottomrule
\end{tabular}
\begin{flushleft} Text in bottom of table.
\end{flushleft}
\label{table1}
\end{table}
\end{document}