The following LaTeX code illustrates my question. Is it possible to get what I want without doing the negative \hskip
, as I want a simple generic solution which will rotate the box to any angle (center origin) but leave it 'in-place'?
An ideal solution would allow me to do this:
{a}\somespecialrotate[origin=c]{\anyangle}{b}
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\newsavebox\bxa
\newsavebox\bxb
\huge
\savebox\bxa{\color{red}\rule{1cm}{1cm}}
\savebox\bxb{\color{black}\rule{1cm}{1cm}}
\usebox\bxa\rotatebox[origin=c]{45}{\usebox\bxb}This is what I do not want\par
\usebox\bxa\hskip-0.25cm\rotatebox[origin=c]{45}{\usebox\bxb}This is what I DO want
\end{document}
Best Answer
This can be easily done with
adjustbox
v0.8 from2011/11/14
. It provides the original width as\Width
which can be used to center the rotated content around it (with the rest overlapping on the left and right) or to calculate the amount which the rotated content should overlap to the left, which is the\hskip
you are talking about. The current width is always\width
, solap=-.5\width+.5\Width
will make the rotated content lap over to the left. See theadjustbox
manual for details.With an older version of
adjustbox
you can substitute\Width
with\wd\bxb
if you box the content by yourself. If you don't want to useadjustbox
, but rather do it yourself, you need to box both the original content (\bxb
) and the rotated one (say\bxc
) and then use\mbox{\hskip\dimexpr -.5\wd\bxb+.5\wd\bxc\relax\usebox\bxc}
to typeset the box.Here a
graphicx
-only solution which only uses one temporary box register:Lower part:
And here for angles from 0,5,...,180: