Is there a command that I can use as a placeholder for \includegraphics
?
I want to use such a placeholder to add the original graphics later.
12 Answers
It's 2018 now, and this has become very easy.
Simply:
\includegraphics[width=\textwidth]{example-image-a}
The mwe
package needs to be installed for this (but it doesn't need to be included in the preamble). If using MiKTex e.g., it will offer to install this package when the document is built.
There are other placeholder images available as well.
Example document from another StackExchange answer:
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\begin{document}
\noindent\includegraphics[width=3cm]{example-image-a}\qquad
\includegraphics[width=3cm]{example-image-golden}\qquad
\includegraphics[width=3cm]{example-grid-100x100pt}
\noindent\includegraphics[height=5cm]{example-image-b}
\noindent\includegraphics[scale=0.5]{example-image-c}
\noindent\includegraphics[width=3cm]{example-image}
\end{document}
-
6
-
Compilation always fails when
[draft]
is not given. Can you explain why?– PatrickApr 13, 2021 at 17:28 -
@Patrick: Not without context. Kindly post a proper question, someone might help then.– TomasMay 31, 2021 at 17:15
-
@Patrick: perhaps you're using
\includegraphics[draft][width=3cm]{example-image-a}
, whereas it should be\includegraphics[draft,width=3cm]{example-image-a}
. That is, use only one pair of block brackets. For others: thedraft
option will only draw a bounding box instead of the actual image (to save ink/toner).– BartJul 27, 2022 at 13:10
todonotes
provides the \missingfigure
command, precisely designed for this case
\documentclass{article}
\usepackage{todonotes}
\begin{document}
\missingfigure[figwidth=6cm]{Testing a long text string}
\end{document}
-
-
5
-
yes exactly so you have to remove \includegraphics and later re-insert it– G MMar 27, 2017 at 15:10
-
I expected something to use with includegraphics like the others answers– G MMar 27, 2017 at 15:23
-
7I don't see why. This is a placeholder, you just replace it with the actual content when you get it. it is no different from e.g. removing
[draft]
and putting the actual path in the accepted solution.– EvpokMar 27, 2017 at 20:40
If you need individual figures to be omitted rather than all of them, you first copy a dummy figure (called foo
here) to your figures path, then use as:
\includegraphics[draft]{foo}
It will display something like:
It will also save ink, and you can use \includegraphics
syntax as it is, you just need to replace foo
and remove draft
from command.
-
8I am not sure if the bounding-box computations are reliable. I had some problems with the replacement of default sized boxes for the
draft
mode graphics. By the way, for every picture you can also use\usepackage[draft]{graphicx}
. Turkce gormek ayrica sasirtici :)– percusseFeb 13, 2012 at 13:56 -
@percusse: actually, although I almost never use default sizes, I omitted
width
,height
arguments in my example. selamlar efendim :)– nimcapFeb 13, 2012 at 19:28
It's 2018 now, and this has become even more fun.
Simply:
\includegraphics[width=\textwidth]{example-image-duck}
The duckuments
package needs to be installed for this. If using MiKTex e.g., it will offer to install this package when the document is built.
Example document from another StackExchange answer:
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{duckuments}
\begin{document}
\noindent\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\includegraphics[width=3cm]{example-image-duck}
\end{document}
(This post may have been inspired by Tomas answer :)
Either load the graphicx
package with the demo
option or replace \includegraphics
by, say, \rule{2cm}{2cm}
.
-
9IIRC,
\includegraphics[demo,width=<..>,height=<..>]{dummy}
should work as well, i.e.demo
used locally. Feb 11, 2012 at 13:39 -
17
-
3To avoid the black box of \rule{2cm}{2cm} but to keep the simplicity, you can draw just two or three edges of the box with \rule{.1pt}{2cm} \rule{2cm}{.1pt} \rule{.1pt}{2cm} Dec 15, 2014 at 14:12
-
@vowel-house-might this is brilliantly simple ! Thanks. Just wanted to highlight for other readers that you cannot get 4 lines with this method (I have tried). But 3 works very well. Also note that the horizontal line cannot be
\linewidth
long, as the others no longer have space. So just put the numbers manually. May 23 at 12:17
I dont't like the demo option of the graphicx
package, because one get some ugly black boxes in the document. And if you want to make a test print you waste a lot of ink and maybe your reviser is wondering about. So I created my own demo mode and just include an empty rectangle with the same size of the original picture. If I want to use the original pictures I comment the definition out and all the pictures will be inserted. For this it is necessary to use the picins
package.
\documentclass{book}
\usepackage{picins}
\usepackage{graphicx}
\makeatletter
\def\Ginclude@graphics#1{%
\parpic(\Gin@@ewidth,\Gin@@eheight)[d]{#1}\picskip{0}}%
\makeatother
\begin{document}
\begin{figure}
\centering
\includegraphics[width=8cm,height=5cm]{myPictureName.png}%
\caption{My Picture}
\end{figure}
\end{document}
-
2
-
4@MarkS.Everitt Used to be standard but was removed from TL, I think, for license reasons.– Joseph Wright ♦Feb 11, 2012 at 14:24
-
2At ctan.org/pkg/picins you can see that picins is standard in MiKTeX (I use MiKTeX) but not in TeXLive. You should install it manually.– HolleFeb 11, 2012 at 14:25
-
1@Holle: Good to know. Could you put the link into the answer though? I think it's a good thing to have there for completeness.– qubyteFeb 11, 2012 at 14:50
-
1@Yiannis Please keep in mind that this approach was intended by the fact that there were no pictures to insert and that we don't want to use the demo mode of the graphicx package. So you don't know the size of the pictures. If you already have the pictures and you don't want to show them in the document you should use the draft option of you documentclass.– HolleFeb 11, 2012 at 18:12
You can do without additional packages: just load graphicx
with the demo
option and do as explained in this answer; I repeat the code for completeness:
\usepackage[demo]{graphicx}
\makeatletter
\AtBeginDocument{%
\def\Ginclude@graphics#1{%
\begingroup\fboxsep=-\fboxrule
\fbox{\rule{\@ifundefined{Gin@@ewidth}{150pt}{\Gin@@ewidth}}{0pt}%
\rule{0pt}{\@ifundefined{Gin@@eheight}{100pt}{\Gin@@eheight}}}\endgroup}}
\makeatother
Just remove the demo
option and comment the additional code when you want to include the real graphic files.
This will produce framed rectangles with the specified width and height, but using a predefined dimension when width=
and height=
are not specified in the options to \includegraphics
.
Another strategy is to load graphicx
with the draft
option, that will read the graphic files for getting their dimensions and print a framed rectangle with the file name in their place
\usepackage[draft]{graphicx}
As always, beware of file names with spaces: enclosing the name between double quotes should avoid problems.
Inspired by Holle's answer (avoid a big black toner hungry box), here is one with pgf. The pgf package has a draft option. With it:
\documentclass{article}
\usepackage[draft]{pgf}
\begin{document}
\begin{figure}[ht]
\centering
\begin{pgfpicture}
\pgftext{\pgfimage[width=5cm,height=4cm]{scratch.png}}
\end{pgfpicture}
\end{figure}
\end{document}
where scratch.png
is your image. With draft
as an option to the pgf package this simply looks like a box with the file name:
Without the draft option, the image is placed as expected.
-
1Doesn't this just draws a box of X by Y? One would ideally need to be able to measure the actual image and print the box to the resulting dimension (i.e, if only width or height is specified, keepaspectratio etc). Feb 11, 2012 at 16:28
-
I agree. It defaults to a 1cm by 1cm box. Perhaps it can be improved, but it's already a peripheral answer.– qubyteFeb 11, 2012 at 16:37
A better version to hide the entire picture but keep the space is to use the phantom
command
\phantom{\includegraphics[...]{picture}}
This avoids white text, could for example be selected in the pdf.
PS: not enough repo to comment on Dennis' answer.
If you want to "hide" the entire picture, but reserve the space, you could use the following lines:
\usepackage{xcolor,graphicx}
...
\color{white}
\includegraphics[draft , ...]{picture}
\color{black}
-
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it) or type Ctrl+K.– henriqueMay 9, 2012 at 15:38
You can use the package draftfigure
to switch off and modify the display of figures:
\documentclass{article}
\usepackage[
%various options globally available
]{draftfigure}
\usepackage{caption}
\setkeys{Gin}{width=.5\linewidth}%only for demonstration
\begin{document}
\begin{figure}[htb]
\centering
\setkeys{draftfigure}{content={white box}}
\includegraphics[draft]{example-image-a}
\caption{A}\label{A}
\setkeys{draftfigure}{filename=true}
\includegraphics[draft]{example-image-b}
\caption{B}\label{B}
\setkeys{draftfigure}{content={another white box}}
\includegraphics[draft]{example-image-c}
\caption{C}\label{C}
\end{figure}
\begin{figure}[htb]
\centering
\setkeys{draftfigure}{content={white box}}
\includegraphics[draft]{example-image-a}
\caption{A}\label{A1}
\setkeys{draftfigure}{filename=true,
style={tt},position={right}}
\includegraphics[draft]{example-image-b}
\caption{B}\label{B1}
\setkeys{draftfigure}{content={hidden image},
style={rm},filename=false,position={center}}
\includegraphics[draft]{example-image-c}
\caption{C}\label{C1}
\end{figure}
\end{document}
I like the simplicity of https://gist.github.com/dpgettings/9635856 (not mine, so credit to the author dpgettings):
\newcommand{\dummyfig}[1]{
\centering
\fbox{
\begin{minipage}[c][0.33\textheight][c]{0.5\textwidth}
\centering{#1}
\end{minipage}
}
}
which can be used as:
\begin{figure*}[h]
\dummyfig{Dummy Figure Label}
\caption{Dummy figure caption}
\label{fig:dummy}
\end{figure*}
dummy.jpg
(or dummy.eps) and use this dummy graphic until you have your original one.demo
option not printing big blobs.