4

I have a template for my project and I don't know very much about LaTeX. It puts that for putting an image is:

\begin{figure}
\centering
% dummy figure replacement 
\begin{tabular}{@{}c@{}}
\rule{.5\textwidth}{.5\textwidth} \\
\end{tabular}
\caption{\label{fig:example}A figure}
\end{figure}

but I think that in this text is missing a command to insert the image like this: \includegraphics[width=0.7\textwidth]{mifigure} but if I put that, it does´t work.

also if I put \includegraphics without width=0.7\textwidth, the image appear too big to the side of the document.

(my image is inside a folder and it is .png)

Now I have another problem related to this.

In main.tex

\documentclass{MScthesisITEM}
\DeclareGraphicsExtensions{.pdf,.jpg,.png}
\graphicspath{{./figs/}}

In example chapter4.tex

\begin{figure}
\centering
% dummy figure replacement 
\begin{tabular}{@{}c@{}}
\rule{.5\textwidth}{.5\textwidth} \\
\end{tabular}
\caption{\label{fig:example}A figure}
\end{figure}

This shows a black image in the center of the document.

In my chapter.tex

\begin{figure}
\centering
% dummy figure replacement 
\begin{tabular}{@{}c@{}}
\rule{.5\textwidth}{.5\textwidth} \\
\includegraphics[width=.5\linewidth]{circuitpacket}
\end{tabular}

\caption{ Explanation...}
\label{fig:comparison_circuit}
\end{figure}

I obtained the black image and my image after the black image. How can I erase the black image?

5
  • Hello Juan, welcome to the community. First, it is a good idea that you include on your code the documentclass and additional packages you're using... because the result depend on these things... Make sure you've included the package graphicx. Second, I'm not sure it is customary to insert the \label on the \caption argument (although it depends on the class you're using. Third, there's an option (intead of width, you can use \includegraphics[scale=.2]{myfigure}
    – Dox
    Nov 13, 2013 at 16:50
  • If you have any problem after trying my answer, please drop some comments. Nov 13, 2013 at 17:08
  • when I put the package that you mention I have an error, so I updated the question with more info. Thank you very much for the help.
    – Juan
    Nov 13, 2013 at 17:44
  • \rule{<width>}{<height>} creates a black box, so the line `\rule{.5\textwidth}{.5\textwidth} \` adds a square black box. Nov 13, 2013 at 19:07
  • If you want to include standard figures more easily check out the easyfig package. Dec 5, 2017 at 11:45

1 Answer 1

3

If your images are in the same directory in which the input file exist, the following code should work. Please make a try by replacing example-image-a with your-image-filename. And make sure you compile with pdflatex rather than latex followed by dvips followed by ps2pdf.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=.5\linewidth]{example-image-a}
\caption{Hello Universe}
\label{fig:HelloUniverse}
\end{figure}
\end{document}

But if your images are in a sub directory subdir1, subdir2, etc, for example, then you need to specify the graphics path as follows.

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{subdir1/}{subdir2/}}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=.5\linewidth]{example-image-a}
\caption{Hello Universe}
\label{fig:HelloUniverse}
\end{figure}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .