有没有办法获得没有图表的 pdf 文件,同时保留正文中的图表编号。
非常感谢
答案1
您可以使用该ifdraft
包中的以下内容:
\documentclass[draft]{scrartcl}
\usepackage{ifdraft}
\usepackage{graphicx}
\newcommand{\tabledraft}[2]{%
\ifdraft{\refstepcounter{table}\label{#1}}{#2}%
}
\newcommand{\figuredraft}[2]{%
\ifdraft{\refstepcounter{figure}\label{#1}}{#2}%
}
\begin{document}
\figuredraft{fig:ex-a}{
\begin{figure}
\centering
\includegraphics[width=5cm]{example-image-a}
\caption{Example image a}\label{fig:ex-a}
\end{figure}
}
\tabledraft{tab:ex}{
\begin{table}
\centering
\caption{A neat table}\label{tab:ex}
\begin{tabular}{ll}
\hline
neat&table\\
being&neat\\
\hline
\end{tabular}
\end{table}
}
Some random text.
Figure \ref{fig:ex-a} is nice but table \ref{tab:ex} is even nicer.
\end{document}
使用draft
-option 会导致:
并且不这样做会导致:
答案2
该解决方案(使用 Skillmon 的 MWE)使图形或表格不可见,尽管它实际上经历了绘制它的所有步骤。
\documentclass[draft]{scrartcl}
\usepackage{ifdraft}
\usepackage{graphicx}
\usepackage{environ}
\makeatletter
\ifdraft{\RenewEnviron{figure}[1][tbp]%
{\hrule height0pt \rlap{\hspace{\paperwidth}\smash{\begin{minipage}{\textwidth}%
\def\@captype{figure}\BODY\end{minipage}}}\ignorespaces}}
\ifdraft{\RenewEnviron{table}[1][tbp]%
{\hrule height0pt \rlap{\hspace{\paperwidth}\smash{\begin{minipage}{\textwidth}%
\def\@captype{table}\BODY\end{minipage}}}\ignorespaces}}
\makeatother
\begin{document}
Before text
\begin{figure}
\centering
\includegraphics[width=5cm]{example-image-a}
\caption{Example image a}\label{fig:ex-a}
\end{figure}
\begin{table}
\centering
\caption{A neat table}\label{tab:ex}
\begin{tabular}{ll}
\hline
neat&table\\
being&neat\\
\hline
\end{tabular}
\end{table}
After text.
Figure \ref{fig:ex-a} is nice but table \ref{tab:ex} is even nicer.
\end{document}