3

I'm trying to create a sideways column type based on column type c. At the moment it looks like this: graphical example

I want to put the expression "long word" in the vertical middle of the column and remove the error droping my text text text ... field. I searched and tried but I didn't succed.

This is my minmal working example:

\documentclass[11pt, a4paper]{article}
\usepackage{lmodern}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{rotating}

\newcolumntype{R}{>{\begin{sideways}}c<{\end{sideways}}}
\begin{document}
\begin{tabularx}{\textwidth}{|R|X|}
\hline
\rotatebox{270}{1234} & text\\
\hline
long word & text text text text text text text text text text text text text     text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text \\
\hline
\end{tabularx}
\end{document}
1
5

There are two things you can do here to get the effect you want.

The first is to redefine \tabularxcolumn. When you call the X column type, tabularx converts the column into a type p{...} column. You can change this behavior.

\renewcommand{\tabularxcolumn}[1]{m{#1}}

to get a parbox that will be centered. Please see the documentation for tabularx for further details.

The second is not to use the rotating package, but to use graphicx package's potential to define the point about which the rotation occurs. The unfortunate drawback of this is that graphicx does not provide the sideways environment you use. So, to this end, you'll define a new sideways environment.

Here's a MWE which illustrates this:

\documentclass{article}
%%--------------------
\usepackage{graphicx}
\makeatletter
\newsavebox{\ingo@sideways@box}
\newenvironment{ingosideways}
  {\begin{lrbox}{\ingo@sideways@box}}
  {\end{lrbox}\rotatebox[origin=c]{90}{\usebox{\ingo@sideways@box}}}
\makeatother
%%--------------------
%%\usepackage{rotating}
\usepackage{array}
\usepackage{tabularx}
\newcolumntype{R}{>{\begin{ingosideways}}c<{\end{ingosideways}}}
%%--------------------
\usepackage{lipsum}
\pagestyle{empty}
\begin{document}

{\renewcommand{\tabularxcolumn}[1]{m{#1}}%
\begin{tabularx}{\textwidth}{| R | X |}\hline
\rotatebox[origin=c]{-90}{1234}             & text                         \\\hline
{This is a very long entry for this column} & {\let\par\relax\lipsum[1-2]} \\\hline
\end{tabularx}}

\end{document}

enter image description here

I've enclosed the redefining of \tabularxcolumn within a group so that the redefinition does not adversely effect the use of tabularx environments later in your document.

Also, the use of lipsum here creates some erroneous white space making the centering look unbalanced: to correct this I've also temporarily redefined \par within the scope of where I'm calling lipsum. In your own document, you should not need this correction!

1
  • The second solution just works fine for me. Thank you a lot! And as you predicted I didn't have to use lipsum
    – ingo
    Jul 21 '13 at 22:15
2

If tabularx is not a must, I'd suggest the package cals:

enter image description here

\documentclass{article}
\usepackage{cals}
\usepackage{rotating}
\usepackage{lipsum}
\begin{document}
\begin{calstable}
\colwidths{{1.1cm}{12cm}}
\brow
\alignC\cell{1234}
\alignL\cell{text}
\erow
\brow
\alignC\cell{\vfil\begin{sideways}long word\end{sideways}}
\alignL\cell{\lipsum[1-2]}
\erow
\end{calstable}
\end{document}
1
  • Thank you for your answer, but actually tabularx is a must.
    – ingo
    Jul 21 '13 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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