8

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 1

8

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.