serhii.net

In the middle of the desert you can say anything you want

18 Apr 2024

Latex centering wide tables

… is hard and nothing worked. If it’s over the margin at least.

After trial and error I got this1.

% \centerline{
\begin{table}[t]
% \begin{center}
\footnotesize
\centering
    \addtolength{\leftskip} {-2cm} % increase (absolute) value if needed
    \addtolength{\rightskip}{-2cm}
% \begin{adjustbox}{center}
% \resizebox{1.0\textwidth}{!}{% Adjust the scale as needed
\begin{tabular*}{1.25\textwidth}{lrrrrrrrrr}
\hline
                          &   LOW &   WIS &   cats\_bin &   cats\_mc &   wordalpha &   wordlength &   UA-CBT &   UP-masked &   UP-unmasked \\
\hline
 BASELINE-human           &       0.97 &       0.94 &            0.97 &           0.98 &             0.92 &              0.94 &     0.94 &        0.84 &          0.88 \\
 BASELINE-random          &       0.09 &       0.05 &            0.50 &           0.20 &             0.50 &              0.50 &     0.17 &        0.10 &          0.10 \\
 Mistral-7B-Instruct-v0.2 &       0.34 &       0.19 &            0.59 &           0.71 &             0.48 &              0.71 &     0.46 &        0.75 &          0.86 \\
 Ms-Inst-Ukr-SFT          &       0.31 &       0.16 &            0.66 &           0.55 &             0.48 &              0.66 &     0.42 &        0.82 &          0.87 \\
 Ms-Inst-Ukr-Slerp        &       0.35 &       0.19 &            0.66 &           0.66 &             0.49 &              0.70 &     0.45 &        0.79 &          0.87 \\
 Ms-Inst-Ukr-sherl        &       0.37 &       0.19 &            0.69 &           0.76 &             0.50 &              0.75 &     0.55 &        0.88 &          0.92 \\
 gpt-3.5-turbo            &       0.68 &       0.34 &            0.68 &           0.91 &             0.78 &              0.89 &     0.61 &        0.77 &          0.86 \\
 gpt-4-1106-preview       &       0.67 &       0.39 &            0.86 &           0.93 &             0.85 &              0.95 &     0.97 &        0.96 &          0.97 \\
\hline
\end{tabular*}
% }
% \end{adjustbox}
% \caption[Evaluation scores]{\TODO{Scores of selected models}}
\label{tab:eval}
% \end{center}
\end{table}
% }

The width 1.25\textwidth has to be manually chosen otherwise the table lines are too long or short for the text.

If it’s too low or too high it causes this (left is low):

2024-04-18-140659_239x215_scrot.png 2024-04-18-140750_112x229_scrot.png

As usual, when doing these things, Overleaf’s draft mode is golden.

For positioning on the page, quoting Overleaf2:

The parameter `h!` passed to the table environment declaration establishes that this table must be placed _here_, and override LATEX defaults. The positioning parameters that can be passed-in include:

`h`
Will place the table _here_ approximately.

`t`
Position the table at the _top_ of the page.

`b`
Position the table at the _bottom_ of the page.

`p`
Put the table in a special page, for tables only.

`!`
Override internal LATEX parameters.

`H`
Place the table at this precise location, pretty much like h!.
Nel mezzo del deserto posso dire tutto quello che voglio.