Graphics, Figures & Tablesproblem with includegraphics

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
syborg
Posts: 3
Joined: Fri Apr 24, 2015 9:41 pm

problem with includegraphics

Post by syborg »

hello,

I simply want to insert a jpg file in a page. Moreover I want the height of the image to fit exactly the height of the page, and the width of the image to be precisely centered in the page.

When I put \includegraphics{my_image.jpg}
the image is inserted with a left and a top margin, regardless the scaling values (always the same margins for all scaling values of the image).

I don't want to use \includepdf because when I convert my jpg file into pdf file there is big loss of quality.

How can I get my image inserted as I want?

Recommended reading 2024:

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

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

problem with includegraphics

Post by Johannes_B »

Hi and welcome,

you can specify the height and the width of picture as a fraction of the text width/height.

\includegraphics[height=\textheight,keepaspectratio]{YourFile} will print the image textheight high. Now the image might be to wide for the text to fit. I will stick over theright margin.

You could use a makebox or package adjustbox to center the image, just as Martin described it in his answer over at TeX.Stackexchange. Center figure that is wider than \textwidth

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage[export]{adjustbox}[2011/08/13]
\begin{document}
\begin{figure}
\includegraphics[width=1.2\textwidth,center]{image}%
\caption{Caption}
\label{fig:key}
\end{figure}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
syborg
Posts: 3
Joined: Fri Apr 24, 2015 9:41 pm

Re: problem with includegraphics

Post by syborg »

\includegraphics[height=\textheight,keepaspectratio]{YourFile} is better, since it centers the image within the page, but still the image heigth does not fit the page height....

I tried to tweak it, changing the values of \voffset and \hoffset locally before \includegraphics, and it works. But of course the rest of the document has those \voffset and \hoffset values also and is completely wrong.

But when if I put back \voffset and \hoffset to 0 after \includegraphics (to get the rest of the document rigth), the image again is not at the rigth position...

How can I change locally (just for one page) the \voffset and \hoffset value ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

problem with includegraphics

Post by Johannes_B »

Wait, page height? So this is not an image within the normal text. The are special packages, that deal with absolute positioning on the page and allow to place a picture wherever you want. eso-pic just got an update on CTAN, textpos is also available. You can even do it with TikZ, if you are already using it.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
syborg
Posts: 3
Joined: Fri Apr 24, 2015 9:41 pm

problem with includegraphics

Post by syborg »

Great ! it works perfectly well using Tikz like that:

Code: Select all

Code, edit and compile here:
\begin{tikzpicture}[remenber picture, overlay]
\draw (current page.center} node {\includegraphics{my image}};
\end{tikzpicure}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Thanks a lot !
Post Reply