Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

For example:

\documentclass{report}
\usepackage{rotating}

\newenvironment{stext}
{\begin{sideways} \bfseries \raggedleft }
{\end{sideways}}

\begin{document}

\begin{stext}
This is an example environment.
\end{stext}

\end{document}

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:

\documentclass{article}
\usepackage{rotating}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
\begin{tabular}{$l^c^r}
\rowstyle{\rotatebox{-90}}% <- I know, the usage is wrong. 
abc & abc & abc\\
b & b & b \\
c & c & c \\
\end{tabular}
\end{document}

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
4  
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

1 Answer 1

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

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{array}% http://ctan.org/pkg/array
\newsavebox\TBox
\newif\ifrotate\rotatefalse
\newcolumntype{C}{%
  >{\begin{lrbox}{\TBox}} 
  c 
  <{\end{lrbox}\ifrotate\rotatebox{90}{\usebox\TBox}\else\usebox\TBox\fi}}
\begin{document}
\begin{tabular}{*3C}
  \global\rotatetrue abc & abc & abc \\ \global\rotatefalse
  b & b & b \\
  c & c & c \\
\end{tabular}
\end{document}

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

 
discard

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.