# Horizontal equivalent to \raisebox?

Is there a horizontal equivalent to \raisebox? I'd like to shift some content horizontally without altering the layout of surrounding content.

Edit:

I feel bad because my question wasn't precise enough. David Carlisle's answer is the best if you're looking for the true horizontal analogue to \raisebox (moves content horizontally instead of vertically, operates in vertical mode instead of LR mode). However, what I really want is something that works in LR mode.

-
@RichardHansen: You could do \hspace*{<length>}\mbox{<content>}\hspace{-<length>} –  Martin Scharrer Apr 7 '12 at 20:28
BTW, LaTeX is the default here, so you don't have to mentioned it. For other things like plainTeX there is a special tag. –  Martin Scharrer Apr 7 '12 at 20:30
@MartinScharrer: Feel free to add that as an answer. :) How does it compare to Werner's answer? –  Richard Hansen Apr 7 '12 at 21:08

Here is a macro \shifttext{<len>}{<stuff>} that shifts <stuff> by <len> (negative for left, positive for right):

\documentclass{article}
\makeatletter
\newcommand*{\shifttext}[2]{%
\settowidth{\@tempdima}{#2}%
\makebox[\@tempdima]{\hspace*{#1}#2}%
}
\makeatother
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
Here is some text. \par
Here is \shifttext{20pt}{some} text. \par
Here is \shifttext{-20pt}{some} text. \par
\end{document}


Note that, in its current form, the shifted content shouldn't contain any \label or counter content. However, that can be fixed if needed, by boxing the content first.

-
I accepted this answer because it seems like the simplest, it works in LR mode, and it contains an illustration. But the other answers are excellent too. Too bad I can't accept more than one answer. –  Richard Hansen Apr 7 '12 at 22:37

If you are in a vertical context you can use the primitive moveright

\moveright  2in  \hbox{.....}

-
Never heard about \moveright. You never stop learning! –  Martin Scharrer Apr 7 '12 at 20:26
@MartinScharrer: It's very rarely used. LaTeX2e uses it in one place (outputting the page headers); L3 nowhere yet. Even ConTeXt doesn't use it. –  Martin Schröder Apr 7 '12 at 21:00
Is there something like this that works in horizontal mode and is already defined in TeX/LaTeX? Or do I have to make my own macro/use a 3rd party package to do it? –  Richard Hansen Apr 7 '12 at 21:05
@RichardHansen in horizontal mode you can just go \hspace{1in}\mbox{hello}\hspace{-1in} \moveright is the natural analogue of \raisebox which is defined in terns of \raise which works exactly the same way (with the same syntax) as \moveright but in hmode rather than vmode. –  David Carlisle Apr 7 '12 at 21:18
@DavidCarlisle Is using \hspace is definitely preferred over using \hspace* for this purpose? –  Lover of Structure Oct 21 '12 at 2:12

My adjustbox package provides \lapbox[<width>]{<amount>}{<content>} which is a generalization of \rlap{<content>} and \llap{<content>}, but can also be used as horizontal equivalent of \raisebox. The <amount> can be positive or negative and will move the content to the right or left, respectively. The original width can be accessed as \width. The official width can be set manually, otherwise it is reduced by the lap amount.

As always there is also a key aquivilent for \adjustbox{<key=value>}{<content>} called lap in this case.

### Except from the adjustbox manual about \lapbox:

This macro is a generalisation of the LaTeX core macros \rlap{<content>} and \llap{<content>} which lap the text to the right or left without taking any official space. The \lapbox macro can be used to only partially lap the content to the right (positive amount) or left (negative amount). As with all macros of this package the original width can be references using \width. The resulting official width of the box is normally the original width minus the absolute lap amount. However, it can also be set explicitly using the option argument. It is also possible to use lap amount which absolute values are larger than the original width. In this case the resulting official width will be zero by default and the content will padded with the required white space. Note that the lap amount always states the distance between the right side of the official box and the right side of the actual content for positive amounts or the distance between the left side of the official box and the left side of the actual content for negative values.

See the manual for graphical examples.

### Example:

If you want to move some content 1em to the right without changing its official width use:

\usepackage{adjustbox}
% ...
\lapbox[\width]{1em}{Some text}
% or


The \adjustbox version can also be combined with other keys, like raise which is the equivalent of \raisebox.

-

I figured out just another simple alternative, that consists of two boxes, one aligned left and the other right.

\newcommand{\shiftleft}[2]{\makebox[0pt][r]{\makebox[#1][l]{#2}}}
\newcommand{\shiftright}[2]{\makebox[#1][r]{\makebox[0pt][l]{#2}}}


example:

\shiftright{20pt}{text}


Shifts 'text' to the right.

-