GeneralVertical alignment in a table

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Vera
Posts: 2
Joined: Tue Jul 22, 2008 1:40 pm

Vertical alignment in a table

Post by Vera »

Hello!

I am trying to make a table which has rotated text in headings. However, the text is quite long and the resulting table is therefore vertically stretched which is not very nice to look at.

I would be very grateful for any kind of hint or help on how to “vertically wrap” the rotated text in the heading.

Example of the code:

Code: Select all

\begin{tabular}{b{1cm} c b{1cm} b{1cm} b{1cm} b{1cm} b{1cm} b{1cm} c}
 \toprule
   & & \multicolumn{6}{c}{Road Type} & \\
\cmidrule{3-8}
 & & \begin{sideways}Pedestrianised street\end{sideways}& \begin{sideways}B road\end{sideways} & \begin{sideways}Minor road\end{sideways} & \begin{sideways}A road single carriageway\end{sideways} & \begin{sideways}Dual carriageway\end{sideways} & \begin{sideways}Local street\end{sideways} & \begin{sideways}Total\end{sideways}\\
 \midrule
Women & Count & 1 & 2 & 3 & 1 & 4 & 2 & 13\\
 & Expected & 0.7 & 3.9 & 3.3 & 0.7 & 2.6 & 2.0 & 13.0 \\
\midrule
Men & Count & 0 & 4 & 2 & 0 & 0 & 1 & 7\\
& Expected  & 0.4 & 2.1 & 1.8 & 0.4 & 1.4 & 1.1 & 7.0 \\
\midrule
Total & Count & 1 & 6 & 5 & 1 & 4 & 3 & 20\\
 & Expected  & 1.0 & 6.0 & 5.0 & 1.0 & 4.0 & 3.0 & 20.0 \\
 \bottomrule
\end{tabular}
and the result (attached)

Thanks for your help!!

Regards,
Vera
Attachments
tableExample.png
tableExample.png (12.59 KiB) Viewed 4350 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Vertical alignment in a table

Post by localghost »

You can keep the sideways environment from rotating. I use the \rotatebox command from the graphicx package. In both cases you will need a parbox of a certain width to get the text wrapped.

Code: Select all

\begin{tabular}{b{1cm} c b{1cm} b{1cm} b{1cm} b{1cm} b{1cm} b{1cm} c}\toprule
  & & \multicolumn{6}{c}{Road Type} & \\ \cmidrule{3-8}
  & & \rotatebox{90}{\parbox{3cm}{Pedestrianised street}}& \rotatebox{90}{\parbox{3cm}{B road}} & \rotatebox{90}{\parbox{3cm}{Minor road}} & \rotatebox{90}{\parbox{3cm}{A road single carriageway}} & \rotatebox{90}{\parbox{3cm}{Dual carriageway}} & \rotatebox{90}{\parbox{3cm}{Local street}} & \rotatebox{90}{\parbox{3cm}{Total}} \\ \midrule
  Women & Count & 1 & 2 & 3 & 1 & 4 & 2 & 13 \\
  & Expected & 0.7 & 3.9 & 3.3 & 0.7 & 2.6 & 2.0 & 13.0 \\ \midrule
  Men & Count & 0 & 4 & 2 & 0 & 0 & 1 & 7 \\
  & Expected  & 0.4 & 2.1 & 1.8 & 0.4 & 1.4 & 1.1 & 7.0 \\ \midrule
  Total & Count & 1 & 6 & 5 & 1 & 4 & 3 & 20 \\
  & Expected  & 1.0 & 6.0 & 5.0 & 1.0 & 4.0 & 3.0 & 20.0 \\ \bottomrule
\end{tabular}
You can adapt the width of the parbox from 3cm to any width that fits best your ideas. You should choose this width not to small because otherwise you could run into trouble with difficulties in hyphenation.


Best regards and welcome to the board
Thorsten¹
Vera
Posts: 2
Joined: Tue Jul 22, 2008 1:40 pm

Re: Vertical alignment in a table

Post by Vera »

Thanks a lot Thorsten!!

t works exactly the way I wanted!

Cheers,
Vera
Post Reply