Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
3  
You can't get the table dimensions without compiling them, so having a placeholder is almost out of the question. One could think of saving the table dimensions in the aux file in case the table is compiled. –  egreg Oct 30 '12 at 13:31
    
@egreg Simply excluding the table would be easy with the ifdraft package, e.g. wrap the whole float in \ifdraft{\relax}{\begin{table}... but that would be really annoying for the layout. The tables won't change, so taking the dimensions values from the aux file after an initial compile sounds like a good idea. –  Jörg Oct 30 '12 at 13:35
    
This sounds a bit tricky --- how does your "complicated table" look like? Can you post an example? –  tohecz Oct 30 '12 at 13:57
add comment

2 Answers 2

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

share|improve this answer
    
Thanks for this. I used your idea and create some automisation for it. –  Jörg Nov 5 '12 at 17:18
add comment
up vote 0 down vote accepted

cmhughes answer made me realise that any form of "automatic" table size recognition is just overkill. First, my tables are usually textwidth-wide, hence there is not a massive variation in size. Second, even if the size is a few cm's longer or shorter it does not really matter. So my strategy is as follows:

  • Create a new ifnotables conditional that can be activated by the documentclass via notables
  • Create a few predefined empty tables: \fulltable is on a extra page float, \halftable is half the size...\thirdtable, \quartertable etc.

The table can then be set by \ifnotables{\halftable}{\begin{tabular}...\end{tabular}. The advantage is that, when set in a table float, captions, labels etc. remain the same which allows for a decent layout: only the actual table is missing.

\documentclass[%
notables
]{article}

\usepackage{tikz}
\usepackage{booktabs,lmodern}

\makeatletter
% Provide new conditionals
\newif\if@notables
\DeclareOption{notables}{%
  \@notablestrue
}
\ProcessOptions*\relax
\newcommand*{\ifnotables}{%
  \if@notables
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\makeatother

% create dummy tables
\newcommand{\fulltable}{%
 \begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}l}
  \hspace{-.5em}\pgfpicture\pgfpathrectanglecorners{\pgfpointorigin}{\pgfpoint{\textwidth}{23cm}}%
  \pgfusepath{stroke}\endpgfpicture%
 \end{tabular*}
}
\newcommand{\halftable}{%
 \begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}l}
  \hspace{-.5em}\pgfpicture\pgfpathrectanglecorners{\pgfpointorigin}{\pgfpoint{\textwidth}{11.5cm}}%
  \pgfusepath{stroke}\endpgfpicture%
 \end{tabular*}
}
\newcommand{\thirdtable}{%
 \begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}l}
  \hspace{-.5em}\pgfpicture\pgfpathrectanglecorners{\pgfpointorigin}{\pgfpoint{\textwidth}{7cm}}%
  \pgfusepath{stroke}\endpgfpicture%
 \end{tabular*}
}
\newcommand{\quartertable}{%
 \begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}l}
  \hspace{-.5em}\pgfpicture\pgfpathrectanglecorners{\pgfpointorigin}{\pgfpoint{\textwidth}{5cm}}%
  \pgfusepath{stroke}\endpgfpicture%
 \end{tabular*}
}

\begin{document}

\begin{table}[!htb]
\centering
\caption{First table}
\label{tab:first}
        \ifnotables{\thirdtable}{%
         \begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}ccc}
         \toprule
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
        \bottomrule
        \end{tabular*}
       }
\end{table}

\begin{table}[!b]
\centering
\caption{Second table}
\label{tab:second}
        \ifnotables{\quartertable}{%
        \begin{tabular*}{\textwidth}{c@{\extracolsep{\fill}}ccc}
        \toprule
            right & center & left \\
            right & center & left \\
            right & center & left \\
            right & center & left \\
        \bottomrule
        \end{tabular*}
       }
\end{table}

\end{document}

enter image description here

The size of the dummies can of course be fine tuned. I usually have my tables stored in separate tex files, hence by creating a command such as:

\usepackage{etoolbox}
\newcommand{\mytable}[2][]{%
 \ifstrempty{#1}{%
  \input{#2}
  }{%
  \ifnotables{#1}{\input{#2}}%  
 }
}

I can make the code in the float tidier and the specification of a dummy table is optional:

\begin{table}[!htb]
\centering
\caption{First table}
\label{tab:first}
   \mytable[\halftable]{table2}
\end{table}
share|improve this answer
    
This is obviously useful for writing a text, but it doesen't really help for layouting a book with many table-floats which have to be arranged properly. For the latter it would be crucial to do as egreg suggests above: Measure the tables in one run and use the precise dimensions to reserve the appropriate space in the draft run. –  Florian Oct 22 '13 at 9:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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