0

I have the following table and it doesn't fit in the page. I already tried looking for the threads which were relevant, tried all suggestions but no success.

Here is my code:

\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{sidewaystable}[]
\centering
\begin{tabular}{|M{1.25cm}|M{1.85cm}|M{3cm}|M{4.0cm}|M{2.5cm}|M{3cm}|M{1.8cm}|M{2cm}|M{3cm}|}
\hline
\textbf{Hazard ID} & {\textbf{Hazard}}   & {\textbf{Incident/Event}}    & {\textbf{Potential Consequences/Impacts}}                                             & {\textbf{Potential Causes}}                   & {\textbf{Mitigation and Prevention Measures}} & \textbf{Potential Offsite Impact?} & \textbf{Qualitative Risk}      & {\textbf{Comments}}                                                                         \\ \hline
1.1                & Failure to generate safe path          & USV does not avoid the obstacle                 & USV attempts to navigate in the environment, results in collusion with the obstacle                      & Failed obstacle avoidance module               & Statedog, N-Version Programming                                  & Yes                                & \cellcolor[HTML]{FE0000}High   & Problem can be either the VFH* component, or the estimation of the obstacle position by the COLREGs component.                      \\ \hline
1.2                & Failure to provide desired manoeuvre   & USV does not provide the necessary acceleration & USV attempts to avoid the obstacle, cannot manoeuvre as expected, results in collusion with the obstacle & Failed sensor; Corrupted sensor data           & Redundant \& Diverse Sensors                                     & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the sensors and/or controllers.                                                                    \\ \hline
2.1                & Failure to detect the inbound obstacle & USV does not map the obstacle                   & USV sails as there was nothing on its way, results in collusion with the obstacle                        & Failed detection algorithm                     & Statedog, Recovery Blocks                                        & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the detection algorithm.                                                                           \\ \hline
2.2                & Failure to detect the inbound obstacle & USV does not map the obstacle                   & USV sails as there was nothing on its way, results in collusion with the obstacle                        & Failed sensor; Corrupted sensor data           & Redundant \& Diverse Sensors                                     & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the sensors (Camera, Radar, AIS).                                                                  \\ \hline
3.1                & Failure to move                        & USV does not accelerate                         & USV attempts to navigate in the environment, results in getting stuck on the initial position            & Failed llstack initiation priority protocol    & Statedog                                                         & No                                 & \cellcolor[HTML]{F8FF00}Medium & A problem possibly rooted within the llstack start-up procedure.                                                                    \\ \hline
3.2                & Failure to arrive to the destination   & USV does not stop at the desired goal point     & USV skips the destination, stops somewhere else and/or keeps going                                       & Failed preferenceStore data transmission       & Redundant Data Diversity                                         & No                                 & \cellcolor[HTML]{F8FF00}Medium & A problem where preferenceStore either gets started too late or transmits corrupted data, leading navigational errors.              \\ \hline
3.3                & Failure to sail normally               & USV acts abnormally, sails unexpectedly         & USV sails abnormally, deviates from the route.                                                           & Failed Mediator component                      & Statedog                                                         & Yes                                & \cellcolor[HTML]{32CB00}Low    & A problem where Mediator somehow fails to compare the results from other Mediators, therefore passing the commands without a check. \\ \hline
\end{tabular}
\caption{Preliminary Hazard Analysis for the Software of USV Roboship}
\label{my-label}

\end{sidewaystable}

and here is my unfortunate output:

enter image description here

as you can see, it floats out of the page, and doesn't even include the coloumn headers, etc.

Anyone knows a quick solution to this?

3
  • 1
    Make the table smaller ;-)
    – Johannes_B
    Commented Apr 6, 2016 at 7:37
  • Welcome to SE. Please complete your code sniped, that we can compile it and see, how to reduce your table size.
    – Zarko
    Commented Apr 6, 2016 at 7:40
  • You might want to preserve proportions/look/font-size of your table. In this case, consider making it run over two pages (in this case, look at the longtable package)
    – ebosi
    Commented Apr 6, 2016 at 7:43

1 Answer 1

1

Quick and dirty: you can reduce the fontsize and make the columns narrower. Still an overfull box, so it's bigger than the text area, but it fits the (A4) page at least.

\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{array,rotating}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{sidewaystable}[]
\centering\footnotesize
\begin{tabular}{|M{1cm}|M{1.25cm}|M{2.2cm}|M{3.0cm}|M{2cm}|M{2.5cm}|M{1.5cm}|M{1.7cm}|M{2.5cm}|}
\hline
\textbf{Hazard ID} & {\textbf{Hazard}}   & {\textbf{Incident/Event}}    & {\textbf{Potential Consequences/Impacts}}                                             & {\textbf{Potential Causes}}                   & {\textbf{Mitigation and Prevention Measures}} & \textbf{Potential Offsite Impact?} & \textbf{Qualitative Risk}      & {\textbf{Comments}}                                                                         \\ \hline
1.1                & Failure to generate safe path          & USV does not avoid the obstacle                 & USV attempts to navigate in the environment, results in collusion with the obstacle                      & Failed obstacle avoidance module               & Statedog, N-Version Programming                                  & Yes                                & \cellcolor[HTML]{FE0000}High   & Problem can be either the VFH* component, or the estimation of the obstacle position by the COLREGs component.                      \\ \hline
1.2                & Failure to provide desired manoeuvre   & USV does not provide the necessary acceleration & USV attempts to avoid the obstacle, cannot manoeuvre as expected, results in collusion with the obstacle & Failed sensor; Corrupted sensor data           & Redundant \& Diverse Sensors                                     & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the sensors and/or controllers.                                                                    \\ \hline
2.1                & Failure to detect the inbound obstacle & USV does not map the obstacle                   & USV sails as there was nothing on its way, results in collusion with the obstacle                        & Failed detection algorithm                     & Statedog, Recovery Blocks                                        & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the detection algorithm.                                                                           \\ \hline
2.2                & Failure to detect the inbound obstacle & USV does not map the obstacle                   & USV sails as there was nothing on its way, results in collusion with the obstacle                        & Failed sensor; Corrupted sensor data           & Redundant \& Diverse Sensors                                     & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the sensors (Camera, Radar, AIS).                                                                  \\ \hline
3.1                & Failure to move                        & USV does not accelerate                         & USV attempts to navigate in the environment, results in getting stuck on the initial position            & Failed llstack initiation priority protocol    & Statedog                                                         & No                                 & \cellcolor[HTML]{F8FF00}Medium & A problem possibly rooted within the llstack start-up procedure.                                                                    \\ \hline
3.2                & Failure to arrive to the destination   & USV does not stop at the desired goal point     & USV skips the destination, stops somewhere else and/or keeps going                                       & Failed preferenceStore data transmission       & Redundant Data Diversity                                         & No                                 & \cellcolor[HTML]{F8FF00}Medium & A problem where preferenceStore either gets started too late or transmits corrupted data, leading navigational errors.              \\ \hline
3.3                & Failure to sail normally               & USV acts abnormally, sails unexpectedly         & USV sails abnormally, deviates from the route.                                                           & Failed Mediator component                      & Statedog                                                         & Yes                                & \cellcolor[HTML]{32CB00}Low    & A problem where Mediator somehow fails to compare the results from other Mediators, therefore passing the commands without a check. \\ \hline
\end{tabular}
\caption{Preliminary Hazard Analysis for the Software of USV Roboship}
\label{my-label}
\end{sidewaystable}
\end{document}

longtable

ebo suggested using longtable in a comment, to allow the table to break across pages. To do that you also have switch from sidewaystable to landscape, and the \caption has to be moved inside the longtable.

I loaded the pdflscape package for the landscape environment.

\documentclass[a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{array,pdflscape,longtable}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{landscape}
\centering\footnotesize
\begin{longtable}{|M{1cm}|M{1.25cm}|M{2.2cm}|M{3.0cm}|M{1.8cm}|M{2.2cm}|M{1.5cm}|M{1.6cm}|M{2.5cm}|}
\caption{Preliminary Hazard Analysis for the Software of USV Roboship\label{my-label}} \\
\hline
\textbf{Hazard ID} & {\textbf{Hazard}}   & {\textbf{Incident/Event}}    & {\textbf{Potential Consequences/Impacts}}                                             & {\textbf{Potential Causes}}                   & {\textbf{Mitigation and Prevention Measures}} & \textbf{Potential Offsite Impact?} & \textbf{Qualitative Risk}      & {\textbf{Comments}}                                                                         \\ \hline
1.1                & Failure to generate safe path          & USV does not avoid the obstacle                 & USV attempts to navigate in the environment, results in collusion with the obstacle                      & Failed obstacle avoidance module               & Statedog, N-Version Programming                                  & Yes                                & \cellcolor[HTML]{FE0000}High   & Problem can be either the VFH* component, or the estimation of the obstacle position by the COLREGs component.                      \\ \hline
1.2                & Failure to provide desired manoeuvre   & USV does not provide the necessary acceleration & USV attempts to avoid the obstacle, cannot manoeuvre as expected, results in collusion with the obstacle & Failed sensor; Corrupted sensor data           & Redundant \& Diverse Sensors                                     & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the sensors and/or controllers.                                                                    \\ \hline
2.1                & Failure to detect the inbound obstacle & USV does not map the obstacle                   & USV sails as there was nothing on its way, results in collusion with the obstacle                        & Failed detection algorithm                     & Statedog, Recovery Blocks                                        & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the detection algorithm.                                                                           \\ \hline
2.2                & Failure to detect the inbound obstacle & USV does not map the obstacle                   & USV sails as there was nothing on its way, results in collusion with the obstacle                        & Failed sensor; Corrupted sensor data           & Redundant \& Diverse Sensors                                     & Yes                                & \cellcolor[HTML]{FE0000}High   & A problem possibly rooted within the sensors (Camera, Radar, AIS).                                                                  \\ \hline
3.1                & Failure to move                        & USV does not accelerate                         & USV attempts to navigate in the environment, results in getting stuck on the initial position            & Failed llstack initiation priority protocol    & Statedog                                                         & No                                 & \cellcolor[HTML]{F8FF00}Medium & A problem possibly rooted within the llstack start-up procedure.                                                                    \\ \hline
3.2                & Failure to arrive to the destination   & USV does not stop at the desired goal point     & USV skips the destination, stops somewhere else and/or keeps going                                       & Failed preferenceStore data transmission       & Redundant Data Diversity                                         & No                                 & \cellcolor[HTML]{F8FF00}Medium & A problem where preferenceStore either gets started too late or transmits corrupted data, leading navigational errors.              \\ \hline
3.3                & Failure to sail normally               & USV acts abnormally, sails unexpectedly         & USV sails abnormally, deviates from the route.                                                           & Failed Mediator component                      & Statedog                                                         & Yes                                & \cellcolor[HTML]{32CB00}Low    & A problem where Mediator somehow fails to compare the results from other Mediators, therefore passing the commands without a check. \\ \hline
\end{longtable}
\end{landscape}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .