[Tex/LaTex] Why has no one told me I can use rubber lengths for graphics? Is that bad

graphicspositioningscaling

I just had a thought. Quite commonly when I define a figure graphics I write something like:

\begin{figure}[btp]
    \centering
    \includegraphics[width=0.95\textwidth]
                    {example.png}
    \caption{foo bar buzz}
\end{figure}

But today, it struck me, that I can do:

\begin{figure}[btp]
    \centering
    \includegraphics[width=0.95\textwidth plus 0.05\textwidth minus 0.05\textwidth]
                    {example.png}
    \caption{foo bar buzz}
\end{figure}

Why has noone told me about this before? 🙂

And more importantly, are there any good reasons not to do this?

EDIT: Just to clarify, my thought was that this would be used to avoid widows and orphans. But maybe that doesn't even work?

Best Answer

Nobody told you because, simply, you can't do it.

This runs without error:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=10pt plus 10pt minus 2pt]{example-image.pdf}
\end{document}

but this is not a sign that it does something according to your wish. Indeed, it's sufficient to look at the output:

enter image description here

Your code

\includegraphics[width=0.95\textwidth plus 0.05\textwidth minus 0.05\textwidth]

makes TeX stop with

! Missing \endcsname inserted.
<to be read again> 
                   \def 

that's due to some \csname construction that finds \textwidth before \endcsname and this token is illegal in that context.

What's the problem? The length you specify for width is used to set the width of a box and a box has a fixed width. Rubber lengths are used for specifying glue that can shrink or stretch.

Related Question