# standalone class would not crop AMS equations properly (left and top margin space remains)

I have the following simple code that I thought would output the AMS "gather" equation properly cropped at all sides up to the point where an imaginary straight line drawn at each side would touch the contents of the equation (enclosing it in imaginary box without leaving any spaces). But for some reason there is a big uncropped space on the left and top sides as well as a little one at the right side.

\documentclass[fleqn,varwidth]{standalone}
\usepackage{amsmath}

\begin{document}
\begin{gather*}
2^{1}=\binom{1}{0}+\binom{1}{1}\\
2^{2}=\binom{2}{0}+\binom{2}{1}+\binom{2}{2}
\end{gather*}
\end{document}


Here I highlight the spaces I don't want standalone class to output

Your help with modifying the code to make this unwanted spaces go away is greatly appreciated.

Thanks

I think you need an output that does not span across multiple page then converting displayed equations to inline equations.

\documentclass[margin=1pt]{standalone}
\usepackage{amsmath}

\begin{document}
$\! \begin{gathered} 2^{1}=\binom{1}{0}+\binom{1}{1}\\ 2^{2}=\binom{2}{0}+\binom{2}{1}+\binom{2}{2} \end{gathered}$
\end{document}


Notes:

• margin of 1 pt is optionally added, remove it if you do not need it.

• \! is important to remove the unnecessary whitespace.

• use \displayequation after the opening  if you need displayed version of "font". The above is for gathered, for aligned see the following. \documentclass[margin=1pt]{standalone} \usepackage{amsmath} \begin{document}\!
\begin{aligned}
2^{1}&=\binom{1}{0}+\binom{1}{1}\\
2^{2}&=\binom{2}{0}+\binom{2}{1}+\binom{2}{2}
\end{aligned}
\$
\end{document}


• Thank you for responding. It looks exactly how I wanted but your solution does not work with amsmath environments and I'm afraid this may impinge on the functionality somewhere down the road. Can you modify it to work with amsmath? Thanks – Ben Oct 10 '16 at 0:34
• @Ben -- the examples shown in this answer are processed with amsmath. i think it's necessary to know what versions of all packages both you and @SingleFighter are using. the most likely reason this isn't working for you is an "old" version of something, or possibly the use of varwidth, which is not used in this answer. – barbara beeton Oct 10 '16 at 0:58
• I used TeX Live 2016 with the latest update. – The Shortest Mustache Theorem Oct 10 '16 at 2:00
• OK, I had to take a look at amsmath documentation to learn that "aligned" is actually a version of "align" that does not span the full line (I didn't know that). That was the problem. Thank you. – Ben Oct 10 '16 at 3:49

You can do it with a TABstack, using the new and improved tabstackengine package (2016-10-04).

\documentclass[varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tabstackengine}[2016-10-04]
\TABstackMath
\TABstackMathstyle{\displaystyle}
\setstackgap{S}{6pt}
\begin{document}
\alignShortstack{
2^{1}=&\binom{1}{0}+\binom{1}{1}\\
2^{2}=&\binom{2}{0}+\binom{2}{1}+\binom{2}{2}
}\!
\end{document}


• @Ben you need to update your tabstackengine version to the one released last week. ctan.org/pkg/tabstackengine (might as well also do ctan.org/pkg/stackengine) – Steven B. Segletes Oct 10 '16 at 0:49
• I did not know the new version has been released recently. As soon as I update (probably tomorrow) I will let you know if your solution works for me too. Thank you. – Ben Oct 10 '16 at 3:53