9

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}
Florian
  • 945

1 Answers1

9

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}
David Carlisle
  • 757,742
  • Wow. Straight to the point. Your solution makes things work and makes me understand the underlying problem. Thanks. – Florian Feb 16 '15 at 13:18