3 列目の数式を中央に垂直に揃えたいと思います。つまり、数式は説明の 2 行の中央に垂直に配置する必要があります。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{caption}
\begin{document}
\begin{table}[htb]
\centering
\caption{I would like the formulae here to be vertically at the middle of the two lines of text}
\begin{tabularx}{\linewidth}{lX>{$}c<{$}}
\toprule
Name & Description & \multicolumn{1}{c}{Formula}\\
\midrule
Ducks & Something which goes on two lines, something which goes on two lines &
A=\dfrac{B}{C}\\
Lions & Something which goes on two lines, something which goes on two lines &
D=\dfrac{E}{F}\\
\bottomrule
\end{tabularx}
\end{table}
\begin{table}[htb]
\centering
\caption{Here the formulae are correctly aligned with the description, but I would like the name at the top like in the previous table}
\begin{tabular}{lm{24em}>{$}c<{$}}
\toprule
Name & Description & \multicolumn{1}{c}{Formula}\\
\midrule
Ducks & Something which goes on two lines, something which goes on two lines &
A=\dfrac{B}{C}\\
Lions & Something which goes on two lines, something which goes on two lines &
D=\dfrac{E}{F}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答え1
ここでは、列タイプの再定義に基づくソリューションX
と、最初の列に対する 2 つの可能なハックを示します (実際の内容に合わせて調整する必要がある可能性があります)。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx, booktabs, makecell}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
\begin{table}[htb]
\centering
\begin{tabularx}{\linewidth}{lX>{$}c<{$}}
\toprule
Name & Description & \multicolumn{1}{c}{Formula}\\
\midrule
\makecell[l]{Ducks\\\mbox{}} & Something which goes on two lines, something which goes on two lines &
A=\dfrac{B}{C}\\
\addlinespace
\makecell[l]{Lions\\\mbox{}} & Something which goes on two lines, something which goes on two lines &
D=\dfrac{E}{F}\\
\addlinespace
\raisebox{1.4ex}{Lions} & Something which goes on two lines, something which goes on two lines &
D=\dfrac{E}{F}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答え2
これはかなり難しいです。問題は、中央のボックスを 2 つの方法で揃えたいということです。左側はベースラインに沿って、右側は中央に沿ってです。このタイプのテーブルでは、通常、テーブルをネストするか (tabularx では困難)、コンテンツの一部を測定して \llap トリックを使用する必要があります。
複数のハンドルを持つ xcoffins に基づく表形式のコードがここにありません...
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{caption,xcoffins}
\newlength\colA
\begin{document}
\begin{table}[htb]
\centering
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\settowidth\colA{\begin{tabular}{l}Name\\Ducks\\Lions\end{tabular}}
\caption{I would like the formulae here to be vertically at the middle of the two lines of text}
\begin{tabularx}{\linewidth}{p{\dimexpr\colA-2\tabcolsep}X>{$}c<{$}}
\toprule
Name & Description & \multicolumn{1}{c}{Formula}\\
\midrule
&\leavevmode\llap{\makebox[\colA][l]{Ducks}}Something which goes on two lines, something which goes on two lines &
A=\dfrac{B}{C}\\
&\leavevmode\llap{\makebox[\colA][l]{Lions}}Something which goes on two lines, something which goes on two lines and on one more line and on one more line and on one more line &
D=\dfrac{E}{F}\\
\bottomrule
\end{tabularx}
\end{table}
%Only for show some coffin code:
\NewCoffin\CoffinA
\NewCoffin\CoffinB
\NewCoffin\CoffinC
\SetHorizontalCoffin\CoffinA{Ducks}
\SetHorizontalCoffin\CoffinC{$D=\dfrac{E}{F}$}
\SetVerticalCoffin\CoffinB{\dimexpr \textwidth-\CoffinWidth\CoffinA-\CoffinWidth\CoffinC-6\tabcolsep}{\noindent Something which goes on two lines, something which goes on two lines and on one more line and on one more line and on one more line}
\JoinCoffins\CoffinA[H,r]\CoffinB[T,l](2\tabcolsep,0pt)
\JoinCoffins\CoffinA[vc,r]\CoffinC[vc,l](2\tabcolsep,0pt)
\noindent\hspace*{\tabcolsep}\TypesetCoffin\CoffinA
\end{document}
答え3
このような:
編集:
列の内容の位置は行のベースラインによって決定されますが、残念ながら列ごとに変更することはできません。
今のところ、ベースラインを揃えるボックスを最後の列か最初の列のいずれかで使用する以外に方法はないようです。あなたの特定のケースに適した候補は次のとおりです\adjustbox
。
\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx,booktabs}
\usepackage{caption}
\usepackage{adjustbox}
\begin{document}
\begin{table}[htb]
\centering
\caption{I would like the formulae here to be vertically at the middle of the two lines of text}
\begin{tabularx}{\linewidth}{lXc}
\toprule
Name & Description & Formula \\
\midrule
Ducks & Something which goes on two lines, something which goes on two lines &
\adjustbox{valign=t}{$A=\dfrac{B}{C}$}\\
Lions & Something which goes on two lines, something which goes on two lines &
\adjustbox{valign=t}{$D=\dfrac{E}{F}$}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
テーブルの書き込みをより便利にするために、新しい列タイプを定義できます。
\newcolumntype{E}{>{\begin{adjustbox}{valign=t}$}c<{$\end{adjustbox}}}
そして、テーブル(本体)を次のように記述します。
\begin{tabularx}{\linewidth}{lXE}
\toprule
Name & Description & Formula \\
\midrule
Ducks & Something which goes on two lines, something which goes on two lines &
A=\dfrac{B}{C}\\
Lions & Something which goes on two lines, something which goes on two lines &
D=\dfrac{E}{F}\\
\bottomrule
\end{tabularx}
中央の列のセルのテキストの行数が不定の場合、または数式が 1 行しかない場合は、結果が悪くなります。このような場合の解決策としては、multirow
最初の列で を使用し、それらのセルがまたがる列の数を手動で調整し、2 番目の列で垂直中央にベースラインを設定することが考えられます。
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs, multirow, tabularx}
\usepackage{caption}
\usepackage{adjustbox}
\usepackage{lipsum}
\begin{document}
\begin{table}[htb]
\centering
\renewcommand\tabularxcolumn[1]{m{#1}} % <---
\caption{I would like the formulae here to be vertically at the middle of the two lines of text}
\begin{tabularx}{\linewidth}{lX>{$}c<{$}}
\toprule
Name & Description & Formula \\
\midrule
\multirow{-6}{*}{Ducks} % <--- manually adjusted
& \lipsum[66] & A=\dfrac{B}{C}\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
または、@Bernard の回答で提案されている解決策を使用します。
答え4
可能性を完全に把握するために、私は以下の助けを借りてタイプセットした表を掲載します。cals. を使用すると、このような配置を簡単に行うことができますcalstable
。OP のテーブルを作成するために厳密に必要ではないコードを追加する左側と右側のベアリングを削除しました。
\documentclass{article}
\usepackage{cals, caption, amsmath}
\usepackage{lmodern}
\begin{document}
\begin{table*}
\caption{I would like the formulae here to be vertically at the middle of the two lines of text}
\begin{calstable}[c]
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/6\relax}
{\dimexpr(\columnwidth)/6*4\relax}
{\dimexpr(\columnwidth)/6\relax}
}
% Set up the tabular
\makeatletter
\def\cals@framers@width{0.8pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@bodyrs@width{0.6pt}
\def\cals@cs@width{0pt} % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.4pt}
\def\bb{\ifx\cals@borderB\relax % Botton border switch (off-on)
\def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}
\def\lp{\ifdim\cals@paddingL=0.0pt\relax % Left padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingL}{0pt}\fi}
\def\rp{\ifdim\cals@paddingR=0.0pt\relax % Right padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingR}{0pt}\fi}
% R1H1
\thead{\small%
\brow
\lp\alignL\cell{Name}\lp
\alignL\cell{Description}
\rp\alignR\cell{Formula}\rp
\erow
\normalsize%
}
\tfoot{\lastrule\strut}
%R2B1
\brow
\lp\bb\alignL\cell{Ducks}\lp
\alignL\cell{Something which goes on two lines, something which goes on two lines}
\rp\alignR\cell{\vfil$A=\dfrac{B}{C}$}\rp
\erow
%R3B2
\brow
\bb\lp\alignL\cell{Gnus}\lp
\alignL\cell{Something which goes on two lines, something which goes on two lines and on one more line and on one more line and on one more line}
\rp\alignR\cell{\vfil$D=\dfrac{E}{F}$}\rp\bb
\erow
%R4B3
\brow
\lp\alignL\cell{Gnats}\lp
\alignL\cell{Something which goes on two lines, something which goes on two lines and on one more line and on one more line and on one more line}
\rp\alignR\cell{\vfil $D=\dfrac{E}{F}$}\rp
\erow
\makeatletter
\end{calstable}\par
\end{table*}
\end{document}