COMPGROUPS.NET | Post | Groups | Users | Stream | Browse | About | |

### A modified \includegraphics

• Email
• Follow

Hi all,

I need a macro that includes a graph but automatically adds a
'width=\textwidth' parameter if the included graph is wider than
\textwidth. Any ideas? Thanks.

Leo

 0

See related articles to this posting

On Nov 28, 6:07=A0am, Leo <sdl....@gmail.com> wrote:
> Hi all,
>
> I need a macro that includes a graph but automatically adds a
> 'width=3D\textwidth' parameter if the included graph is wider than
> \textwidth. Any ideas? Thanks.
>
> Leo

Dunno why graphicx doesn't have a maximum width function. workaround
is here

http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2007-08/msg00572=
..html

got it from the second entry here

http://tinyurl.com/yars8jv


 0

On 2009-11-28 11:38 +0000, Perkee wrote:
> On Nov 28, 6:07�am, Leo <sdl....@gmail.com> wrote:
>> Hi all,
>>
>> I need a macro that includes a graph but automatically adds a
>> 'width=\textwidth' parameter if the included graph is wider than
>> \textwidth. Any ideas? Thanks.
>>
>> Leo
>
> Dunno why graphicx doesn't have a maximum width function. workaround
> is here
>
> http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2007-08/msg00572.html
>
> got it from the second entry here
>
> http://tinyurl.com/yars8jv

Thank you for this. By the way the macro:

\newlength{\testwd}
\newcommand{\fitpic}[1]{%
\settowidth{\testwd}{\includegraphics{#1}}%
% \message{#1 width=\the\testwd, page=\the\textwidth}%
\ifthenelse{\lengthtest{\testwd>\textwidth}}{%
\noindent\includegraphics[width=\textwidth]{#1}}{%
\centering\includegraphics{#1}}}

seems to use includegraphics twice. Is that expensive (slow)?

Thanks again.

Leo

 0

Leo <sdl.web@gmail.com> wrote:

> I need a macro that includes a graph but automatically adds a
> 'width=\textwidth' parameter if the included graph is wider than
> \textwidth. Any ideas? Thanks.

\newcommand*{\maxwidth}{%
\ifdim\Gin@nat@width<\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother

\includegraphics[width=\maxwidth]{...}

Yours sincerely
Heiko <oberdiek@uni-freiburg.de>

 0

On 2009-11-28 12:10 +0000, Heiko Oberdiek wrote:
> Leo <sdl.web@gmail.com> wrote:
>
>> I need a macro that includes a graph but automatically adds a
>> 'width=\textwidth' parameter if the included graph is wider than
>> \textwidth. Any ideas? Thanks.
>
> \newcommand*{\maxwidth}{%
>   \ifdim\Gin@nat@width<\linewidth
>     \linewidth
>   \else
>     \Gin@nat@width
>   \fi
> }
> \makeatother
>
> \includegraphics[width=\maxwidth]{...}
>
> Yours sincerely
>   Heiko <oberdiek@uni-freiburg.de>

I've used this. Many thanks.

Leo

 0

 Leo <sdl.web@gmail.com> writes:
>On 2009-11-28 11:38 +0000, Perkee wrote:
>> On Nov 28, 6:07�am, Leo <sdl....@gmail.com> wrote:
>>>
>>> I need a macro that includes a graph but automatically adds a
>>> 'width=\textwidth' parameter if the included graph is wider than
>>> \textwidth. Any ideas? Thanks.
>>
>> Dunno why graphicx doesn't have a maximum width function. workaround
>> is here
>>
>> http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2007-08/msg00572.html
>>
>> got it from the second entry here
>>
>> http://tinyurl.com/yars8jv
>
>Thank you for this. By the way the macro:
>
>\newlength{\testwd}
>\newcommand{\fitpic}[1]{%
>  \settowidth{\testwd}{\includegraphics{#1}}%
>  % \message{#1 width=\the\testwd, page=\the\textwidth}%
>  \ifthenelse{\lengthtest{\testwd>\textwidth}}{%
>    \noindent\includegraphics[width=\textwidth]{#1}}{%
>    \centering\includegraphics{#1}}}
>
>seems to use includegraphics twice. Is that expensive (slow)?

potentially, yes.  the next entry in the thread, from heiko oberdiek,
is the one i use (when i'm doing figures, which isn't often):

\documentclass{article}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\begin{document}
\noindent
\includegraphics[width=\maxwidth]{picture.png}
\end{document}

i _think_ i had worked it out independently, actually.  (let's claim i
did: heiko doesn't need any more glory, and i'm a mere drudge... ;-)
--
Robin Fairbairns, Cambridge

 0

On 2009-11-28 15:03 +0000, Robin Fairbairns wrote:
> potentially, yes.  the next entry in the thread, from heiko oberdiek,
> is the one i use (when i'm doing figures, which isn't often):
>
> \documentclass{article}
> \usepackage{graphicx}
> \makeatletter
> \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
> \else\Gin@nat@width\fi}
> \makeatother
> \begin{document}
> \noindent
> \includegraphics[width=\maxwidth]{picture.png}
> \end{document}

I use this one too.

> i _think_ i had worked it out independently, actually. (let's claim i
> did: heiko doesn't need any more glory, and i'm a mere drudge... ;-)

;)

Leo

 0

rf10@cl.cam.ac.uk (Robin Fairbairns) wrote:

> \makeatletter
> \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
> \else\Gin@nat@width\fi}
> \makeatother
> \begin{document}
> \noindent
> \includegraphics[width=\maxwidth]{picture.png}
> \end{document}
>
> i _think_ i had worked it out independently, actually.  (let's claim i
> did: heiko doesn't need any more glory, and i'm a mere drudge... ;-)

As far as I can remember, it isn't my invention, but I cannot remember
the exact source.

Yours sincerely
Heiko <oberdiek@uni-freiburg.de>

 0
 comp.text.tex 36140 articles. 68 followers.

7 Replies
295 Views

Similar Articles

[PageSpeed] 43

• Email
• Follow

Similar Artilces:

\includegraphics and \includegraphics* difference
Does anyone know what is the difference between \includegraphics and \includegraphics* (yes, with a *)? montecinos.julio@gmail.com writes: > Does anyone know what is the difference between \includegraphics and > \includegraphics* (yes, with a *)? ,----[ grfguide, 4.4 Including Graphics Files ] | If * is present, then the graphic is clipped' to the size specified. If | * is omitted, then any part of the graphic that is outside the specified | bounding box' will over-print the surrounding text. `---- or read epslatex.{ps,pdf} cheerio ralf <montecinos.julio@gmail.com>...

lvalue -modifiable and non-modifiable
Can someone give and explain in simple terms a definition of lvalue? Also what are these modifiable and non-modifiable lvalues? I always thought that, if we can assign to anything then that anything is lvalue and if cannot assign to anything then that anything is not lvalue. "Kavya" <Lerner84@gmail.com> wrote: > Can someone give and explain in simple terms a definition of lvalue? Sure. The Standard can, in [6.3.2.1#1]: # An lvalue is an expression with an object type or an incomplete type # other than void; > Also what are these modifiable and non-modifiable lvalues...

Class & modifiers modifiers
Hi I want to make a question to all the ruby-lang people (I hope that somebody answered it). I'm writing a database GUI and I'm coding the backend using modules and classes. If I have this situation: module A protected def b_method() return 'foo->A' end end class B include A def b_method() return 'foo->B' end end Is B's method b_method() protected? Is it public? What the hell is this method (;-) ) ? Thanks in advance Kind regards Miquel ______________________________________________ LLama Gratis a cualquier PC del Mundo. ...

\includegraphics
Hi! I wanted include graphics with this command. I tested it with jpeg files (i read that that should be supported), but i get an error. How can i include jpeg files? Thanks, flox Florian Xaver wrote: > Hi! > > I wanted include graphics with this command. I tested it with jpeg files > (i read that that should be supported), but i get an error. > How can i include jpeg files? > > Thanks, flox That should be possible if you add something where you include the package "graphicx": \ifx\pdftexversion\undefined \usepackage[dvips]{graphicx} \else \usepackage[...

includegraphics
I have this odd problem. Heres is what i use, in a subsubsection, to include a picture: \begin{figure} \includegraphics[width=8cm,height=6cm]{Misc/loga.jpg} \end{figure I then compile the tex file with pdflatex. The odd thing is when i look through the pdf file the includedgraphics loga.jpg is placed roughtly 1 page above where it should be located. What could be wrong? cp wrote: > I have this odd problem. > > Heres is what i use, in a subsubsection, to include a picture: > > \begin{figure} > \includegraphics[width=8cm,height=6cm]{Misc/loga.jpg} > \end{figure > &...

Modify it !
Hello to all, I have made a calendar from 1900-2000(Except leap years which i do my own!)It gives you the day when inputting the month and date. I want to know how can i improve it in terms of complexity(of concepts).Waiting for your creative ideas james. ------------------------- #include<conio.h> #include<stdio.h> void days(int); int *cal(int,int,int); void main() { char ch='y'; int month=0,date=0,i,year,year1,*day; clrscr(); printf("\t\t\t\tCALENDAR \n\n\t\t\t 1900--2000\n\n"); printf("\n Enter the year(1900-2000)"); scanf("%d",&...

vintage disk drive dilema
Hi Folks, I figured I throw this dilema out there as something that all users of vintage articles have to deal with from time to time. I strongly believe that this old stuff should be used from time to time, but there are usually compromises involved in such usage. I am currently using my original Disk II drive which I purchased in 1978. Right now I am using it as drive 1 on my primary Apple II and it works fine, except that it does not do well reading Atarisoft game disks. Unfortunately I find that those old time games are kind of fun, and I would like to play those games from t...

modified a*?
The following problem: Given a 2D array of integers, starting at a point A (x, y), find the LONGEST way, so that the summed up values along the way don't exceed some given value N. Any ideas? sauron wrote: > The following problem: > > Given a 2D array of integers, starting at a point A (x, y), find the > LONGEST way, so that the summed up values along the way don't exceed some > given value N. > > Any ideas? If your integers can be negative then this problem is likely to be NP, so I'll assume that all integers are non-negative. Furthermore, I'll ass...

how to modify...
i have in a xml file this <post> <titolo>Forno solare</titolo> <data>28/08/2006</data> <testo> Ecco il mio forno solare, bla , bla, bla , bla, bla , bla.... </testo> </post> and in xsl file this: <div id="post"> <xsl:for-each select="news/post"> <xsl:sort data-type="text" select="data" order="descending"/> <h1><xsl:value-of select="titolo" /></h1> <...