[Tex/LaTex] Landscape table on portrait page

formattinglandscapetablestabularx

I have a portrait page with a section heading below which I would like to place a table in landscape (as in this orientation it should take up most of the rest of the page).

I can get the whole page in landscape and do it that way, however, if I do this, the section heading does not appear on the same page.

My current attempt (which sticks the table on a new, landscape, page looks like this:

\documentclass[a4paper]{report}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\usepackage{booktabs}
\usepackage{float}
\usepackage{tabularx}
\usepackage{pdflscape}
\begin{document}
    \section{Appendix B - Risk Assessment}
    \begin{landscape}
    \begin{table}[H]
    \centering\ra{1.3}
    \caption{Table to show risks, hazards and mitigation techniques for this experiment}
    \label{tbl:RiskMatrix}
    \begin{tabularx}{\linewidth}{X X c X c c}
    \toprule
    Description of Hazard & Consequences & Risk Before & Mitigations Required & Risk After & ALARP? (Yes/No) \\ [0.5ex]
    \midrule
    Electrocution & Serious injury or death & 0.5 & Ensure hands are dry when plugging in. Do not tamper with any electrical components & 0.1 & Yes \\
    Burns from hot components & Non-serious burns & 0.7 & Wear thermally insulated gloves when operating equipment & 0.2 & Yes \\
    Burns from steam & Very serious burns, potential loss of sight & 0.6 & Wear safety goggles and a lab coat to protect from steam egress & 0.2 & Yes \\
    Loss of apparatus integrity & Injuries from shrapnel, serious burns, potentially fatal & 0.3 & Check equipment for signs of buckling before use. Ensure that it remains within safe operating pressures. Ensure ballistic screen is in place around equipment. & 0.2 & Yes \\\bottomrule
    \end{tabularx}
    \end{table}
    \end{landscape}

\end{document}

If anyone would have any suggestions on how I could achieve this or, if this is not possible, what the best alternative solution might be.

Best Answer

The solution is twofold, thanks to @David Carlilse for the idea to use the rotating package.

Firstly, the tabularx inside the table needs to be placed inside a sideways block.

Secondly, tabularx needs to be told the \textheight instead of the \textwidth so that it knows the total width of the table for its X column calculations. However, this results in the column overlapping with the page number so we subtract 3cm for margin.

The section now reads like this:

\section{Appendix B - Risk Assessment}
\begin{table}[H]
\centering\ra{1.3}
\caption{Table to show risks, hazards and mitigation techniques for this experiment}
\label{tbl:RiskMatrix}
\begin{sideways}
\begin{tabularx}{\textheight - 3cm}{X X c X c c}
\toprule
Description of Hazard & Consequences & Risk Before & Mitigations Required & Risk After & ALARP? (Yes/No) \\ [0.5ex]
\midrule
Electrocution & Serious injury or death & 0.5 & Ensure hands are dry when plugging in. Do not tamper with any electrical components & 0.1 & Yes \\
Burns from hot components & Non-serious burns & 0.7 & Wear thermally insulated gloves when operating equipment & 0.2 & Yes \\
Burns from steam & Very serious burns, potential loss of sight & 0.6 & Wear safety goggles and a lab coat to protect from steam egress & 0.2 & Yes \\
Loss of apparatus integrity & Injuries from shrapnel, serious burns, potentially fatal & 0.3 & Check equipment for signs of buckling before use. Ensure that it remains within safe operating pressures. Ensure ballistic screen is in place around equipment. & 0.2 & Yes \\\bottomrule
\end{tabularx}
\end{sideways}
\end{table}
Related Question