[Tex/LaTex] How to adjust space between columns in longtable environment

longtablespacingtables

In the regular tabular environment, we can use \setlength{\tabcolsep} to specify the size of the space between the columns, but this doesn't work in longtable. Is there a similar command?

\documentclass[12pt]{article}    
\usepackage{longtable} 


\begin{document}
\begin{longtable}{rl}
\setlength{\tabcolsep}{2pt}
2: $x^3$&= $6x^2-4x-16$ \\
4: $x^5$ &= $6x^4-8x^3+8x^2-16x-64$ \\
6: $x^9$ &= $6x^8-4x^7-24x^6+48x^5-32x^4-64x^3-384x^2+256x+1024 $ \\
8: $x^{15}$ &=$6x^{14}-4x^{13}-16x^{12}-32x^{11}+192x^{10}-128x^{9}-512x^8+512x^7$\\
&$\hspace{.25cm}-3072x^6+2048x^5+8192x^4+4096x^3-24576x^2+16384x+65536$
\end{longtable}

\end{document}

Best Answer

You need to set the length before entering longtable just as you would set it before tabular. However note that as set you have = being set out of math mode so getting incorrect spacing. The second example shows = set in math mode with mathrel spacing. Finally a suggestion not to use longtable at all but a dedicated math display environment such as align.

enter image description here

\documentclass[12pt]{article}    
\usepackage{longtable,amsmath} 


\begin{document}
{\setlength{\tabcolsep}{2pt}
\begin{longtable}{rl}
2: $x^3$&= $6x^2-4x-16$ \\
4: $x^5$ &= $6x^4-8x^3+8x^2-16x-64$ \\
6: $x^9$ &= $6x^8-4x^7-24x^6+48x^5-32x^4-64x^3-384x^2+256x+1024 $ \\
8: $x^{15}$ &=$6x^{14}-4x^{13}-16x^{12}-32x^{11}+192x^{10}-128x^{9}-512x^8+512x^7$\\
&$\hspace{.25cm}-3072x^6+2048x^5+8192x^4+4096x^3-24576x^2+16384x+65536$
\end{longtable}
}


\begin{longtable}{l@{:\qquad}r@{}l}
2& $x^3$&${}= 6x^2-4x-16$ \\
4& $x^5$ &${}= 6x^4-8x^3+8x^2-16x-64$ \\
6& $x^9$ &${}= 6x^8-4x^7-24x^6+48x^5-32x^4-64x^3-384x^2+256x+1024 $ \\
8& $x^{15}$ &${}=6x^{14}-4x^{13}-16x^{12}-32x^{11}+192x^{10}-128x^{9}-512x^8+512x^7$\\
&&$\hspace{.25cm}{}-3072x^6+2048x^5+8192x^4+4096x^3-24576x^2+16384x+65536$
\end{longtable}


\begin{align*}
 x^3&= 6x^2-4x-16 \tag{2}\\
 x^5 &= 6x^4-8x^3+8x^2-16x-64 \tag{4}\\
 x^9 &= 6x^8-4x^7-24x^6+48x^5-32x^4-64x^3-384x^2+256x+1024  \tag{6}\\
 x^{15} &=6x^{14}-4x^{13}-16x^{12}-32x^{11}+192x^{10}-128x^{9}-512x^8+512x^7\tag{8}\\
& \qquad-3072x^6+2048x^5+8192x^4+4096x^3-24576x^2+16384x+65536
\end{align*}

\end{document}
Related Question