How to Upload a Picture Onto Latex

Images are essential elements in virtually of the scientific documents. LaTeTen provides several options to handle images and brand them look exactly what y'all demand. In this article we explain how to include images in the most mutual formats, how to compress, overstate and rotate them, and how to reference them within your document.

Contents

  • i Introduction
  • 2 The folder path to images
  • 3 Irresolute the epitome size and rotating the picture show
  • 4 Positioning
  • 5 Captioning, labelling and referencing
    • 5.one Captions
    • 5.2 Labels and cross-references
  • 6 Generating high-res and depression-res images
  • 7 Reference guide
  • 8 Further reading

Introduction

Below is an example on how to import a motion-picture show.

                            \documentclass              {article}              \usepackage              {graphicx}              \graphicspath              {              {./images/}              }              \begin              {document}              The universe is immense and it seems to be homogeneous,  in a large scale, everywhere we expect at.              \includegraphics              {universe}              There's a picture show of a galaxy in a higher place              \end              {certificate}            

Example of inserting an image

Latex can non manage images by itself, so nosotros need to use the graphicx package. To use it, we include the post-obit line in the preamble: \usepackage{graphicx}.

The command \graphicspath{ {./images/} } tells 50aTeX that the images are kept in a folder named images under the directory of the main document.

The \includegraphics{universe} command is the ane that actually included the paradigm in the certificate. Here universe is the proper noun of the file containing the prototype without the extension, then universe.PNG becomes universe. The file name of the image should not contain white spaces nor multiple dots.

Note: The file extension is allowed to be included, merely information technology's a skillful idea to omit it. If the file extension is omitted it volition prompt LaTeX to search for all the supported formats. For more details see the section about generating high resolution and low resolution images.

 Open an images example in Overleaf

The folder path to images

When working on a document which includes several images it's possible to go on those images in i or more than separated folders so that your project is more organised.

The command \graphicspath{ {images/} } tells 50aTeX to expect in the images folder. The path is relative to the electric current working directory—then, the compiler will await for the file in the aforementioned binder as the code where the paradigm is included. The path to the folder is relative by default, if there is no initial directory specified, for instance

                        %Path relative to the .tex file containing the \includegraphics control            \graphicspath            {            {images/}            }          

This is a typically straightforward way to accomplish the graphics folder within a file tree, but can leads to complications when .tex files within folders are included in the mail .tex file. And then, the compiler may end upwards looking for the images folder in the wrong place. Thus, information technology is best practice to specify the graphics path to be relative to the main .tex file, denoting the master .tex file directory equally ./ , for instance:

                        %Path relative to the primary .tex file                        \graphicspath            {            {./images/}            }          

as in the introduction.

The path can also be accented , if the exact location of the file on your system is specified. For example, if you were working on a local LaTeX installation on your own computer:

                        %Path in Windows format:            \graphicspath            {            {c:/user/images/}            }            %Path in Unix-like (Linux, Mac Bone) format            \graphicspath            {            {/domicile/user/images/}            }          

Notice that this control requires a trailing slash / and that the path is in between double braces.

Yous can also prepare multiple paths if the images are saved in more one folder. For case, if there are two folders named images1 and images2, employ the control

                        \graphicspath            {            {./images1/}{./images2/}            }          

 Open an images example in Overleaf

Changing the epitome size and rotating the picture

If we want to further specify how 50aTeTen should include our image in the document (length, height, etc), we can pass those settings in the following format:

                            \brainstorm              {certificate}              Overleaf is a bang-up professional tool to edit online documents,  share and backup your              \LaTeX              {}              projects. Likewise offers a  rather large help documentation.              \includegraphics              [calibration=1.five]              {overleaf-logo}            

Example of changing image size

The command \includegraphics[scale=ane.five]{overleaf-logo} volition include the epitome overleaf-logo in the certificate, the extra parameter scale=1.5 volition do exactly that, scale the image 1.five of its existent size.

You lot tin also scale the prototype to a some specific width and acme.

                            \begin              {document}              Overleaf is a keen professional tool to edit online documents,  share and backup your              \LaTeX              {}              projects. Likewise offers a  rather large help documentation.              \includegraphics              [width=5cm, summit=4cm]              {overleaf-logo}            

Example of setting image height and width

Every bit you probably take guessed, the parameters inside the brackets [width=3cm, height=4cm] define the width and the peak of the pic. You tin employ different units for these parameters. If only the width parameter is passed, the height volition be scaled to go on the aspect ratio.

The length units can as well exist relative to some elements in document. If you want, for case, make a picture the aforementioned width as the text:

                            \begin              {certificate}              The universe is immense and it seems to be homogeneous,  in a large scale, everywhere we expect at.              \includegraphics              [width=\textwidth]              {universe}            

Example of image set to text width

Instead of \textwidth yous can utilize any other default LaTeastwardX length: \columnsep, \linewidth, \textheight, \paperheight, etc. See the reference guide for a further description of these units.

There is another mutual choice when including a picture show inside your document, to rotate it. This tin can easily accomplished in 50aTeastTen:

                            \begin              {document}              Overleaf is a smashing professional tool to edit online,  share and fill-in your              \LaTeX              {}              projects. Also offers a  rather large base of help documentation.              \includegraphics              [scale=1.2, angle=45]              {overleaf-logo}            

Example of rotating an image

The parameter bending=45 rotates the picture 45 degrees counter-clockwise. To rotate the moving-picture show clockwise use a negative number.

Positioning

In the previous section was explained how to include images in your document, but the combination of text and images may non look equally we expected. To change this we demand to innovate a new environment.

              In the adjacent example the figure will exist positioned  right below this sentence.              \begin              {figure}[h]              \includegraphics              [width=8cm]              {Plot}              \end              {figure}            

Example of positioning figures

The figure surround is used to display pictures as floating elements within the document. This means yous include the picture inside the effigy environment and y'all don't have to worry virtually it's placement, LaTdue eastX will position information technology in a such way that it fits the period of the document.

Anyway, sometimes we demand to take more than control on the way the figures are displayed. An boosted parameter tin be passed to determine the effigy positioning. In the example, begin{effigy}[h], the parameter inside the brackets set the position of the figure to here . Below a table to list the possible positioning values.

Parameter Position
h Place the float hither, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
t Position at the elevation of the folio.
b Position at the bottom of the page.
p Put on a special page for floats just.
! Override internal parameters LaTeX uses for determining "good" float positions.
H Places the float at precisely the location in the FiftyaTeX code. Requires the float parcel, though may cause problems occasionally. This is somewhat equivalent to h!.

In the next example yous can see a picture at the top of the document, despite being declared beneath the text.

              In this picture you lot can come across a bar graph that shows the results of a survey which involved some important data studied as time passed.              \brainstorm              {figure}[t]              \includegraphics              [width=8cm]              {Plot}              \centering              \end              {effigy}            

Example of bar graph

The boosted command \centering will center the picture. The default alignment is left.

It's also possible to wrap the text around a figure. When the document contains pocket-size pictures this makes it look better.

                            \begin              {wrapfigure}{r}{0.25\textwidth              }              %this figure volition be at the right              \centering              \includegraphics              [width=0.25\textwidth]              {mesh}              \end              {wrapfigure}              At that place are several ways to plot a function of 2 variables,  depending on the information you are interested in. For  instance, if y'all want to meet the mesh of a part so it  easier to run into the derivative you can use a plot like the  one on the left.              \begin              {wrapfigure}{50}{0.25\textwidth              }              \centering              \includegraphics              [width=0.25\textwidth]              {profile}              \end              {wrapfigure}              On the other side, if you lot are only interested on sure values y'all can utilise the contour plot, you  tin can use the contour plot, you can use the contour  plot, you can utilize the contour plot, you lot can use  the profile plot, you can use the contour plot,  yous tin can employ the contour plot, like the one on the left.  On the other side, if you lot are only interested on  sure values you tin can apply the contour plot, you  can use the contour plot, you tin can use the profile  plot, y'all can use the contour plot, y'all can apply the  contour plot, you tin can use the contour plot,  you can use the profile plot,  like the one on the left.            

Example of plot

For the commands in the example to work, you take to import the package wrapfig. Add to the preamble the line \usepackage{wrapfig}.

At present you tin ascertain the wrapfigure surroundings by ways of the commands \brainstorm{wrapfigure}{l}{0.25\textwidth} \finish{wrapfigure}. Detect that the surroundings has 2 additional parameters enclosed in braces. Below the code is explained with more detail:

{l}
This defines the alignment of the figure. Set up l for left and r for correct. Furthermore, if you are using a volume or whatever similar format, employ instead o for the outer edge and i for the inner border of the folio.
{0.25\textwidth}
This is the width of effigy box. It'due south not the width of the paradigm itself, that must be set in the \includegraphics command. Notice that the length is relative to the text width, but normal units can besides be used (cm, in, mm, etc). See the reference guide for a list of units.
\centering
This was already explained, but in this case the image will exist centred by using its container as reference, instead of the whole text.

For a more complete article almost epitome positioning meet Positioning images and tables

 Open an images example in Overleaf

Captioning, labelling and referencing

Captioning images to add together a cursory description and labelling them for further reference are two important tools when working on a lengthy text.

Captions

Let's showtime with a caption instance:

                            \brainstorm              {effigy}[h]              \caption              {Example of a parametric plot ($              \sin                                          (              x              )              ,                            \cos              (              x              )              , x              $)}              \centering              \includegraphics              [width=0.5\textwidth]              {spiral}              \end              {figure}            

Example of parametric plot

It'south really easy, just add the \caption{Some explanation} and inside the braces write the text to be shown. The placement of the explanation depends on where you place the command; if it's in a higher place the \includegraphics then the caption will be on summit of it, if it'due south below then the caption will also be set up below the figure.

Captions can too be placed right after the figures. The sidecap bundle uses similar code to the i in the previous case to accomplish this.

                            \documentclass              {article}              \usepackage              [rightcaption]              {sidecap}              \usepackage              {graphicx}              %bundle to manage images              \graphicspath              {              {images/}              }              \begin              {SCfigure}[0.5][h]              \explanation              {Using over again the picture of the universe. This caption volition be on the right}              \includegraphics              [width=0.6\textwidth]              {universe}              \end              {SCfigure}            

Example of parametric plot with caption

At that place are 2 new commands

\usepackage[rightcaption]{sidecap}
As you may wait this line volition 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, y'all can also apply leftcaption. In book-similar documents outercaption and innercaption are also available. The names of these are self-descriptive.
\begin{SCfigure}[0.5][h] \end{SCfigure}
Defines an environment like to figure. The get-go parameter is the width of the caption relative to the size of the paradigm, as declared in \includegraphics. The second parameter h works exactly as in the figure environs. Run into the placement department for more information.

You lot tin can practice a more advanced management of the caption formatting. Check the further reading section for references.

Labels and cantankerous-references

Figures, just as many other elements in a LaTeastward10 document (equations, tables, plots, etc) can exist referenced within the text. This is very like shooting fish in a barrel, just add a \characterization to the figure or SCfigure surround, then after use that characterization to refer the picture.

                            \begin              {figure}[h]              \centering              \includegraphics              [width=0.25\textwidth]              {mesh}              \caption              {a nice plot}              \label              {fig:mesh1}              \end              {figure}              As you can see in the effigy              \ref              {fig:mesh1}, the  function grows near 0. Besides, in the folio              \pageref              {fig:mesh1}              is the aforementioned case.            

Example of figure with label

In that location are three commands that generate cross-references in this example.

\characterization{fig:mesh1}
This will set a label for this figure. Since labels can be used in several types of elements inside the certificate, it'due south a good practice to utilize a prefix, such every bit fig: in the example.
\ref{fig:mesh1}
This command will insert the number assigned to the figure. Information technology's automatically generated and volition be updated if insert some other figure earlier the referenced one.
\pageref{fig:mesh1}
This prints out the page number where the referenced image appears.

The \caption is mandatory to reference a effigy.

Another corking characteristic in a LaTdue east10 certificate is the power to automatically generate a list of figures. This is straightforward.

Example of list of figures

This command merely works on captioned figures, since it uses the explanation in the table. The case higher up lists the images in this article.

Important Notation: When using cross-references your FiftyaTe10 project must be compiled twice, otherwise the references, the page references and the tabular array of figures won't work—Overleaf takes care of that for y'all.

Generating high-res and depression-res images

And so far while specifying the image file name in the \includegraphics command nosotros have omitted file extensions. However, that is not necessary, though it is ofttimes useful. If the file extension is omitted, LaTeX volition search for any supported epitome format in that directory, and volition search for diverse extensions in the default order (which can be modified).

This is useful in switching between development and production environments. In a development environment (when the article/report/book is still in progress), it is desirable to use low-resolution versions of images (typically in .png format) for fast compilation of the preview. In the production environment (when the final version of the article/written report/book is produced), information technology is desirable to include the high-resolution version of the images.

This is accomplished past

  • Non specifying the file extension in the \includegraphics command, and
  • Specifying the desired extension in the preamble.

Thus, if nosotros have two versions of an epitome, venndiagram.pdf (high-resolution) and venndiagram.png (low-resolution), then we can include the following line in the preamble to use the .png version while developing the study -

                        \DeclareGraphicsExtensions            {.png,.pdf}          

The command in a higher place will ensure that if two files are encountered with the same base proper name merely different extensions (for case venndiagram.pdf and venndiagram.png), then the .png version will exist used first, and in its absence the .pdf version will exist used, this is also a good ideas if some low-resolution versions are not available.

Once the report has been developed, to utilize the high-resolution .pdf version, we can change the line in the preamble specifying the extension search guild to

                        \DeclareGraphicsExtensions            {.pdf,.png}          

Improving on the technique described in the previous paragraphs, we tin also instruct LaTeX to generate depression-resolution .png versions of images on the fly while compiling the certificate if at that place is a PDF that has non 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}          

If venndiagram2.pdf exists just not venndiagram2.png, the file venndiagram2-pdf-converted-to.png will be created and loaded in its place. The control convert #1 is responsible for the conversion and additional parameters may exist passed between catechumen and #1. For case - convert -density 100 #1.

There are some important things to take in heed though:

  • For the automatic conversion to work, we need to call pdflatex with the --shell-escape option.
  • For the last production version, we must comment out the \epstopdfDeclareGraphicsRule, so that but high-resolution PDF files are loaded. We'll as well need to change the order of precedence.

 Open an images case in Overleaf

Reference guide

LaTeastwardTen units and legths

Abbreviation Definition
pt A bespeak, is the default length unit. About 0.3515mm
mm a millimetre
cm a centimetre
in an inch
ex the height of an x in the current font
em the width of an m in the current font
\columnsep distance between columns
\columnwidth width of the column
\linewidth width of the line in the current environment
\paperwidth width of the page
\paperheight height of the page
\textwidth width of the text
\textheight height of the text
\unitlength units of length in the moving-picture show environment.

About paradigm types in LaTeX

latex
When compiling with latex, we can only use EPS images, which is a vector format.
pdflatex
If nosotros are compiling using "pdflatex" to produce a PDF, and so we can use a number of image formats -
          JPG: Best choice if we want to insert photos    PNG: Best option if we want to insert diagrams (if a vector version could not be generated) and screenshots    PDF: Even though we are used to seeing PDF documents, a PDF can also store images     EPS: EPS images can be included using the          epstopdf          package (we just need to install the bundle, we          don't need to utilize          \usepackage{}          to include it in our document.)        
Vector format or bitmap format?
Images can be of either vector format of bitmap format. Generally nosotros don't demand to worry near information technology, but if we practise happen to know the format the image is in, we can use that data to choose an appropriate image format to include in our LaTeX document. If we take an epitome in vector format, we should go for PDF or EPS. If we accept it in bitmap format, we should go for JPG or PNG, as storing bitmap pictures in PDF or EPS takes a lot of disk space.

 Open an images example in Overleaf

Farther reading

For more information run into

  • Positioning images and tables
  • Lists of tables and figures
  • Single sided and double sided documents
  • Lengths in LaTeX
  • floatrow parcel for advanced explanation managing of floating elements (tables and figures)
  • sidecap bundle documentation, for side-figure captions
  • epstopdf packet documentation (PDF to EPS conversion)

jonesthavill.blogspot.com

Source: https://www.overleaf.com/learn/latex/Inserting_Images

0 Response to "How to Upload a Picture Onto Latex"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel