3

This question already has an answer here:

I would like to create a pdf file that containes only the table captions, but not the content of the table. So I tried to redefine the tabular environment in the preamble of my document (it is probably not the best solution but I don't mind quick and dirty - I need to use it only temporarily):

\let\oldtabular\tabular
\let\endoldtabular\endtabular
\renewenvironment{tabular}{\iffalse\oldtabular}{\endoldtabular\fi}

or

\usepackage{etoolbox}
\preto\tabular{\iffalse}
\appto\tabular{\fi}

Unfortunatelly, it seems to have no effect on my document. If I manually frame the tabular environment it works:

\begin{table}[htbp]
    \centering
    \caption{my captiontext}
    \iffalse
        \begin{tabular}
            Content I don't want to see
        \end{tabular}
    \fi
    \label{myTableLabel}
\end{table}

Thanks in advance for any input!

marked as duplicate by yo', Manuel, user31729, percusse, Claudio Fiandrino Jul 31 '14 at 14:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

This seems to work... Also, if you change the \iffalse to \iftrue, you get back the tabular content.

\documentclass{article}
\let\svtabular\tabular
\let\endsvtabular\endtabular
\renewenvironment{tabular}
  {\setbox0=\vbox\bgroup\svtabular}
  {\endsvtabular\egroup\iffalse\box0\fi}
\begin{document}
xxxx
\begin{table}[htbp]
    \centering
    \caption{my captiontext}
        \begin{tabular}{c}
            Content I don't want to see\\
             multi-line\\
             test
        \end{tabular}
    \label{myTableLabel}
\end{table}
xxxx

xxxx
\begin{table}[htbp]
    \centering
    \caption{my captiontext}
        \begin{tabular}{c}
            Content I don't want to see\\
         \end{tabular}
    \label{myTableLabel}
\end{table}
xxxx
\end{document}

And if you wanted the tabular removal to leave in place a censored version of the content of the same size, then this would work:

\documentclass{article}
\usepackage{censor}
\let\svtabular\tabular
\let\endsvtabular\endtabular
\renewenvironment{tabular}
  {\setbox0=\hbox\bgroup\svtabular}
  {\endsvtabular\egroup\leavevmode\censorbox{\box0}}
\begin{document}
xxxx
\begin{table}[htbp]
    \centering
    \caption{my captiontext}
        \begin{tabular}{c}
            Content I don't want to see\\
             multi-line\\
             test
        \end{tabular}
    \label{myTableLabel}
\end{table}
xxxx

xxxx
\begin{table}[htbp]
    \centering
    \caption{my captiontext}
        \begin{tabular}{c}
            Content I don't want to see\\
         \end{tabular}
    \label{myTableLabel}
\end{table}
xxxx
\end{document}

enter image description here

In all cases above, what I essentially do is to save the tabular content into temporary box 0. Then I can choose to 1) not print it; 2) print it; or 3) replace it with a black box of the same size.

1

You can use the environ package to hide your tabular environments. If you just want to kill off all existing tabular environments then you can simply use:

 \RenewEnviron{tabular}[2][\relax]{}

As I slightly misread you question, below I have also defined an environment Htabular (=hidden tablular) with a default first argument of c. This becomes the layout specification for the hidden tabular environment, as per your example. The second argument of the environment is the table caption. By default the tabular environments are hidden. As in the midle example, you can change the tabular visibilty by setting \ShowTabulartrue.

\documentclass{article}
\usepackage{environ}
\newif\ifShowTabular\ShowTabularfalse
\NewEnviron{Htabular}[2][c]{%
  \table[htbp]\centering\caption{#2}%
  \ifShowTabular\tabular{#1}\BODY\endtabular\fi%
  \endtable}

\begin{document}

\begin{Htabular}{my captiontext}
Content I don't want to see
\end{Htabular}

\ShowTabulartrue

\begin{Htabular}[c|c]{Visible tabular}
  Content I don't want to see & More content\\
  Even more stuff
\end{Htabular}

\ShowTabularfalse
\begin{Htabular}[c|c]{my captiontext}
  Content I don't want to see & More content\\
  Even more stuff
\end{Htabular}

\end{document}

This produces:

enter image description here

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