# Example figure placement

I am using the following code in an example file.

\documentclass{book}

\usepackage{graphicx}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{figure}[h]
\includegraphics[width=\textwidth]{box}
\caption{I am a figure\label{fig:one}}
\end{figure}
\lipsum[2]
\end{document}


This means that there has to be an image named 'box' in the same directory (e.g. box.pdf). Is there a way to avoid that? I was thinking about an example image that ships with TeX-Live anyway or some tikZ solution? Which would be the most portable way of defining such an example without the necessity of a second file?

-

Here are a couple of possibilities

• use the demo option with the graphicx package: \usepackage[demo]{graphicx}
• use the mwe package, which gives you access to a few images- a MWE (!) is shown below

MWE

\documentclass{book}

\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{mwe}

\begin{document}
\lipsum[1]
\begin{figure}[h]
\includegraphics[width=\textwidth]{example-image-a}
\caption{I am a figure\label{fig:one}}
\end{figure}
\lipsum[2]
\end{document}


-
<s>I like the [demo] solution, because it is so easy to switch on and off. However, some portability is lost, you cannot use the mhchem package in the example any more.</s> It seams that I just have to load the demoed graphicx-package first. – Andy Dec 2 '12 at 18:27
@Andy I experimented and loaded the mhchem just fine- could you give more details? – cmhughes Dec 2 '12 at 20:59
You have to load the mhchem package after the [demo]{graphicx} package, at least in the actual non-MWE example I am trying. I figured that out only after commenting and tried to strikeout the earlier part of my comment. Therefore, a totally unrelated question: Is there a way to strikeout comments. I am sure I have seen it in questions and answers. – Andy Dec 3 '12 at 7:29