I was creating a pseudocode/JavaScript comparison table, and wanted to typeset algorithms written with the algorithm2e package vertically centered in table cells. Out-of-the box, algorithm2e can't do this, but I modded the code, and everything but one point seems to be working. That's this: algorithm2e normally places pseudocode lines in boxes out to \hsize, but in the table context I want their natural size, so I used the varwidth environment. And that has broken the vertical centering.
MWE:
\documentclass{article}
\usepackage{varwidth}
\newcommand{\verticalcenter}[1]{\raisebox{-0.5\height}{#1}}
\begin{document}
\begin{tabular}{ll}
\hline
\verticalcenter{%
\begin{varwidth}{\hsize}%
text\par
text\par
text\par
\end{varwidth}%
}&\verticalcenter{\rule{1cm}{1pt}}\\
\hline
\end{tabular}
\end{document}
This produces:
where the centerline is well above the center of the text.
I tried to dive in the varwidth code, but nothing is jumping out at me. How can I fix the varwidth's dimensions?