我想创建一个只包含表格标题而不包含表格内容的 pdf 文件。因此,我尝试在文档的序言中重新定义表格环境(这可能不是最好的解决方案,但我不介意快速而粗糙 - 我只需要暂时使用它):
\let\oldtabular\tabular
\let\endoldtabular\endtabular
\renewenvironment{tabular}{\iffalse\oldtabular}{\endoldtabular\fi}
或者
\usepackage{etoolbox}
\preto\tabular{\iffalse}
\appto\tabular{\fi}
不幸的是,它似乎对我的文档没有影响。如果我手动构建表格环境,它就会起作用:
\begin{table}[htbp]
\centering
\caption{my captiontext}
\iffalse
\begin{tabular}
Content I don't want to see
\end{tabular}
\fi
\label{myTableLabel}
\end{table}
提前感谢您的任何意见!
答案1
这似乎有效...此外,如果您将 更改为\iffalse
,\iftrue
您将获得tabular
内容。
\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}
并且如果您希望表格删除后保留相同大小的审查版本的内容,那么这将起作用:
\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}
在上述所有情况下,我所做的基本上是将表格内容保存到临时框 0 中。然后我可以选择 1) 不打印它;2) 打印它;或 3) 用相同大小的黑框替换它。
答案2
您可以使用该environ
包来隐藏您的表格环境。如果您只想删除所有现有tabular
环境,那么您只需使用:
\RenewEnviron{tabular}[2][\relax]{}
由于我稍微误读了您的问题,下面我还定义了一个环境Htabular
(=hidden tablular),其默认第一个参数为c
。根据您的示例,这将成为隐藏表格环境的布局规范。环境的第二个参数是表格标题。默认情况下,表格环境是隐藏的。与 midle 示例一样,您可以通过设置来更改表格可见性\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}
得出的结果为: