Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Build \raisebox feature into \includegraphics

742 views
Skip to first unread message

Martin Scharrer

unread,
Jul 1, 2011, 6:55:31 AM7/1/11
to
This is a request for comments about a planned feature.

The `graphicx` package provides `\includegraphics` with a lot of
functions like scaling, size adjustments and trimming. Most of these
features are also provided for normal text using macros like `
\scalebox`, `\resizebox`, etc. The `adjustbox` package also adds the
missing `\trimbox` and `\clipbox` macros, as well as the general
`adjustbox` which accepts the same key=value option as `
\includegraphics` and in fact simply uses the `graphics/x` code for
the user interface.

What I'm missing are features provided by `\raisebox` especially the
one provided by the two optional arguments to set the official height
and width which the box reserves, to given values. Removing an outer `
\raisebox` wrapper b y having a `raise` option for `\includegraphics
would be convenient and shorter but would be much more important to
`adjustbox`, which would otherwise loose the benefit of allowing for
verbatim content. Because both share the same key=value system (which
manipulates how the internally token register holding the image or
code) it should be easily possible to implement this for both at the
same time.

I'm still not sure about the user interface. Maybe allowing for
`raise=<length>` as well as `raise={<length>}[<height>][<depth>]` to
mirror the `\raisebox` interface. Also dedicated options `set height`
and `set depth` would be possible. Because `adjustbox` provides `
\height`, `\depth`, `\width` and `\totalheight` the `trim` option
could also be (mis-?)used to simply trim the necessary amount off. So
instead of setting the depth to e.g. 5pt the user would need to use
`trim=0 {\depth-5pt} 0 0`. However, this is not supported by `
\includegraphics` (both `\depth` and using subtraction) as well as
less user friendly an difficult to combine with another, "normal"
`trim` or `viewport` option. Using `trim` for this would not by
combinable with a `clip`. (E.g. clip of some margin, raise it by 10pt
and set the depth to 0pt would not be possible).

I would be happy to receive comments about this planned feature, its
possible implementation and user interface.

Thanks a lot,
Martin Scharrer

Enrico Gregorio

unread,
Jul 1, 2011, 7:27:04 AM7/1/11
to
Martin Scharrer <martin....@gmail.com> wrote:

I endorse this proposal; I actually have a tentative small
package to be loaded on top of graphicx that does this.

A very common problem is aligning images in a tabular environment:

\begin{tabular}{p{5cm}c}
Descriptive text ... & \includegraphics[...]{image} \\
...
\end{tabular}

With a "raise" option or maybe a "topalign" in such a way that
the image has the height of \strut, the alignment would be
correct.

Ciao
Enrico

m.maunier

unread,
Jul 1, 2011, 10:45:49 AM7/1/11
to
May be i am completely away of the question, but i personnaly use
a special macro to raise or lower different objects :
(yes i know, it would be better into includegraphics)

here is the code (modification of an original code from JC Charpentier ) :

-----------------------8<----------------------------------
\makeatletter
%% to place object verticaly with a coeff
% usage :
% \placeobjet[decalage]{coeff}{objet}
% decalage (optionnel) ---> lower or raise the box
% coeff=1 ---> at top [b]
% coeff=0.5 ---> in the middle [m]
% coeff=0 ---> bottom [t]
% but you can use any coeff

\def\placeobjet{\@ifnextchar[{\placeobjet@ii}{\placeobjet@i}}
\def\placeobjet@i#1#2{%
\placeobjet@ii[0cm]{#1}{#2}%
}
\def\placeobjet@ii[#1]#2#3{%
\leavevmode%
\setbox0=\hbox{#3}%
\dimen0=\dp0%
\advance\dimen0 \ht0 %\dimen0 is the total height of the box
\dimen1=\ht0%\dimen1 is actual coeff * total
\dimen2=#2\dimen0 %\dimen2 is asked coeff * total
\ifdim\dimen1<\dimen2%
\advance\dimen2 -\dimen1%
\advance\dimen2 -#1%
\raise \dimen2 \box0%
\else%
\advance\dimen1 -\dimen2%
\advance\dimen1 -#1%
\lower \dimen1 \box0%
\fi%
}

\makeatother

-----------------------8<----------------------------------

*************************************************************
an example of how to use it : (you can use \includegraphics instead of \carre)


\documentclass{minimal}
\makeatletter
\def\placeobjet{\@ifnextchar[{\placeobjet@ii}{\placeobjet@i}}
\def\placeobjet@i#1#2{%
\placeobjet@ii[0cm]{#1}{#2}%
}
\def\placeobjet@ii[#1]#2#3{%
\leavevmode%
\setbox0=\hbox{#3}%
\dimen0=\dp0%
\advance\dimen0 \ht0 %\dimen0 contient la hauteur totale de la boite
\dimen1=\ht0%\dimen1 contient le coeff en cours * total
\dimen2=#2\dimen0 %\dimen2 contient le coeff demandé * total
\ifdim\dimen1<\dimen2%
\advance\dimen2 -\dimen1%
\advance\dimen2 -#1%
\raise \dimen2 \box0%
\else%
\advance\dimen1 -\dimen2%
\advance\dimen1 -#1%
\lower \dimen1 \box0%
\fi%
}
\makeatother
\newcommand\carre{\fbox{\parbox{1cm}{\rule[1cm]{0cm}{0cm}}}}

\begin{document}
Some text before \_ \placeobjet{1}{\carre} \ \_ \placeobjet{.5}{\carre}\ \_
\placeobjet{0}{\carre}
\end{document}

*************************************************************

Hope it will help, even if it could certainly be improved.

Sincerely,
M.Maunier

GL

unread,
Jul 1, 2011, 10:55:50 AM7/1/11
to
Le 01/07/2011 16:45, m.maunier a écrit :
> May be i am completely away of the question, but i personnaly use
> a special macro to raise or lower different objects :
> (yes i know, it would be better into includegraphics)
>
> here is the code (modification of an original code from JC Charpentier ) :

Could be rewritten in a more readable way:

\documentclass{minimal}
\makeatletter

\newcommand\placeobjet [3][0pt]{\begingroup \leavevmode \sbox\@tempboxa
{#3}%
\dimen@ \dimexpr \dp\@tempboxa +\ht\@tempboxa
\dimen@i \dimexpr \ht\@tempboxa
\dimen@ii #2\dimen@
\ifdim \ht\@tempboxa <#2\dimen@ \raise \dimexpr #2\dimen@
-\ht\@tempboxa -#1
\else \lower \dimexpr \ht\@tempboxa
-#2\dimen@ -#1
\fi
\box\@tempboxa \endgroup

GL

unread,
Jul 1, 2011, 10:59:09 AM7/1/11
to
Le 01/07/2011 16:55, GL a écrit :
> Le 01/07/2011 16:45, m.maunier a écrit :
>> May be i am completely away of the question, but i personnaly use
>> a special macro to raise or lower different objects :
>> (yes i know, it would be better into includegraphics)
>>
>> here is the code (modification of an original code from JC Charpentier
>> ) :
>
> Could be rewritten in a more readable way:

\documentclass{minimal}
\makeatletter

\newcommand\placeobjet [3][0pt]{\begingroup \leavevmode \sbox\@tempboxa
{#3}%
\dimen@ \dimexpr \dp\@tempboxa +\ht\@tempboxa

\raise \dimexpr #2\dimen@ -\ht\@tempboxa

+ \ifdim \ht\@tempboxa <#2\dimen@ -\fi #1

\box\@tempboxa \endgroup
}
\makeatother
\newcommand\carre{\fbox{\parbox{1cm}{\rule[1cm]{0cm}{0cm}}}}

\begin{document}
Some text before \_ \placeobjet{1}{\carre} \ \_
\placeobjet{.5}{\carre}\ \_ \placeobjet{0}{\carre}
\end{document}

Sorry i missed a factorisation in my last post ;-)

m.maunier

unread,
Jul 1, 2011, 11:06:26 AM7/1/11
to
L'incroyable GL a écrit en ce jour merveilleux du 01/07/2011 16:59 :
>
> \documentclass{minimal}
> \makeatletter
>
> \newcommand\placeobjet [3][0pt]{\begingroup \leavevmode \sbox\@tempboxa {#3}%
> \dimen@ \dimexpr \dp\@tempboxa +\ht\@tempboxa
> \raise \dimexpr #2\dimen@ -\ht\@tempboxa
> + \ifdim \ht\@tempboxa <#2\dimen@ -\fi #1 \box\@tempboxa
> \endgroup
> }
> \makeatother
> \newcommand\carre{\fbox{\parbox{1cm}{\rule[1cm]{0cm}{0cm}}}}
>
> \begin{document}
> Some text before \_ \placeobjet{1}{\carre} \ \_ \placeobjet{.5}{\carre}\ \_
> \placeobjet{0}{\carre}
> \end{document}

you're right, it's much better ! tested and approved !!
Thank You :-D
M.Maunier

Martin Scharrer

unread,
Jul 1, 2011, 7:37:11 PM7/1/11
to
On Jul 1, 12:27 pm, Enrico Gregorio <Facile.da.trov...@in.rete.it>
wrote:

The `raise` option seems to easily added using:

\define@key{Gin}{raise}
{\Gin@esetsize
\@tempswatrue
\edef\@tempa{\toks@{\noexpand\raisebox{#1}{\the\toks@}}}%
\@tempa}

Where the code was adapted from the `angle` option. It's not yet fully
tested, but worked well in simple tests.
As shown it simply wraps a `\raisebox` around the image.

> A very common problem is aligning images in a tabular environment:
>
> \begin{tabular}{p{5cm}c}
> Descriptive text ... & \includegraphics[...]{image} \\
> ...
> \end{tabular}
>
> With a "raise" option or maybe a "topalign" in such a way that
> the image has the height of \strut, the alignment would be
> correct.

I also plan to allow for the use of `\height`, `\depth` etc.
and then this can be achieved using `raise=\dimexpr\ht\strutbox-\height
\relax` (i.e. lower by the full height and raise by the height of a
\strut).
However having (in addition) an `align` option which takes values like
`t`, `b` and `c` like e.g. a `minipage` which then executes something
like above would be even better. This value would be baseline related,
i.e. `t` leaves \ht\strutbox as height, `b` sets \dp\strutbox as
depth, `c` would center it to .5ex--.6ex or so to be centered with the
vertical center of text. Then there could be `T`, `B` and `C` for top
side (all depth, no height), bottom side (like it is now) and centered
at the geometric center, respectively.
(Would `l` and `r` for an `\llap` and `\rlap` like placement be
overkill?)

Best Regards,
Martin Scharrer

Martin Scharrer

unread,
Jul 4, 2011, 6:36:10 AM7/4/11
to

I now added this to my code repository. I also added the options `min
width`, `min height`, `max width` and `max height`.

Feel free to test it and provide feedback:
http://latex.scharrer-online.de/general/export/2461/adjustbox/dev/adjustbox.dtx
http://latex.scharrer-online.de/general/export/2461/adjustbox/dev/adjustbox.ins
The changes are however not fully tested yet.

> > A very common problem is aligning images in a tabular environment:
>
> > \begin{tabular}{p{5cm}c}
> > Descriptive text ... & \includegraphics[...]{image} \\
> > ...
> > \end{tabular}
>
> > With a "raise" option or maybe a "topalign" in such a way that
> > the image has the height of \strut, the alignment would be
> > correct.

This would be possible (see my previous answer), but should it be
really \ht\strutbox which is larger than
the uppercase letters in the neighbor cell or should it be the size of
an uppercase `X` or somehow between?
I wonder what would look better. Some thing for the depth. It's not
just in tabulars but sometimes also in text, however much more rarely.

See also http://tex.stackexchange.com/questions/22225/determine-height-and-depth-of-letters-relative-to-the-font-size
where I was asking the question how to
figure out the best height and depths.

Best,
Martin

Enrico Gregorio

unread,
Jul 4, 2011, 6:50:12 AM7/4/11
to
Martin Scharrer <martin....@gmail.com> wrote:

Probably the strut height is correct in the case of top aligned
images in tabulars; for bottom aligned ones no depth should be
necessary. Also center align should be provided, although it
can be obtained via \height (or \totalheight if the image is
rotated).

A finer control might indeed be necessary if the graphic is used
like a character, say a symbol built "externally".

Ciao
Enrico

GL

unread,
Jul 4, 2011, 3:40:36 PM7/4/11
to
Le 04/07/2011 12:36, Martin Scharrer a �crit :
>>> Descriptive text ...& \includegraphics[...]{image} \\

>>> ...
>>> \end{tabular}
>>
>>> With a "raise" option or maybe a "topalign" in such a way that
>>> the image has the height of \strut, the alignment would be
>>> correct.
>
> This would be possible (see my previous answer), but should it be
> really \ht\strutbox which is larger than
> the uppercase letters in the neighbor cell or should it be the size of
> an uppercase `X` or somehow between?
> I wonder what would look better. Some thing for the depth. It's not
> just in tabulars but sometimes also in text, however much more rarely.
>
> See also http://tex.stackexchange.com/questions/22225/determine-height-and-depth-of-letters-relative-to-the-font-size
> where I was asking the question how to
> figure out the best height and depths.

\fontcharht\font<number>
\fontchardp and \fontcharwd with e-TeX.


>
> Best,
> Martin

Enrico Gregorio

unread,
Jul 4, 2011, 4:54:45 PM7/4/11
to
GL <goua...@gmail.com> wrote:

> Le 04/07/2011 12:36, Martin Scharrer a ÔøΩcrit :


> >
> > See also
> > <http://tex.stackexchange.com/questions/22225/determine-height-and-depth-of-letters-relative-to-the-font-size>
> > where I was asking the question how to
> > figure out the best height and depths.
>
> \fontcharht\font<number>
> \fontchardp and \fontcharwd with e-TeX.

Wasn't it already in the answer, even with an explanation?

Ciao
Enrico

GL

unread,
Jul 4, 2011, 5:22:18 PM7/4/11
to
Le 04/07/2011 22:54, Enrico Gregorio a ÔøΩcrit :

Is this a new question ?

>
> Ciao
> Enrico

Donald Arseneau

unread,
Jul 4, 2011, 10:13:25 PM7/4/11
to
Enrico Gregorio <Facile.d...@in.rete.it> writes:

> Probably the strut height is correct in the case of top aligned
> images in tabulars;

That tends to bump into whatever is above. I usually use 1ex to
align the top to the top of lowercase letters. But hte *best* choice
really depends on what sort of text is in the other columns.


Donald Arseneau as...@triumf.ca

Enrico Gregorio

unread,
Jul 5, 2011, 4:45:37 AM7/5/11
to
Donald Arseneau <as...@triumf.ca> wrote:

You're right; but I always use booktabs for tables, which tends
to avoid that problem.

Ciao
Enrico

0 new messages