General ⇒ Vertical alignment of vertical text in tabular & array
Vertical alignment of vertical text in tabular & array
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
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Vertical alignment of vertical text in tabular & array
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
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
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}}