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

\phantom command

480 views
Skip to first unread message

minimus

unread,
Dec 24, 2011, 10:31:11 AM12/24/11
to
Hello,

\phantom{} command is a very useful command which allows for extra space
where the amount of the space is determined exactly with what is indicated
in the curly braces. For example, \phantom{1.} will add white space exactly
by the amount that "1." occupies.

My question is the following. Is there a \phantom like command that will not
add but delete white space by exactly the amount to be specified? For
example, I want to delete a white space amount of "1.". Is there a command I
can achieve this?

Enrico Gregorio

unread,
Dec 24, 2011, 11:19:58 AM12/24/11
to
If you need only the horizontal space,

\newcommand{\neghphantom}[1]{%
\begingroup\sbox0{#1}\hspace*{-\wd0}\endgroup}

For use in math formulas it's more complicated.

Ciao
Enrico

Enrico Gregorio

unread,
Dec 24, 2011, 11:32:54 AM12/24/11
to
\makeatletter
\newcommand{\negphantom}{\v@true\h@true\negph@nt}
\newcommand{\neghphantom}{\v@false\h@true\negph@nt}
\newcommand{\negph@nt}{\ifmmode\expandafter\mathpalette
\expandafter\mathnegph@nt\else\expandafter\makenegph@nt\fi}
\newcommand{\makenegph@nt}[1]{%
\setbox\z@\hbox{\color@begingroup#1\color@endgroup}\finnegph@nt}
\newcommand{\finnegph@nt}{%
\setbox\tw@\null
\ifv@ \ht\tw@\ht\z@\dp\tw@\dp\z@\fi \ifh@\wd\tw@-\wd\z@\fi\box\tw@}
\newcommand{\mathnegph@nt}[2]{%
\setbox\z@\hbox{$\m@th #1{#2}$}\finnegph@nt}
\makeatother

Now \neghphantom and \negphantom do as \hphantom and \phantom
(the difference is that also the height and depth of the material
are taken into account).

There's no \negvphantom, since it makes little sense.

Ciao
Enrico

minimus

unread,
Dec 24, 2011, 12:06:47 PM12/24/11
to
>"Enrico Gregorio" wrote in message
>news:241220111732540000%Facile.d...@in.rete.it...
Thank you very much. I thought there would be a direct pre written command
like phantom. Thanks so much for writing this whole code!

Peter Flynn

unread,
Dec 24, 2011, 6:05:15 PM12/24/11
to
\usepackage{calc}
...
stuff\hspace{-\widthof{1.}}stuff

[untested]

///Peter

minimus

unread,
Dec 24, 2011, 6:39:45 PM12/24/11
to
Thank you very much. I will test it.

Heiko Oberdiek

unread,
Dec 24, 2011, 11:50:47 PM12/24/11
to
Peter Flynn <peter...@m.silmaril.ie> wrote:

> \usepackage{calc}
> ...
> stuff\hspace{-\widthof{1.}}stuff
>
> [untested]

Unhappily \hspace doesn't use \setlength and therefore doesn't
support package calc. A additional \setlength is needed, e.g.:

\newlength\mytemplength % in preamble
\usepackage{calc}
...
stuff\setlength{\mytemplength}{-\widthof{1.}}\hspace{\mytemplength}stuff

But then this can be achieved without package calc:

\newlength\mytemplength % in preamble
...
stuff\settowidth{\mytemplength}{1.}\hspace{-\mytemplength}stuff

--
Heiko Oberdiek

Bruno Le Floch

unread,
Dec 25, 2011, 10:38:36 AM12/25/11
to
If your goal is to overlap different texts (i.e., if you want to do
"1.\negphantom{1.}"), a better way is to use "\rlap{1.}".

Of course, this does not cover the general case.

Regards,
Bruno

Martin Scharrer

unread,
Dec 25, 2011, 11:55:55 AM12/25/11
to
On 25/12/11 16:38, Bruno Le Floch wrote:
> If your goal is to overlap different texts (i.e., if you want to do
> "1.\negphantom{1.}"), a better way is to use "\rlap{1.}".
Indeed. Also, the 'lap' key of \adjustbox or the \lapbox macro from the
'adjustbox' package can be used here and allow for a very flexible
overlapping. When loaded with the 'calc' option the \widthof macro can
be used in the length argument.


Regards,
Martin Scharrer

Enrico Gregorio

unread,
Dec 25, 2011, 1:48:58 PM12/25/11
to
Or else \leavevmode\llap{1.} instead of

\negphantom{1.}1.

Ciao
Enrico
0 new messages