[Tex/LaTex] Equivalent to graphicx draft/demo option for tables

compilingdrafttables

I am looking for a way to exclude tables from compilation when I am in draft mode (technically I want to create a boolean such as drafttables that would exclude tables when active). Usually I have tables in a separate file at the end of the document and just exclude it from compilation while working on the document. But now I need to put many many tables inside the document as floats, and because the tables are rather complicated, compilation takes a long time.

Is it possible to create a macro that just puts a placeholder instead of the table, similar to the option of the graphicx package? A bonus would be if the placeholder would have similar dimensions as the table, so that the layout stays the same.

Best Answer

I've borrowed some work from Draft mode for pgfplots in the solution below.

If you use

\documentclass[draft]{article}

then all the tables will not appear. If you use

\documentclass{article}

then they'll appear as usual.

I've used the verbatim package just for the comment environment.

Measuring the dimensions of the table would be tricky- perhaps this will help someone go in that direction.

%\documentclass{article}
\documentclass[draft]{article}
\usepackage{verbatim}

\makeatletter
\@tempswafalse
\def\@tempa{draft}
\@for\next:=\@classoptionslist\do
  {\ifx\next\@tempa\@tempswatrue\fi}
\if@tempswa % draft option is active
    \renewenvironment{table}{\comment}{\endcomment}
    \fi
\makeatother

\begin{document}

hello world

\begin{table}[!htb]
    \begin{minipage}{.5\textwidth}
        \centering
        \caption{}
        \label{tab:first}
        \begin{tabular}{rcl}
            right & center & left \\
            right & center & left 
        \end{tabular}
    \end{minipage}%
    \begin{minipage}{.5\textwidth}
        \centering
        \caption{}
        \label{tab:second}
        \begin{tabular}{rcl}
            right & center & left \\
            right & center & left 
        \end{tabular}
    \end{minipage}
\end{table}


\end{document}

Alternative

Or else you might prefer to load tikz or pgf and then use the following in the \ifdraft check

\renewenvironment{tabular}{%
\pgfpicture\pgfpathrectanglecorners{\pgfpointorigin}{\pgfpoint{3cm}{3cm}}%
     \pgfusepath{stroke}\endpgfpicture%
\comment}{\endcomment}

which gives

screenshot

Related Question