Shear transform a "box"

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).

\documentclass{article}
\newsavebox{\foobox}
\newcommand{\slantbox}[2][.5]
  {%
    \mbox
      {%
        \sbox{\foobox}{#2}%
        \hskip\wd\foobox
        \pdfsave
        \pdfsetmatrix{1 0 #1 1}%
        \llap{\usebox{\foobox}}%
        \pdfrestore
      }%
  }
\begin{document}
\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!}

\end{document}

enter image description here


Aha, TikZability opportunity!

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

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

enter image description here


enter image description here

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

\documentclass{article}

\begin{document}


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


\end{document}

Tags:

Graphics