Adding a jpeg in LaTeX automatically adds directory address

  • LaTeX
  • Thread starter Kinetica
  • Start date
  • Tags
    Latex
In summary: I use it for diagrams that include pictures and it's really inconvenient.In summary, LaTeX adds the directory of the file when you include a picture in your document. You can fix this by moving the picture to the same folder as your document or by using a different package that does not do this. The graphicx package does not add the file name by default, but you can change this by using the \usepackage[final]{graphicx} command. The package also includes other features that are incorporated into the memoir class.
  • #1
Kinetica
88
0
Hello! When I add a picture in my LaTeX document, the system automatically adds the directory of the file like seen in the attachment. Is there a way to fix it? because I don't need the directory to be seen.
My code is:

\begin{center}
\includegraphics[width=0.50\textwidth]{E:/Game Theory E600/HW6/5.png}
\end{center}

I use package graphicx

Thank you!
 

Attachments

  • 12.png
    12.png
    8.4 KB · Views: 447
Physics news on Phys.org
  • #2
I would move the picture to the directory, where your latex document is, or at least to its subfolder - in this case you don't even need to write the full path to the picture, only {picture.jpg} or {subfolder/picture.jpg}. It works for sure :)
 
  • #3
The graphicx package does not do what you got by default. If you run it in "draft" mode it will just draw a rectangle the size of the image with the file name inside (to save time). Otherwise it will just display the image, not the fikle name.

Try replacing
\usepackage{graphicx}
with
\usepackage[final]{graphicx}
which should make sure some strange option is not switched on when you don't want it.

If that doesn't work, can you attach a complete (preferably short) LaTeX file that produces this output? My guess is that some other package is redefining what \includegraphics does.
 
  • #4
The picture is located in the same folder where my latex file is.
 
  • #5
Weird things happen with my TeXnicCenter. Now, a table got stuck in between my picture no matter where I place this table within the document.

Also, the last suggestion did not help. Let me attach the file.
 
  • #6
Here is the latex file and the document.

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

% This is a simple template for a LaTeX document using the "article" class.
% See "book", "report", "letter" for other types of document.

\documentclass[11pt]{article} % use larger type; default would be 10pt

\usepackage[utf8]{inputenc} % set input encoding (not needed with XeLaTeX)

%%% Examples of Article customizations
% These packages are optional, depending whether you want the features they provide.
% See the LaTeX Companion or other references for full information.

%%% PAGE DIMENSIONS
\usepackage{geometry} % to change the page dimensions
\geometry{a4paper} % or letterpaper (US) or a5paper or...
% \geometry{margin=2in} % for example, change the margins to 2 inches all round
% \geometry{landscape} % set up the page for landscape
% read geometry.pdf for detailed page layout information

\usepackage[final]{graphicx} % support the \includegraphics command and options

% \usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent

%%% PACKAGES
\usepackage{booktabs} % for much better looking tables
\usepackage{array} % for better arrays (eg matrices) in maths
\usepackage{paralist} % very flexible & customisable lists (eg. enumerate/itemize, etc.)
\usepackage{verbatim} % adds environment for commenting out blocks of text & for better verbatim
\usepackage{subfig} % make it possible to include more than one captioned figure/table in a single float
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{graphicx}

% These packages are all incorporated in the memoir class to one degree or another...

%%% HEADERS & FOOTERS
\usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
\pagestyle{fancy} % options: empty , plain , fancy
\renewcommand{\headrulewidth}{0pt} % customise the layout...
\lhead{}\chead{}\rhead{}
\lfoot{}\cfoot{\thepage}\rfoot{}

%%% SECTION TITLE APPEARANCE
\usepackage{sectsty}
\allsectionsfont{\sffamily\mdseries\upshape} % (See the fntguide.pdf for font help)
% (This matches ConTeXt defaults)

%%% ToC (table of contents) APPEARANCE
\usepackage[nottoc,notlof,notlot]{tocbibind} % Put the bibliography in the ToC
\usepackage[titles,subfigure]{tocloft} % Alter the style of the Table of Contents
\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape}
\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} % No bold!

%%% END Article customizations

%%% The "real" document content comes below...

\title{STAT S516: Homework 2. Due: September 17th, 2012}
\author{ }
\date{} % Activate to display a given date or no date (if empty),


\begin{document}

\maketitle

\section*{Problem 1. 2.72}

For a certain population of employees, the percentage passing or failing a job competency exam,
listed according to sex, were as shown in the accompanying table. That is, of all the people
taking the exam, $24\%$ were in the male-pass category, $16\%$ were in the male-fail category, and
so forth. An employee is to be selected randomly from this population. Let A be the event that
the employee scores a passing grade on the exam and let M be the event that a male is selected.

\begin{center}
\includegraphics[width=0.60\textwidth]{E:/FALL 2012/STAT-S516/HW2/1.png}
\end{center}


\begin{center}
\includegraphics[width=0.80\textwidth]{E:/FALL 2012/STAT-S516/HW2/2.png}
\end{center}

\end{document}
 

Attachments

  • LaTeX1.pdf
    74.4 KB · Views: 464
  • #7
The problem is that you have a blank in your file names E:/FALL 2012/etc. If you get rid of that, it should work OK. Blanks in file names are never a good idea, especially if you are using software that isn't specifically written for MS Windows only.

I've no idea WHY it does what it does. I get a warning saying "file not found" but LaTeX then includes it (plus part of the file name starting after the blank) even though it says it can't find it! This looks like a bug (or at least a "feature") in the graphicx package.
 
  • #8
Thank you a lot!
 

1. How do I add a jpeg in LaTeX automatically?

To automatically add a jpeg in LaTeX, you can use the command \includegraphics{image_name.jpeg} and make sure to include the graphicx package in your document.

2. Can I add a jpeg from any directory in LaTeX?

Yes, you can add a jpeg from any directory in LaTeX by using the full file path in the \includegraphics command. For example, \includegraphics{/Users/username/Desktop/image_name.jpeg}.

3. What if I want to add multiple jpegs in LaTeX automatically?

You can use the subfig package to add multiple jpegs in LaTeX automatically. This package allows you to include multiple images in a single figure with a shared caption and numbering.

4. How do I change the size of the jpeg in LaTeX?

You can change the size of the jpeg in LaTeX by using the optional arguments in the \includegraphics command. For example, \includegraphics[width=0.5\textwidth]{image_name.jpeg} will resize the image to half of the text width.

5. Can I add a caption to the jpeg in LaTeX?

Yes, you can add a caption to the jpeg in LaTeX by using the \caption command after the \includegraphics command. This will automatically number and label the figure. You can also use the \label and \ref commands to refer to the figure in your document.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top