2

I am trying to get a large table to fit the page. I have tried multiple solutions found on this post. I am not sure if I am understanding the issue correctly. The error is overfull \hbox. Here is the table I am trying to set up. I have tried removing a couple of the columns and it was fine, but I would prefer keeping everything.

\newgeometry{margin=1.5cm} % modify this if you need even more space
\begin{landscape}
\subsubsection{co variance Matrix}
\begin{table}[htbp]
    \begin{center}
    \tiny
\caption{Co variance Matrix}
\label{tab:cmcDataCoVar}
\begin{tabular}{|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4m}|p{.4cm}|p{.4cm}|p{.4cm}|p{.4cm}}
\hline
 1.0&-0.1&-0.2& 0.0&-0.2& 0.1& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.1&-0.1\\
-0.1& 1.0&-0.1&-0.3& 0.1&-0.3& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0\\
-0.2&-0.1& 1.0& 0.5& 0.4& 0.3& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0&-0.1& 0.1\\
-0.0&-0.3& 0.5& 1.0& 0.4& 0.8&-0.1& 0.1& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0&-0.1& 0.0\\
-0.2& 0.1& 0.4& 0.4& 1.0&-0.2&-0.1& 0.0& 0.0& 0.0& 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& 0.0& 0.0\\
 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0\\
 0.0& 0.0& 0.0& 0.0& 0.1& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0\\
 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.1& 0.0& 0.0&-0.1\\
 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0\\
 0.1& 0.0&-0.1&-0.1&-0.1& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.2&-0.2\\
-0.1& 0.0& 0.1& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0&-0.1& 0.0&-0.2& 0.2\\
    \hline
\end{tabular}

\end{center} \end{table} \end{landscape} \restoregeometry

Paul Gessler
  • 29,607
  • 6
    I get an error ! Illegal unit of measure (pt inserted). as you have .4m not .4cm but other than that if I guess the parts you didn't show as \documentclass{article} \usepackage{geometry} \usepackage{lscape} \usepackage{array} \begin{document} then it fits easily on the page the output is this screenshot – David Carlisle Nov 17 '21 at 23:22
  • Thanks, I could have sworn I checked that they were all correct multiple times, but I am new to it so I thought the error was coming from something I didnt understand. – Nikita Belooussov Nov 18 '21 at 09:07

1 Answers1

1

As @DavidCarlisle has already pointed out in a comment, there's a typo in one of the p-type columns: p{.4m}. As m is not a valid length unit for TeX, TeX generates an error message. Replacing p{.4m} with p{.4cm} is the obvious remedy.

For the table at hand, it makes sense to want all 26 columns to have equal width. However, it makes little sense to use the p column type, as surely you'll never want line breaking to occur in any of the cells. I suggest you switch to the w column type; it lets you specify a fixed usable width, but it won't allow automatic line breaking. Moreover, don't just assign an arbitrary width (of 4mm, say); instead, just measure the needed width via a \settowidth instruction. See the code below for how to implement this idea.

I would further like to suggest that you (a) employ an array environment instead of a tabular environment (since the contents of all columns are "math-y"), (b) reduce the amount of inter-column whitespace padding (specifically, from 5pt to 3pt), and (c) right-align the cells in order to make the numbers look like they're aligned on the decimal markers.

With these changes in place, there happily is no need to run \tiny; indeed, \small will do just fine. Your readers will definitely appreciate that you're not forcing them to squint -- or go looking for a magnifying glass.

enter image description here

\documentclass{article}
\usepackage{array} % for 'w' column type
\usepackage{geometry,pdflscape}
\newlength\mylen
\settowidth{\mylen}{\small$-0.2$} % measure the required (usable) width of columns

\begin{document} \newgeometry{margin=1.5cm} % modify this as needed

\begin{landscape} \subsubsection*{Covariance matrix} \begin{table}[htbp] \centering \setlength\arraycolsep{3pt} % default: 5pt \setlength\extrarowheight{1pt} % for a less cramped "look" \small % not \tiny

\caption{Covariance matrix}
\label{tab:cmcDataCoVar}

\medskip
$\begin{array}{| *{26}{wr{\mylen}|} }
\hline
 1.0&-0.1&-0.2& 0.0&-0.2& 0.1& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.1&-0.1\\
-0.1& 1.0&-0.1&-0.3& 0.1&-0.3& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0.0& 0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