|
|
A modified \includegraphics
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
|
|
|
|
Reply
|
Leo
|
11/28/2009 11:07:37 AM |
|
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
|
|
|
|
Reply
|
Perkee
|
11/28/2009 11:38:40 AM
|
|
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
|
|
|
|
Reply
|
Leo
|
11/28/2009 11:54:02 AM
|
|
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
|
|
|
|
Reply
|
Heiko
|
11/28/2009 12:10:47 PM
|
|
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
|
|
|
|
Reply
|
Leo
|
11/28/2009 1:27:10 PM
|
|
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
|
|
|
|
Reply
|
rf10
|
11/28/2009 3:03:57 PM
|
|
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
|
|
|
|
Reply
|
Leo
|
11/28/2009 3:46:37 PM
|
|
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
|
|
|
|
Reply
|
Heiko
|
11/28/2009 4:55:21 PM
|
|
|
7 Replies
231 Views
(page loaded in 0.097 seconds)
Similiar Articles:7/10/2012 7:12:39 AM
|
|
|
|
|
|
|
|
|