[Tex/LaTex] How to vertically center `\begin{equation}…\end{equation}` in a table cell

equationsvertical alignment

How to vertically center \begin{equation}...\end{equation} in a table cell?

alt text

Minimal Code (I cannot minimize anymore)

\documentclass{article}
\usepackage{array,longtable,calc,amsmath}

\newcolumntype{A}[1]{%
    >{\begin{minipage}{#1\linewidth-2\tabcolsep-1.5\arrayrulewidth}\vspace{\tabcolsep}}%
    c%
    <{\vspace{\tabcolsep}\end{minipage}}%
}

\begin{document}
\begin{longtable}{|*2{A{0.5}|}}
\hline
\begin{equation}
  \sin x \cos x = y
\end{equation}
& \hrulefill \tabularnewline\hline
\end{longtable}
\end{document}

Best Answer

To get correct spacing, put a \strut before and after the display, and give the two shortdisplayskips the same value.

\documentclass{article}
\usepackage{array,longtable,calc,amsmath}

\tabcolsep=1pt
\arrayrulewidth=1pt

\newcolumntype{A}[1]{%
    >{\begin{minipage}{#1\linewidth-2\tabcolsep-1.5\arrayrulewidth}\vspace{\tabcolsep}}%
    c%
    <{\vspace{\tabcolsep}\end{minipage}}%
}

\begin{document}
\begin{longtable}{|*2{A{0.5}|}}
\hline
\setlength\abovedisplayshortskip{0pt}
\setlength\belowdisplayshortskip{0pt}
\strut
\begin{equation}
  \sin x \cos x = y
\end{equation}
\strut
& \hrulefill \tabularnewline\hline
\end{longtable}
\end{document}

You can change the shortdisplayskips according to your needs; negative values are possible, too.