I have the following working MWE file:
\documentclass{article}
\usepackage[rgb,dvipsnames,svgnames,table]{xcolor}
\usepackage{array}
\usepackage{booktabs}
%
\begin{document}
\begin{table}[!hbt]
\renewcommand{\arraystretch}{1.5}%
\centering%
\setlength{\fboxsep}{0pt}%
\arrayrulecolor{blue}%
\colorbox{lightgray}{%
\begin{tabular}{l l}
\toprule%
Column 1 & Column 2\tabularnewline% Unchanging column headers
\midrule%
One-one & One-two\tabularnewline% Changing content line one
Two-one & Two-two\tabularnewline% Changing content line two
\bottomrule%
\end{tabular}}
\end{table}
\end{document}
I would like to extract the static portions of this setup into either a new environment or a new command so that only the changing content lines will be passed to the new environment, say mytable, as
\begin{mytable}
One-one & One-two\tabularnewline% Changing content line one
Two-one & Two-two\tabularnewline% Changing content line two
\end{mytable}
or new command, say \mytable, as
\mytable{%
One-one & One-two\tabularnewline% Changing content line one
Two-one & Two-two\tabularnewline% Changing content line two
}
The \colorbox seems to throw a spanner in the works for this effort. How might I surmount this problem, please?
EDIT
In answer to @David Carlisle's query, here is the command version of what I tried:
\documentclass{article}
\usepackage[rgb,dvipsnames,svgnames,table]{xcolor}
\usepackage{array}
\usepackage{booktabs}
%
\newcommand{\mycontents}[1]{%
\renewcommand{\arraystretch}{1.5}%
\centering%
\setlength{\fboxsep}{0pt}%
\arrayrulecolor{blue}%
\colorbox{lightgray}{%
\begin{tabular}{l l}
\toprule%
Column 1 & Column 2\tabularnewline% Column headers
\midrule%
#1 % mind no braces {} around #1; that caused the error reported below
\bottomrule%
\end{tabular}}} % table environment removed as suggested by @egreg
%
\begin{document}
\mycontents{One-one & One-two\tabularnewline%
Two-one & Two-two\tabularnewline}
\end{document}
The error was:
```! Missing } inserted.
<inserted text>
}
l.25 Two-one & Two-two\tabularnewline}
?```


\newcommandreplacingOne-...line twoby#1. what error did you get? – David Carlisle Nov 19 '22 at 10:42?```
I have appended my question above with the command version just in case it has an obvious error.
{}? They were not in your original code,#1not{#1}That is why you should always put full code in the question, we would have had no clue about the error in code until you show it – David Carlisle Nov 19 '22 at 14:30{}pairs could lead to such problems in LaTeX. I think that adding gratuitous brace pairs is a carry over frombashwhere the defensive programming recommendation is to add them rather than leave them out. I can confirm that it works correctly now, And the command version is straightforward as you have alluded to. – chandra Nov 19 '22 at 15:09