Me gustaría que las fórmulas de la tercera columna estuvieran alineadas verticalmente hacia el medio, es decir, las fórmulas deberían estar verticalmente en el medio de las dos líneas de las descripciones.
\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}
Respuesta1
Aquí una solución basada en la redefinición del X
tipo de columna y dos posibles trucos para la primera columna (es posible que deban adaptarse al contenido 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}
Respuesta2
Esto es bastante difícil: el problema es que desea alinear el cuadro del medio de dos maneras: a la izquierda a lo largo de la línea de base, a la derecha a lo largo del centro. Este tipo de tabla normalmente requiere anidar tablas (lo cual es difícil con tabularx) o medir parte del contenido para usar trucos \llap.
Aquí nos falta un código tabular basado en xcoffins que tiene más de un 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}
Respuesta3
Como esto:
Editar:
La posición del contenido de las columnas está determinada por la línea base de la fila, que (desafortunadamente) no se puede cambiar de una columna a otra.
Hasta ahora no veo otra posibilidad que usar cuadros en la última o en la primera columna, que alinean su línea de base. Un buen candidato para su caso particular es \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 una escritura más cómoda de la tabla, puede definir un nuevo tipo de columna:
\newcolumntype{E}{>{\begin{adjustbox}{valign=t}$}c<{$\end{adjustbox}}}
y luego escribe la tabla (cuerpo) 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}
Si el texto en las celdas de la columna del medio tiene un número arbitrario de líneas, o si la ecuación tiene solo una línea, el resultado es peor. En tal caso, una posible solución es usar multirow
en la primera columna y ajustar manualmente el número de columnas que abarcan esas celdas, y en la segunda columna establecer la línea de base en el medio 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}
o utilice la solución propuesta en la respuesta de @Bernard.
Respuesta4
Para tener una imagen completa de las posibilidades, incluyo una tabla tipográfica con la ayuda decalorías. Es muy fácil tener tales alineaciones usando un archivo calstable
. He eliminado los cojinetes del lado izquierdo y derecho, que agregan código, que no es estrictamente necesario para crear la tabla de 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}