1

I am new to latex, and saw a lot of other questions asking about this, but I could not find a way to fit my 5 column table in a page.

\begin{table}[h]
\centering
\begin{tabularx}{\textwidth}{|c|c|c|c|c|}
    \hline
    Area of Interest & Pearson Correlation and p-value & Spearman correlation and p-value & Mean squared error (MSE) & $R^2$ Value\\
    \hline
    Buoy 44097 and satellite $H_s$ (0.25 dd) & (0.9872, 0.05$<$)  & (0.9663, 0.05$<$) & 0.1268 & 0.9683\\
    \hline
    Buoy 44097 and satellite $H_s$ (0.25- 0.5 dd) & (0.9795, 0.05$<$)  & (0.9641, 0.05$<$) & 0.1605 & 0.9586\\
    \hline
\end{tabularx}
\caption{Correlation, $R^2$ Value, and MSE values between buoy 44097 and Saral/AltiKa Hs measurements.}
\end{table}

I got this: enter image description here

Bob
  • 55
  • It must be at least one X column. Note also than c columns cannot have line breaks, so the width depend on the content, i.e., use \begin{tabularx}{\textwidth}{XXXXX} or \begin{tabularx}{\textwidth}{cXXXX}, or \begin{tabularx}{\textwidth}{XXccc}, etc. Run texdoc tabularx, BTW, run also texdoc booktabs. – Fran Jun 16 '20 at 01:34

1 Answers1

1

This is a simple fix of mistake of not using X columns in tabularx (btw, \centering have no sense if width of is \textwidth), and an alternative format using tabulary and booktabs, also with some others design changes:

mwe

\documentclass{article}
\usepackage{booktabs,tabularx,tabulary}
\begin{document}

\begin{table}[h] \begin{tabularx}{\textwidth}{|p{7em}|X|X|X|X|} \hline Area of Interest & Pearson Correlation and p-value & Spearman correlation and p-value & Mean squared error (MSE) & $R^2$ Value\ \hline Buoy 44097 and satellite $H_s$ (0.25 dd) & (0.9872, 0.05$<$) & (0.9663, 0.05$<$) & 0.1268 & 0.9683\ \hline Buoy 44097 and satellite $H_s$ (0.25- 0.5 dd) & (0.9795, 0.05$<$) & (0.9641, 0.05$<$) & 0.1605 & 0.9586\ \hline \end{tabularx}

\caption{Correlation, $R^2$ Value, and MSE values between buoy 44097 and Saral/AltiKa Hs measurements.} \end{table}

\begin{table}[h] \tymin0pt\tymax145pt\sffamily\small \caption{Correlations, $R^2$ Value, and Mean Square Error (MSE) values between buoy 44097 and Saral/AltiKa Hs measurements.} \begin{tabulary}{\textwidth}{LCCCC}\toprule Area of Interest & \mbox{Pearson's $r$} (p-value) & \mbox{Spearman's $\rho$} (p-value) & MSE & $R^2$ \\midrule Buoy 44097 and satellite $H_s$ (0.25 dd) & 0.9872 ($<$0.05) & 0.9663 ($<$0.05) & 0.1268 & 0.9683\\addlinespace Buoy 44097 and satellite $H_s$ (0.25--0.5 dd) & 0.9795 ($<$0.05) & 0.9641 ($<$0.05) & 0.1605 & 0.9586\\bottomrule \end{tabulary} \end{table}

\end{document}

Fran
  • 80,769