Hi all
I'd like to have vertical text down the side of a figure vertically centred. Here is a MWE of the problem:
\documentclass[a4paper,11pt]{report}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\begin{tabular}{cc}
\rotatebox{90}{This should be centred vertically} &
\framebox[0.8\linewidth]{\rule{1pt}{\linewidth}}
\end{tabular}
\end{figure}
\end{document}
I've tried the obvious use of [c] in the tabular environment and enclosing the text in a parbox with [c] also, but these don't work as desired. Currently I'm using \hspace, and setting the amount manually by trial and error, which isn't ideal.
Any ideas of how to do this properly would be much appreciated.
Thanks,
Olly
General ⇒ Vertical alignment of vertical text in tabular & array
NEW: TikZ book now 40% off at Amazon.com for a short time.

Vertical alignment of vertical text in tabular & array
Hello,
here is a solution. It is probably suboptimal, but at least working:
here is a solution. It is probably suboptimal, but at least working:
Code: Select all
\documentclass[a4paper,11pt]{report}
\usepackage{graphicx}
\usepackage{array}
\newsavebox\DescBox
\begin{document}
\begin{figure}
\sbox\DescBox{This should be centred vertically}
\begin{tabular}{m{\dimexpr\ht\DescBox+\dp\DescBox}m{0.8\linewidth}}
\rotatebox[origin=c]{90}{\usebox\DescBox} &
\framebox[0.8\linewidth]{\rule{1pt}{\linewidth}}
\end{tabular}
\end{figure}
\end{document}
Vertical alignment of vertical text in tabular & array
Many thanks for your suggestion, Phi.
In fact, I can make your code much simpler and have it still work:
However, it breaks as soon as I define any of the columns using something other than 'm'. This is a pain if I want the width of the other columns to be variable (which I do), for example using 'c'.
Can anyone see a way round this?
Many thanks,
Olly
In fact, I can make your code much simpler and have it still work:
Code: Select all
\documentclass[a4paper,11pt]{report}
\usepackage{graphicx}
\def\uptext#1{\rotatebox[origin=c]{90}{#1}}
\begin{document}
\begin{figure}
\begin{tabular}{m{11pt}m{0.8\linewidth}}
\uptext{This should be centred vertically} &
\framebox[0.8\linewidth]{\rule{1pt}{0.7\linewidth}}\\
\uptext{So should this} &
\framebox[0.8\linewidth]{\rule{1pt}{0.7\linewidth}}
\end{tabular}
\end{figure}
\end{document}
Can anyone see a way round this?
Many thanks,
Olly
Vertical alignment of vertical text in tabular & array
It's much simpler than I thought:
I set \fboxsep to zero, otherwise there is a small offset of length \fboxsep, which can be easily corrected in the \raisebox command, if necessary.
EDIT: This version of \vertcenter also works if the box has a nonzero depth (like \framebox):
Code: Select all
\documentclass[a4paper,11pt]{report}
\usepackage{graphicx}
\newcommand*\vertcenter[1]{\raisebox{-0.5\height}{#1}}
\newcommand*\uptext[1]{\vertcenter{\rotatebox{90}{#1}}}
\setlength\fboxsep{0.0pt}
\begin{document}
\begin{figure}
\begin{tabular}{cc}
\hline
\uptext{This should be centred vertically} &
\vertcenter{\framebox[0.8\linewidth]{\rule{1pt}{0.42\linewidth}}} \\
\hline
\uptext{So should this} &
\vertcenter{\framebox[0.8\linewidth]{\rule{1pt}{0.12\linewidth}}} \\
\hline
\end{tabular}
\end{figure}
\end{document}
EDIT: This version of \vertcenter also works if the box has a nonzero depth (like \framebox):
Code: Select all
\newcommand*\vertcenter[1]{\raisebox{\dimexpr(\depth-\height)/2}{#1}}
Re: Vertical alignment of vertical text in tabular & array
Great. Thanks, Phi.