Professional Documents
Culture Documents
Inserting Images - ShareLaTeX, Online LaTeX Editor
Inserting Images - ShareLaTeX, Online LaTeX Editor
Inserting Images - ShareLaTeX, Online LaTeX Editor
Documentation Home
Search help library....
(/learn/Main_Page)
Learn LaTeX in 30 minutes Suggest new doc
(/learn/Learn_LaTeX_in_30_minutes)
ShareLaTeX guides
Creating a document in ShareLaTeX
Inserting Images
(/learn/Creating_a_document_in_ShareLaTeX)
Uploading a project
(/learn/Uploading_a_project) Images are essential elements in most of the scienti c documents. LATEX provides several options
Copying a project to handle images and make them look exactly what you need. In this article is explained how to
(/learn/Copying_a_project) include images in the most common formats, how to shrink, enlarge and rotate them, and how to
Creating a project from a template reference them within your document.
(/learn/Creating_a_project_from_a_template)
Including images in ShareLaTeX
(/learn/Including_images_in_ShareLaTeX) Contents
Exporting your work from
1 Introduction
ShareLaTeX
2 The folder path to images
(/learn/Exporting_your_work_from_ShareLaTeX)
3 Changing the image size and rotating the picture
Using bibliographies in ShareLaTeX
(/learn/Using_bibliographies_in_ShareLaTeX) 4 Positioning
5 Captioning, labelling and referencing
Sharing your work with others
(/learn/Sharing_your_work_with_others) 5.1 Captions
Debugging Compilation timeout 5.2 Labels and cross-references
errors 6 Generating high-res and low-res images
(/learn/Debugging_Compilation_timeout_errors) 7 Reference guide
Knowledge Base 8 Further reading
(/learn/Kb/Knowledge_Base)
LaTeX Basics
Introduction
Creating your rst LaTeX document
(/learn/Creating_a_document_in_LaTeX) Below is a example on how to import a picture.
Choosing a LaTeX Compiler
(/learn/Choosing_a_LaTeX_Compiler) \documentclass{article}
\usepackage{graphicx}
Paragraphs and new lines \graphicspath{ {images/} }
(/learn/Paragraphs_and_new_lines)
Bold, italics and underlining \begin{document}
The universe is immense and it seems to be homogeneous,
(/learn/Bold,_italics_and_underlining)
in a large scale, everywhere we look at.
Lists (/learn/Lists)
\includegraphics{universe}
Errors (/learn/Errors)
There's a picture of a galaxy above
Mathematics \end{document}
Mathematical expressions
(/learn/Mathematical_expressions)
Subscripts and superscripts
(/learn/Subscripts_and_superscripts)
Brackets and Parentheses
(/learn/Brackets_and_Parentheses)
Fractions and Binomials
(/learn/Fractions_and_Binomials)
Aligning Equations
(/learn/Aligning_equations)
Operators (/learn/Operators) (/learn/File:InsertingImagesEx1.png)
Spacing in math mode
Latex can not manage images by itself, so we need to use the graphicx package. To use it, we
(/learn/Spacing_in_math_mode)
include the following line in the preamble: \usepackage{graphicx}
Integrals, sums and limits
(/learn/Integrals,_sums_and_limits)
The command \graphicspath{ {images/} }tells LATEX that the images are kept in a folder
Display style in math mode
named images under the current directory.
(/learn/Display_style_in_math_mode)
List of Greek letters and math The \includegraphics{universe}command is the one that actually included the image in
symbols the document. Here universe is the name of the le containing the image without the extension,
(/learn/List_of_Greek_letters_and_math_symbols)
then universe.PNG becomes universe. The le name of the image should not contain white
Mathematical fonts
https://www.sharelatex.com/learn/Inserting_Images 1/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
(/learn/Mathematical_fonts) spaces nor multiple dots.
References and Citations In the example at the introduction the command \graphicspath{ {images/} }tells LATEX to
look in the images folder. The path is relative to the current working directory.
Bibliography management in LaTeX
(/learn/Bibliography_management_in_LaTeX) The path to the folder can be relative (recommended) if it is in the same location as the main .tex
Bibliography management with le or in one of the sub-folders, or absolute if you have to specify the exact path. For example:
biblatex
(/learn/Bibliography_management_in_LaTeX)
%Path in Windows format:
Biblatex bibliography styles \graphicspath{ {c:/user/images/} }
(/learn/Biblatex_bibliography_styles)
%Path in Unix-like (Linux, OsX) format
Biblatex citation styles \graphicspath{ {/home/user/images/} }
(/learn/Biblatex_citation_styles)
Bibliography management with Notice that this command requires a trailing slash / and that the path is in between double
natbib
braces.
(/learn/Bibliography_management_with_natbib)
Natbib bibliography styles You can also set multiple paths if the images are saved in more than one folder. For instance, if
(/learn/Natbib_bibliography_styles) there are two folders named images1 and images2, use the command.
Natbib citation styles
(/learn/Natbib_citation_styles) \graphicspath{ {images1/}{images2/} }
Bibliography management with
bibtex If no path is set LATEX will look for pictures in the folder where the .tex le is saved.
(/learn/Bibliography_management_with_bibtex)
Open an example in ShareLaTeX (https://www.sharelatex.com/project/new/template?
Bibtex bibliography styles
zipUrl=/project/52f4102815577d644c0017fb/download/zip&templateName=InsertingImages&compiler=pd ate
(/learn/Bibtex_bibliography_styles)
Formatting
(/learn/File:InsertingImagesEx3.png)
Lengths in LATEX
(/learn/Lengths_in_LaTeX)
Headers and footers
(/learn/Headers_and_footers)
As you probably have guessed, the parameters inside the brackets [width=3cm, height=4cm]
Page numbering
de ne the width and the height of the picture. You can use di erent units for these parameters. If
(/learn/Page_numbering)
only the width parameter is passed, the height will be scaled to keep the aspect ratio.
Paragraph formatting
(/learn/Paragraph_formatting)
The length units can also be relative to some elements in document. If you want, for instance,
Line breaks and blank spaces make a picture the same width as the text:
(/learn/Line_breaks_and_blank_spaces)
Text alignment ShareLaTeX is a great professional tool to edit online,
(/learn/Text_alignment) share and backup your \LaTeX projects. Also offers a
rather large help documentation.
Page size and margins
(/learn/Page_size_and_margins) \includegraphics[width=\textwidth]{universe}
Single sided and double sided
documents
(/learn/Single_sided_and_double_sided_documents)
Multiple columns
(/learn/Multiple_columns)
Counters (/learn/Counters)
Code listing (/learn/Code_listing)
Code Highlighting with minted
(/learn/Code_Highlighting_with_minted)
Using colours in LaTeX
(/learn/Using_colours_in_LaTeX)
Footnotes (/learn/Footnotes)
Margin notes (/learn/Margin_notes)
Fonts
Font sizes, families, and styles
(/learn/Font_sizes,_families,_and_styles)
Font typefaces
(/learn/Font_typefaces) (/learn/File:InsertingImagesEx5.png)
Supporting modern fonts with
Instead of \textwidthyou can use any other default LATEX length: \columnsep, \linewidht,
XLATEX (/learn/XeLaTeX)
\textheight, \paperheight, etc. See the reference guide for a further description of these units.
Presentations There is another common option when including a picture within your document, to rotate it.
Beamer (/learn/Beamer) This can easily accomplished in LATEX:
Powerdot (/learn/Powerdot)
ShareLaTeX is a great professional tool to edit online,
Posters (/learn/Posters)
share and backup your \LaTeX projects. Also offers a
rather large help documentation.
Commands
\includegraphics[scale=1.2, angle=45]{lion-logo}
Commands (/learn/Commands)
Environments (/learn/Environments)
Field specific
Theorems and proofs
(/learn/Theorems_and_proofs)
Chemistry formulae
(/learn/Chemistry_formulae)
Feynman diagrams
(/learn/Feynman_diagrams)
Molecular orbital diagrams
https://www.sharelatex.com/learn/Inserting_Images 3/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
(/learn/Molecular_orbital_diagrams)
Chess notation
(/learn/Chess_notation)
Knitting patterns
(/learn/Knitting_patterns)
CircuiTikz package
(/learn/CircuiTikz_package)
(/learn/File:InsertingImagesEx4.png)
Pgfplots package
(/learn/Pgfplots_package)
Typing exams in LaTeX
(/learn/Typing_exams_in_LaTeX)
Knitr (/learn/Knitr)
Attribute Value Matrices
(/learn/Attribute_Value_Matrices)
The parameter angle=45rotates the picture 45 degrees counter-clockwise. To rotate the picture
Class files
clockwise use a negative number.
Understanding packages and class
les Open an example in ShareLaTeX (https://www.sharelatex.com/project/new/template?
(/learn/Understanding_packages_and_class_ zipUrl=/project/52f4102815577d644c0017fb/download/zip&templateName=InsertingImages&compiler=pd
les) ate
List of packages and class les
(/learn/List_of_packages_and_class_ les)
Writing your own package
Positioning
(/learn/Writing_your_own_package) In the previous section was explained how to include images in your document, but the
Writing your own class combination of text and images may not look as we expected. To change this we need to
(/learn/Writing_your_own_class) introduce a new environment.
Tips (/learn/Tips)
In the next example the figure will be positioned
right below this sentence.
\begin{figure}[h]
\includegraphics[width=8cm]{Plot}
\end{figure}
(/learn/File:InsertingImagesEx6.png)
The figureenvironment is used to display pictures as oating elements within the document.
This means you include the picture inside the gure environment and you don't have to worry
about it's placement, LATEX will position it in a such way that it ts the ow of the document.
Anyway, sometimes we need to have more control on the way the gures are displayed. An
additional parameter can be passed to determine the gure positioning. In the example,
begin{figure}[h], the parameter inside the brackets set the position of the gure to here.
Below a table to list the possible positioning values.
Parameter Position
Place the oat here, i.e., approximately at the same point it occurs in the source
h
text (however, not exactly at the spot)
https://www.sharelatex.com/learn/Inserting_Images 4/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
! Override internal parameters LaTeX uses for determining "good" oat positions.
Places the oat at precisely the location in the LATEX code. Requires the float
H
package. This is somewhat equivalent to h!.
In the next example you can see a picture at the top of the document, despite being declared
below the text.
\begin{figure}[t]
\includegraphics[width=8cm]{Plot}
\centering
\end{figure}
(/learn/File:InsertingImagesEx7.png)
The additional command \centeringwill centre the picture. The default alignment is left.
It's also possible to wrap the text around a gure. When the document contains small pictures
this makes it look better.
\begin{wrapfigure}{l}{0.25\textwidth}
\centering
\includegraphics[width=0.25\textwidth]{contour}
\end{wrapfigure}
https://www.sharelatex.com/learn/Inserting_Images 5/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
(/learn/File:InsertingImagesEx8.png)
For the commands in the example to work, you have to import the package wrap g. Add to the
preamble the line \usepackage{wrapfig}.
Now you can de ne the wrap gure environment by means of the commands
\begin{wrapfigure}{l}{0.25\textwidth} \end{wrapfigure}. Notice that the
environment has two additional parameters enclosed in braces. Below the code is explained with
more detail:
{l}
This de nes the alignment of the gure. Set l for left and r for right. Furthermore, if you are using
a book or any similar format, use instead o for the outer edge and i for the inner edge of the
page.
{0.25\textwidth}
This is the width of gure box. It's not the width of the image itself, that must be set in the
includegraphics command. Notice that the length is relative to the text width, but normal units
can also be used (cm, in, mm, etc). See the reference guide for a list of units.
\centering
This was already explained, but in this example the image will be centred by using its container as
reference, instead of the whole text.
For a more complete article about image positioning see Positioning images and tables
(/learn/Positioning_images_and_tables)
Captions
Let's start with a caption example:
\begin{figure}[h]
\caption{Example of a parametric plot ($\sin (x), \cos(x), x$)}
\centering
\includegraphics[width=0.5\textwidth]{spiral}
\end{figure}
https://www.sharelatex.com/learn/Inserting_Images 6/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
(/learn/File:InsertingImagesEx9.png)
It's really easy, just add the \caption{Some caption}and inside the braces write the text to
be shown. The placement of the caption depends on where you place the command; if it'a above
the includegraphics then the caption will be on top of it, if it's below then the caption will also be
set below the gure.
Captions can also be placed right after the gures. The sidecap package uses similar code to the
one in the previous example to accomplish this.
\documentclass{article}
\usepackage[rightcaption]{sidecap}
\begin{SCfigure}[0.5][h]
\caption{Example of a parametric plot.
This caption will be on the right}
\includegraphics[width=0.6\textwidth]{spiral}
\end{SCfigure}
(/learn/File:InsertingImagesEx10.png)
\usepackage[rightcaption]{sidecap}
As you may expect this line will import a package named sidecap, but there is an additional
parameter: rightcaption. This parameter establishes the placement of the caption at the right
of the picture, you can also use leftcaption. In book-like documents outercaption and innercaption
are also available. The names of these are self-descriptive.
\begin{SCfigure}[0.5][h] \end{SCfigure}
De nes an environment similar to gure. The rst parameter is the width of the caption relative to
the size of the image, as declared in includegraphics. The second parameter hworks exactly as in
the gure environment. See the placement section for more information.
You can do a more advanced management of the caption formatting. Check the further reading
section for references.
https://www.sharelatex.com/learn/Inserting_Images 7/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
\begin{figure}[h]
\centering
\includegraphics[width=0.25\textwidth]{mesh}
\caption{a nice plot}
\label{fig:mesh1}
\end{figure}
(/learn/File:InsertingImagesEx11.png)
\label{fig:mesh1}
This will set a label for this gure. Since labels can be used in several types of elements within the
document, it's a good practice to use a pre x, such as g: in the example.
\ref{fig:mesh1}
This command will insert the number assigned to the gure. It's automatically generated and will
be updated if insert some other gure before the referenced one.
\pageref{fig:mesh1}
This prints out the page number where the referenced image appears.
Another great characteristic in a LATEX document is the ability to automatically generate a list of
gures. This is straightforward.
\listoffigures
(/learn/File:InsertingImagesEx12.png)
This command only works on captioned gures, since it uses the caption in the table. The
example above lists the images in this article.
Important Note: When using cross-references your LATEX project must be compiled twice,
otherwise the references, the page references and the table of gures won't work.
This is accomplished by
\DeclareGraphicsExtensions{.png,.pdf}
The command above will ensure that if two les are encountered with the same base name but
di erent extensions (for example venndiagram.pdf and venndiagram.png), then the .png version
will be used rst, and in its absence the .pdf version will be used, this is also a good ideas if some
low-resolution versions are not available.
Once the report has been developed, to use the high-resolution .pdf version, we can change the
line in the preamble specifying the extension search order to
\DeclareGraphicsExtensions{.pdf,.png}
Improving on the technique described in the previous paragraphs, we can also instruct LATEX to
generate low-resolution .png versions of images on the y while compiling the document if there
is a PDF that has not been converted to PNG yet. To achieve that, we can include the following in
the preamble after \usepackage{graphicx}
\usepackage{epstopdf}
\epstopdfDeclareGraphicsRule{.pdf}{png}{.png}{convert #1
\OutputFile}
\DeclareGraphicsExtensions{.png,.pdf}
For the automatic conversion to work, we need to call pd atex with the --shell-escape
option.
For the nal production version, we must comment out the
\epstopdfDeclareGraphicsRule, so that only high-resolution PDF les are loaded. We'll
also need to change the order of precedence.
Reference guide
LATEX units and legths
Abbreviation Definition
https://www.sharelatex.com/learn/Inserting_Images 9/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
mm a millimetre
cm a centimetre
in an inch
latex
When compiling with latex, we can only use EPS images, which is a vector format.
pd atex
If we are compiling using "pd atex" to produce a PDF, then we can use a number of image
formats -
Further reading
For more information see
https://www.sharelatex.com/learn/Inserting_Images 10/11
5/12/17 Inserting Images ShareLaTeX, Online LaTeX Editor
8QweEXeEauFew&sig2=qamKo3qpid8CEqzsHhpIrQ&bvm=bv.60983673,d.aWM)
2017 ShareLaTeX Terms (/tos) Privacy (/privacy_policy) Security (/security) Contact () About (/about) Blog (/blog)
Universities (/university?ref=footer)
(http://www.twitter.com/sharelatex) (http://www.facebook.com/pages/ShareLaTeX/301671376556660)
(https://plus.google.com/115074691861228882827) (https://github.com/sharelatex/sharelatex)
https://www.sharelatex.com/learn/Inserting_Images 11/11