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

I am trying to create a new environment that works similar to the {\bfseries } command.

For example:


{\begin{sideways} \bfseries \raggedleft }


This is an example environment.


In the above example, I want to redefine the stext environment so that it works as follows:

{\stext This is an example environment.}

Here is the use case for this new environment:


\rowstyle{\rotatebox{-90}}% <- I know, the usage is wrong. 
abc & abc & abc\\
b & b & b \\
c & c & c \\

The aim here is to get the text in the first row sideways so that they don't occupy as much width. For the \rowstyle command to work properly, I need an environment which can be invoked like so:

{\rotatetext Rotated text}
share|improve this question
Do you still want the contents to be rotated? – Werner Feb 14 '12 at 16:35
It's quite hard to understand why you'd want this. Can you give more motivation? – egreg Feb 14 '12 at 16:43
You could create a macro that wraps the text in the environment, e.g. \stext{Your text}; this is ALMOST like what you stated that you wanted... – Scribblemacher Feb 14 '12 at 18:10
@Werner, yes. It should do the same thing as the stext environment in the MWE. – Adi Feb 14 '12 at 18:23
@egreg For instance, I want the text in a row of a large table to be sideways so that it doesn't occupy as much width. I am using the solution from here to apply a row style. However, the \rowstyle command here takes formatting commands in the form {\formatting Text goes here}. I cannot use a begin{environment}-\end{environment} construct here. – Adi Feb 14 '12 at 18:31
up vote 4 down vote accepted

Here is an option using a slightly modified version of Herbert's answer to An improved \rowstyle that takes the cell contents as an argument:

enter image description here

\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{array}% http://ctan.org/pkg/array
  \global\rotatetrue abc & abc & abc \\ \global\rotatefalse
  b & b & b \\
  c & c & c \\

The idea behind this solution is to box the contents in \TBox and conditionally rotate it or not, based on \ifrotate - a boolean value set to true (\rotatetrue) or false (\rotatefalse).

It's usage should be clear from the example - place \global\rotatetrue in the first entry you want to rotate in that row, and \global\rotatefalse after the last entry. For convenience you could also define these as "switches" using

\newcommand{\rotateon}{\global\rotatetrue}% rotate switch ON
\newcommand{\rotateoff}{\global\rotatefalse}% rotate switch OFF

If you want different alignment for the respective columns, you can define an L and R column (say), similar to my C.

graphicx provides the \rotatebox{<angle>}{<stuff>} command to rotate <stuff> through an angle of <angle> degrees.

share|improve this answer
Quick follow-up question: How can I modify the code so as to allow text wrapping in the rotated text? I tried changing the column alignment from c to p, but that didn't work. – Adi Feb 15 '12 at 13:00
@Adi: You can place the contents in a \parbox of a specific width. For example, use \parbox{2cm}{abc def ghi jkl} in the above example for one of the header entries. – Werner Feb 16 '12 at 7:33

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.