Graphics, Figures & TablesDetermining Size of Image prior to its Display

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ceke
Posts: 13
Joined: Thu Nov 20, 2008 9:45 am

Determining Size of Image prior to its Display

Post by ceke »

Hej,

I'm using the graphicx package to include pictures into a slide presentation.

The following works fine:

Code: Select all

\includegraphics[width=\textwidth,height=.75\textheight,keepaspectratio]{figure.png}
This automatically makes the figure fill the "printable" area.

What I would like to do, though, is to use the above call within a {minipage} environment, and I would like to adjust the width of the {minipage} relative to the width of the scaled image.

So, is there a way of determining the width a picture will have, prior to actually including it, so that I can create the {minipage}?

Many thanks in advance,
/Johan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Determining Size of Image prior to its Display

Post by localghost »

You are probably looking for something like the varwidth package.


Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
ceke
Posts: 13
Joined: Thu Nov 20, 2008 9:45 am

Re: Determining Size of Image prior to its Display

Post by ceke »

Hej,

That could have been exactly what I was looking for. Unfortunately it does not work.

I'm using Beamer and would like to do some customized block environment, for example to show a boxed image, automatically scaled to fit the slide. Problem is that the \begin{block}...\end{block} automatically spans the whole \textwidth. Placing it in a minipage enabled me to limit the width. With the varwidth environment this does not work.

My best bet now is to find the original definition of the block environment and modify it. Any ideas of in which file (in Beamer) this is defined?

/Johan
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Determining Size of Image prior to its Display

Post by Stefan Kottwitz »

Hi Johan,

have a look at my post here: Beamer block width.

Stefan
LaTeX.org admin
ceke
Posts: 13
Joined: Thu Nov 20, 2008 9:45 am

Determining Size of Image prior to its Display

Post by ceke »

PROBLEM SOLVED!

So, this is how I did it, Beamer lingo:

-----------------------------

Code: Select all

\newlength{\mywidth}

% Just find out the width of the image after scaling, don't actually show it
\settowidth{\mywidth}{\includegraphics[width=\textwidth,height=.75\textheight,keepaspectratio]{myimage.jpg}}

% Now build the beamer block with the width determined above and place image
\begin{minipage}{\mywidth}
  \begin{block}{}
     \includegraphics[width=\mywidth]{myimage.jpg}
  \end{block}
\end{minipage}
Post Reply