Gostaria que as fórmulas da terceira coluna estivessem alinhadas verticalmente ao meio, ou seja, as fórmulas deveriam ficar verticalmente no meio das duas linhas das descrições.
\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}
Responder1
Aqui está uma solução baseada na redefinição do X
tipo de coluna, e dois hacks possíveis para a primeira coluna (podem ter que ser adaptados ao conteúdo real):
\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}
Responder2
Isto é bastante difícil: o problema é que você deseja alinhar a caixa do meio de duas maneiras: à esquerda ao longo da linha de base, à direita ao longo do centro. Este tipo de tabela normalmente requer aninhamento de tabelas (o que é difícil com tabularx) ou medição de parte do conteúdo para usar truques do \llap.
Estamos faltando aqui o código tabular baseado em xcoffins que possui mais de um identificador ...
\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}
Responder3
Assim:
Editar:
A posição do conteúdo das colunas é determinada pela linha de base da linha, que (infelizmente) não pode ser alterada de coluna para coluna.
Até agora não vejo outra possibilidade a não ser usar caixas na última ou na primeira coluna, que alinham sua linha de base. Um bom candidato para o seu caso específico é \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}
Para uma escrita mais conveniente da tabela, você pode definir um novo tipo de coluna:
\newcolumntype{E}{>{\begin{adjustbox}{valign=t}$}c<{$\end{adjustbox}}}
e então escreva a tabela (corpo) como:
\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}
Se o texto nas células da coluna do meio tiver um número arbitrário de linhas, ou se a equação tiver apenas uma linha, o resultado será pior. Nesse caso, uma solução possível é usar multirow
na primeira coluna e ajustar manualmente o número de colunas que essas células abrangem, e na segunda coluna definir a linha de base no meio vertical:
\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}
ou use a solução proposta na resposta de @Bernard.
Responder4
Para ter uma visão completa das possibilidades, incluo uma tabela composta com a ajuda dechamadas. É muito fácil ter esses alinhamentos usando um arquivo calstable
. Removi os rolamentos dos lados esquerdo e direito, que adicionam código, não estritamente necessário para a criação da tabela do 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}