GeneralHow do I add a jpeg picture to Latex

LaTeX specific issues not fitting into one of the other forums of this category.
akira32
Posts: 45
Joined: Tue Nov 13, 2007 10:32 am

How do I add a jpeg picture to Latex

Post by akira32 »

How do I add a jpeg picture to Latex?
What command should I use?
Could somebody tell me the code an detail?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How do I add a jpeg picture to Latex

Post by Stefan Kottwitz »

Hi akira32,

you should load the graphicx package and use \includegraphics. Here is a very basic example:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\begin{document}
Here is an example:
\begin{center}
\includegraphics{test.jpg}
\end{center}
\end{document}
It may be extended, but that depends on what your requirements are. Do you want the picture placed at an exact position or do you want to let it float? Do you need a caption below the picture? Do you need it to be listed in a list of figures? Do you need a number, a label for referencing?
Concerning \includegraphics you will find more information in the graphicx documentation.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How do I add a jpeg picture to Latex

Post by localghost »

As a supplement to the statements of Stefan I want to remark that graphics files in JPG format only can be included when compiling with pdflatex.


Best regards
Thorsten¹
akira32
Posts: 45
Joined: Tue Nov 13, 2007 10:32 am

How do I add a jpeg picture to Latex

Post by akira32 »

I write the code as below:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\begin{document}

\begin{center}
\includegraphics{test.jpg}
\end{center}
\end{document}
But when I click the button "build output", it appears 4 errors.
The 4 errors are in the jpeg4error.JPG in Attachments.
Attachments
add test.jpg, it appears 4 errors
add test.jpg, it appears 4 errors
jpeg4errors.JPG (47.39 KiB) Viewed 8970 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How do I add a jpeg picture to Latex

Post by Stefan Kottwitz »

Hi akira32,

the example I gave above is a complete compilable document, you should not insert that complete code into your own document. In your document you can insert the picture just by

Code: Select all

\includegraphics{test.jpg}
and if you want to center it then write instead:

Code: Select all

\begin{center}
\includegraphics{test.jpg}
\end{center}
Make sure that at the beginning of your document, in your preamble, there's the line

Code: Select all

\usepackage{graphicx}
Further the comment of Thorsten is important: use pdflatex, that means use the LaTeX => PDF output profile.

Stefan
LaTeX.org admin
akira32
Posts: 45
Joined: Tue Nov 13, 2007 10:32 am

Re: How do I add a jpeg picture to Latex

Post by akira32 »

Thank you! I add the line of "\includegraphics{test.jpg}" and "\usepackage{graphicx}" in preamble. But when I build the project, it appears a error as the picture attached.
Attachments
a error in adding jpeg file
a error in adding jpeg file
latex_jpg.JPG (13.8 KiB) Viewed 8953 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: How do I add a jpeg picture to Latex

Post by Stefan Kottwitz »

It seems that you are not using pdflatex, that's why the .jpg format is not supported.
You should compile directly into pdf format, not to dvi, then it will work. If you use TeXnicCenter, choose the output profile LaTeX => PDF. If you use WinEdit then choose the PDFTeXify (or PDFLaTeX) button. Or tell us, which editor you are using.

Stefan
LaTeX.org admin
akira32
Posts: 45
Joined: Tue Nov 13, 2007 10:32 am

How do I add a jpeg picture to Latex

Post by akira32 »

\includegraphics[width=\textwidth , bb= 20 20 575 575]{test.jpg}
I forget add the bounding box. But it still cannot show the jpeg file in my Latex.
Becuase my Latex project is created by my classmate.
I am a beginner. Now I try to create a new report project and try to add the jpeg file.
akira32
Posts: 45
Joined: Tue Nov 13, 2007 10:32 am

Re: How do I add a jpeg picture to Latex

Post by akira32 »

I add the jpeg file successfuly with the build option of "LaTex=>PS=>PDF".
But the jpeg file becomes a gray-level picture in pdf.
Attachments
test1-gray-level in pdf
test1-gray-level in pdf
test1-gray.JPG (1.43 KiB) Viewed 8906 times
tes1.jpg colorful (original)
tes1.jpg colorful (original)
test.JPG (1.39 KiB) Viewed 8907 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

How do I add a jpeg picture to Latex

Post by Stefan Kottwitz »

akira32 wrote: I add the jpeg file successfuly with the build option of "LaTex=>PS=>PDF".
That's not the right profile. Do really you have not LaTeX=>PDF od didn't you try that?
With LaTeX=>PDF (that's pdflatex) you will get color and you won't need a bounding box.

Stefan
LaTeX.org admin
Post Reply