I have the following table which compiles perfectly
\documentclass{article}
\usepackage{booktabs}
\usepackage[margin=32mm]{geometry}
\usepackage{tabularx}
\usepackage{float}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}[H]\centering
\begin{tabularx}{\textwidth}{ccYYcYY@{}}
\toprule
&& \multicolumn{2}{c}{Next State} && \multicolumn{2}{c}{Output} \
\cmidrule{3-4} \cmidrule{6-7}
Present State && $x = 0$ & $x = 1$ && $x = 0$ & $x = 1$\
\midrule
000 && 010 & 011 && 0 & 0 \
001 && 001 & 001 && 1 & 1 \
010 && 110 & 011 && 0 & 0 \
011 && 000 & 101 && 1 & 1 \[0.5em]
100 && 111 & 101 && 0 & 0 \
101 && 000 & 101 && 0 & 1 \
110 && 000 & 001 && 1 & 0 \
111 && 101 & 011 && 0 & 0 \
\bottomrule
\end{tabularx}
\caption{State table for the sequential circuit discussed}
\end{table}
\end{document}
Based on this I want to make an environment so I can reuse this table (the number of columns don’t have to change). I have tried defining it like so (I have simply extracted the begin and end parts of the table and left out the contents):
\newenvironment{statetable}%
{\begin{table}[H]\centering
\begin{tabularx}{\textwidth}{ccYYcYY@{}}
\toprule
&& \multicolumn{2}{c}{Next State} && \multicolumn{2}{c}{Output} \\
\cmidrule{3-4} \cmidrule{6-7}
Present State && $x = 0$ & $x = 1$ && $x = 0$ & $x = 1$ \\
\midrule}%
{\bottomrule
\end{tabularx}
\caption{State table for the sequential circuit discussed}%
\end{table}}
So I can use it like this:
% \begin{statetable}
000 && 010 & 011 && 0 & 0 \\
001 && 001 & 001 && 1 & 1 \\
010 && 110 & 011 && 0 & 0 \\
011 && 000 & 101 && 1 & 1 \\[0.5em]
100 && 111 & 101 && 0 & 0 \\
101 && 000 & 101 && 0 & 1 \\
110 && 000 & 001 && 1 & 0 \\
111 && 101 & 011 && 0 & 0 \\
% \end{statetable}
But I get the following error:
ABD: EveryShipout initializing macros
! Misplaced alignment tab character &.
l.52 000 &
& 010 & 011 && 0 & 0 \\
?

