Horizontal equivalent to \raisebox?
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.
If you are in a vertical context you can use the primitive moveright
\moveright 2in \hbox{.....}
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 equivalent for \adjustbox{<key=value>}{<content>}
called lap
in this case.
Excerpt 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
\adjustbox{lap={\width}{1em}}{Some text}
The \adjustbox
version can also be combined with other keys like raise
, which is the equivalent of \raisebox
.