Adding a jpeg in LaTeX automatically adds directory address

  • Context: LaTeX 
  • Thread starter Thread starter Kinetica
  • Start date Start date
  • Tags Tags
    Latex
Click For Summary

Discussion Overview

The discussion revolves around an issue with including JPEG images in a LaTeX document using the graphicx package, specifically regarding the automatic addition of the file's directory path in the output. Participants explore potential solutions and troubleshooting steps related to this problem.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports that the LaTeX system adds the directory path of the image when included, which they wish to avoid.
  • Another participant suggests moving the image to the same directory as the LaTeX document to simplify the file path.
  • A different participant mentions that the graphicx package should not display the file name by default and recommends using the final option in the package to avoid issues related to draft mode.
  • One participant notes that their image is already in the same folder as the LaTeX file, indicating that the issue persists despite this.
  • Another participant describes experiencing additional issues with their LaTeX editor, suggesting that the problem may be related to the software rather than the LaTeX code itself.
  • A later reply points out that having spaces in file names could cause problems and suggests removing them to resolve the issue.

Areas of Agreement / Disagreement

Participants express various viewpoints on the cause of the issue and potential solutions, with no consensus reached on a definitive fix. Some suggest file management practices, while others focus on package options and software behavior.

Contextual Notes

Participants note potential limitations related to file naming conventions, such as the presence of spaces, which may affect how LaTeX processes file paths. There is also mention of the possibility that other packages may interfere with the graphicx package's functionality.

Kinetica
Messages
83
Reaction score
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: 518
Physics news on Phys.org
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 :)
 
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.
 
The picture is located in the same folder where my latex file is.
 
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.
 
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

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.
 
Thank you a lot!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
7K