How to trim the left and right white spaces when a table is previewed?

The following table has unwanted right and left white spaces. But you cannot see them because the figure has been converted to PNG with alpha channel enabled.

How to trim the left and right white spaces when a table is previewed?

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs,longtable,array}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{longtable}

\begin{document}
\begin{longtable}{*3{m{\dimexpr0.5\linewidth/3\relax}}}
\toprule
Unit & Macro & Symbol\\
\midrule
ampere & \verb|\ampere| & \si{\ampere}\\
candela & \verb|\candela|& \si{\candela}\\
kelvin & \verb|\kelvin|& \si{\kelvin}\\
kilogram & \verb|\kilogram|& \si{\kilogram}\\
meter & \verb|\meter|& \si{\meter}\\
mole & \verb|\mole|& \si{\mole}\\
second & \verb|\second|& \si{\second}\\
\bottomrule
\end{longtable}
\end{document}


Note that I am not talking about the white spaces that can be removed by @{}s. The unwanted white spaces can be understood if you compile my MWE.

-
Not an answer to the question, but I would suggest using an s coulmn for the units. You might also want to define a function which prints the name and the unit, as I do in the siunitx manual, to avoid repeating material in your source. –  Joseph Wright Aug 5 '12 at 8:38
@JosephWright: I agree. I am very keen on applying the DRY (Don't Repeat Yourself) philosophy to my daily projects. :-) Thanks! –  Stiff Jokes Aug 5 '12 at 8:46

Implicit change from longtable to tabular

In simple cases, where the use of longtable does not contain more than tabular would allow, the longtable environment could be redefined to be a tabular environment:

\ifPreview
\let\longtable\tabular
\let\endlongtable\endtabular
\fi
\PreviewEnvironment{longtable}


Anyway, the longtable is not broken across pages, when taken as preview element. Also other features of longtable will not work, e.g. \endfoot.

Adjusting \hsize

The longtable environment sets chunks with width \hsize, filled left with \LTleft and on the right side with \LTright. The widths of the columns are remembered in the .aux file. The latter data can be used to calculate the width of the table. Then \hsize is set to the total width. \linewidth can remain unchanged, it is not used in longtable.

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs,longtable,array}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt

\makeatletter
\ifPreview
\newcommand*{\SetLongtableWidth}{%
\begingroup
\edef\@ltnum{\@roman\numexpr\value{LT@tables}+1}%
\@ifundefined{LT@\@ltnum}{%
\gdef\@ltwidth{0pt}%
}{%
\def\LT@entry##1##2{+##2}%
\xdef\@ltwidth{\the\dimexpr 0pt\csname LT@\@ltnum\endcsname}%
}%
\endgroup
\ifdim\@ltwidth>\z@
\hsize=\@ltwidth\relax
\fi
}%
\newcommand{\org@longtable}{}%
\let\org@longtable\longtable
\def\longtable{\SetLongtableWidth\org@longtable}%
\fi
\makeatother

\PreviewEnvironment{longtable}

\begin{document}
\begin{longtable}{*3{m{\dimexpr0.5\linewidth/3\relax}}}
\toprule
Unit & Macro & Symbol\\
\midrule
ampere & \verb|\ampere| & \si{\ampere}\\
candela & \verb|\candela|& \si{\candela}\\
kelvin & \verb|\kelvin|& \si{\kelvin}\\
kilogram & \verb|\kilogram|& \si{\kilogram}\\
meter & \verb|\meter|& \si{\meter}\\
mole & \verb|\mole|& \si{\mole}\\
second & \verb|\second|& \si{\second}\\
\bottomrule
\end{longtable}
\end{document}

-

\begin{document}
\begin{longtable}{@{}*3{m{\dimexpr0.5\linewidth/3\relax}}@{}}
\toprule
etc.
\midrule
etc
\bottomrule
\end{longtable}
\end{document}

-
The unwanted white spaces I am talking about are not what you said above. –  Stiff Jokes Aug 5 '12 at 7:07
\renewcommand \PreviewBbAdjust {2.4cm -\PreviewBorder -2.4cm \PreviewBorder}