user4964330
user4964330

Reputation:

Latex Table Fitting

I'm trying to fit a table to a page and I did that eventually, by using \resizebox{\textwidth}{!} and {sidewaystable} , now it fits in a page. However it is not even readable anymore. The text became so small that table has no use now. Here is my table:

\begin{sidewaystable}[]
\centering
\resizebox{\textwidth}{!}{\begin{tabular}{|c|l|l|l|l|l|c|c|l|}
\hline
\textbf{Hazard ID} & \multicolumn{1}{c|}{\textbf{Hazard}}   & \multicolumn{1}{c|}{\textbf{Incident/Event}}    & \multicolumn{1}{c|}{\textbf{Potential Consequences/Impacts}}                                             & \multicolumn{1}{c|}{\textbf{Potential Causes}}                   & \multicolumn{1}{c|}{\textbf{Mitigation and Prevention Measures}} & \textbf{Potential Offsite Impact?} & \textbf{Qualitative Risk}      & \multicolumn{1}{c|}{\textbf{Comments}}                                                                         \\ \hline
1.1                & 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]{F8FF00}Medium & A problem possibly rooted within the sensors and/or controllers.                                               \\ \hline
1.2                & 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]{34FF34}Low    & Problem can be either the VFH* component, or the estimation of the obstacle position by the COLREGs component. \\ \hline
1.3                & 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, Failed sensor; Corrupted sensor data & Statedog, Redundant \& Diverse Sensors, Recovery Blocks          & Yes                                & \cellcolor[HTML]{F56B00}High   & A problem possibly rooted within the detection algorithm.                                                      \\ \hline
\end{tabular}}
\caption{My caption}
\label{my-label}
\end{sidewaystable}

Is there a way to adjust the table to fit in a page, meanwhile maintaining the text size? One idea is to have spaces, as I have sentences in my table. If I give spaces (like 1-2 words per line), then I guess it would fit. However when I insert \\ the table gets screwed, things collide and everything looks even more ridiculous.

Here is what I want to achieve finally:

enter image description here

And unfortunately, here is what I get:

enter image description here

Any thoughts?

Upvotes: 0

Views: 711

Answers (1)

Gipfeli
Gipfeli

Reputation: 61

First, you can add these to the preamble:

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

You don't need \resizebox{\textwidth}{!}.

You should change \begin{tabular}{|c|l|l|l|l|l|c|c|l|} to \begin{tabular}{|M{1.5cm}|M{1.85cm}|M{3.5cm}|M{6cm}|M{2.5cm}|M{2cm}|M{2cm}|M{2cm}|M{3cm}|}

Finally, please omit \multicolumn{1}{c|} at each header cell. Here is the result.

enter image description here

Upvotes: 2

Related Questions