TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the graphicx package, I can make any arbitrary box rotated using the \rotatebox{...}{...} command. Is there a comparable command in any package that lets me shear a box, i.e., producing a kind of general slanting?

share|improve this question
up vote 20 down vote accepted

With a slightly more recent pdfTeX than in David's answer, you can more directly do affine transforms using \pdfsetmatrix. I don't claim to know anything about this, but here is roughly what graphicx does under the hood in \rotatebox (with a different matrix, of course).

        \pdfsetmatrix{1 0 #1 1}%
\slantbox{Hello, world!}

\slantbox[-2]{Hello, world!}
\slantbox[-1]{Hello, world!}
\slantbox[-.8]{Hello, world!}
\slantbox[-.6]{Hello, world!}
\slantbox[-.4]{Hello, world!}
\slantbox[-.2]{Hello, world!}

\slantbox[.2]{Hello, world!}
\slantbox[.4]{Hello, world!}
\slantbox[.6]{Hello, world!}
\slantbox[.8]{Hello, world!}
\slantbox[1]{Hello, world!}
\slantbox[2]{Hello, world!}


enter image description here

share|improve this answer
Do we want this for LaTeX3? It should be pretty easy to code as I've already got the basics sorted. – Joseph Wright Jul 13 '12 at 17:10
I'm still a bit confused. How do those four numbers correspond to a transformation matrix? Is it just a list of elements of the matrix left to right, row by row? Would \slantbox[0]{} amount to the identity transformation? – Seamus Jul 13 '12 at 17:15
@Seamus: yes, the four numbers 1, 0, #1, and 1 are the entries in the 2×2 matrix defining the linear transformation. David's answer with \pdfliteral allows arbitrary affine transformation (so the 4 coefficients for the linear part, and 2 coefficients for the offset, I think). – Bruno Le Floch Jul 13 '12 at 17:47
@Joseph: I was thinking of it (I didn't upvote your comment, so at least one other person would like that), but I'm not sure whether we should give \box_linear_transform:Nnnnn for arbitrary parameters, or \box_vertical_shear:Nn and \box_horizontal_shear:Nn, or... – Bruno Le Floch Jul 13 '12 at 17:59
@BrunoLeFloch If we provide a mechanism here, we should have the 'general case' shear, something like \box_shear:Nnn or even as you say a totally-general transformation (\box_affine:Nnnnn?). One for LaTeX-L – Joseph Wright Jul 13 '12 at 18:40

Aha, TikZability opportunity!

\begin{scope}[cm={1,0,1,1,(0,0)}] % Sets the coordinate trafo matrix entries.
\node[transform shape] at (0,0) {ABC};
\node[transform shape] at (3,0) {Hello};
\node[transform shape] at (2,2) {World};
\node[transform shape] at (1,2) {FOObar?};

You can put into nodes instead of boxes (with less risk :P).

enter image description here

share|improve this answer

enter image description here

You can mess with the coordinate matrix, but at your own risk...



ABC\pdfliteral{ q 2 0.1 0.6 .4 0 0 cm}\rlap{XYZ}\pdfliteral{ Q}

share|improve this answer
q (\pdfsave) and Q (\pdfrestore) should be used at the same place. Otherwise the coordinate system of TeX and its output device get indeed messed up. – Heiko Oberdiek Jun 19 '14 at 15:36
@HeikoOberdiek ah yes I wrote some driver graphics back end files once, clearly I forgot everything, I'll add an rlap.... – David Carlisle Jun 19 '14 at 15:49

Shear transforms can be decomposed into scalings and rotations.

% \hshearbox{vertical_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial vertical downscale is often necessary for a 3d projection
% \vshearbox{horizontal_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial horizontal downscale is often necessary for a 3d projection
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.