How can I protect the ampersand (tab alignment character within tabular) and possibly the \\
(new row in tabular) when defining a \savebox
?
\documentclass{article}
\usepackage{fontspec}% xelatex
\newsavebox{\tabdata}
\savebox{\tabdata}{sto1 & sto2 & sto3}% I'd like to save this.
\begin{document}
\begin{tabular}{lll}
col1 & col2 & col3 \\
\usebox{\tabdata} \\
\end{tabular}
\end{document}
Background
I have hundreds of thousands of tables. All of the headers start with \mybeginheadrow
and end with \myendheadrow
. I'd like to utilize these macros to grab the headers and apply them in different ways to longtable's \endhead
, \endfirsthead
, etc. I am actually using ltxtable
, which first writes all data to an external file. I am not sure whether this is relevant.
Intention
- Store header row (could be multiple rows) tokens in a macro.
- Expand them in different places in the table multiple times.
\savebox
, but you can do it with a\def
as in\documentclass{article} \def\tabdata{sto1 & sto2 & sto3} \begin{document} \begin{tabular}{lll} col1 & col2 & col3 \\ \tabdata \\ \end{tabular} \end{document}
. Once inside a box, any content is fully isolated from the surrounding code.\def
should be\newcommand
in a latex docuemnt)