6

Similar to this problem, I want to define \shearbox with \rotatebox and \scalebox using singular value decomposition: singular value decomposition

The latex code is as follows:

\documentclass[12pt]{article}
\usepackage[nomessages]{fp}
\usepackage{graphicx}
\newcommand\xshearbox[2]{%
  \FPeval{\sheark}{(root(2,(#1)*(#1)+4)+#1)/2}\FPeval{\shearl}{1/\sheark}%
  \FPeval{\sheara}{arctan(-\sheark)*180/pi}\FPeval{\shearb}{90+\sheara}%
  \rotatebox{\shearb}{\scalebox{\sheark}[\shearl]{\rotatebox{\sheara}{#2}}}%
}
\begin{document}
pefgh\xshearbox{0.2}{pefgh}pefgh\xshearbox{0.4}{pefgh}pefgh\xshearbox{0.6}{pefgh}%
pefgh\xshearbox{0.8}{pefgh}pefgh\xshearbox{1}{pefgh}pefgh
\end{document}

enter image description here

But there are still two problems here:

  1. There are extra spaces between shearing text and normal text;
  2. The baselines of shearing text is a little higher than normal text.
Z.H.
  • 3,346
  • 21
  • 39

1 Answers1

4

The problems are caused by the height and depth of the original box. You can ignore these by smashing the contents \smash{#2}:

Sample output

\documentclass[12pt]{article}
\usepackage[nomessages]{fp}
\usepackage{graphicx}
\newcommand\xshearbox[2]{%
  \FPeval{\sheark}{(root(2,(#1)*(#1)+4)+#1)/2}\FPeval{\shearl}{1/\sheark}%
  \FPeval{\sheara}{arctan(-\sheark)*180/pi}\FPeval{\shearb}{90+\sheara}%
  \rotatebox{\shearb}{\scalebox{\sheark}[\shearl]{{\rotatebox{\sheara}{\smash{#2}}}}}%
}
\begin{document}
pefgh\xshearbox{0.2}{pefgh}pefgh\xshearbox{0.4}{pefgh}pefgh\xshearbox{0.6}{pefgh}%
pefgh\xshearbox{0.8}{pefgh}pefgh\xshearbox{1}{pefgh}pefgh

\end{document}
Andrew Swann
  • 95,762
  • The correct height and depth can be taken into account with \vphantom{#2}. Probably wrapping the whole construction like with \mbox{\vphantom{#2}\rotatebox{\shearb}{...}} – egreg Jun 26 '14 at 13:35