# Save table using savebox

I want to save a tabularx using a savebox, such that I can define it in one place and print it in another. While the code below worked for a listing, I could not make it work for a table. Is there any way to achieve this? The code below gives me an "Not in outer par mode" error.

\documentclass{article}
\usepackage{tabularx}

\begin{document}

\newsavebox{\mybox}

\begin{lrbox}{\mybox}
\begin{table}
\begin{tabularx}{\textwidth}{|l|ll|}
x & y & z\\\hline
\end{tabularx}
\end{table}
\end{lrbox}

\usebox{\mybox}

\end{document}


## 1 Answer

You can not save a floating environment in a box, but you can save the tabularx

\documentclass{article}
\usepackage{tabularx}

\begin{document}

\newsavebox{\mybox}

\begin{lrbox}{\mybox}
\begin{tabularx}{\textwidth}{|l|ll|}
x & y & z\\\hline
\end{tabularx}
\end{lrbox}

\begin{table}
\usebox{\mybox}
\end{table}

\end{document}

• Wow. Straight to the point. Your solution makes things work and makes me understand the underlying problem. Thanks. Feb 16, 2015 at 13:18