[Tex/LaTex] Centering longtable

horizontal alignmentlongtable

I use longtable for some very long tables showing evaluation results. They look ok, but I have two problems with them:

  1. For some reason, I don't understand, the table seems to be too wide. When I sum up all my p values I get to 0.98/textwidth. Why should this be broader then /textwidth?
  2. LaTeX writes only across the right margin. Is there any way to tell it to write onto both side margins to center the table?
    I tried the solution from here, but it does not do anything.

Here is a MWE:

\documentclass{scrartcl}
\usepackage{longtable}
\begin{document}
\begin{longtable}[c]{|p{0.26\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|p{0.12\textwidth}|}
    \hline
    \textbf{settings} & \textbf{micro-average precision} & \textbf{micro-average recall} & \textbf{micro-average f-score} & \textbf{macro-average precision} & \textbf{macro-average recall} & \textbf{macro-average f-score} \\ \hline 
\end{longtable}
\end{document}

Best Answer

I would not advice to get out of the margins if not absolutely necessary. This looks inconsistent and therefore typographically ugly (I am exaggerating). Just reduce each column by the width of its two separators on both sides and you are good to go. I have enlarged the width so that you can use the maximum available. If you reduce a bit, the [c] will do the centring for you.

% arara: pdflatex

\documentclass{scrartcl}
\usepackage{longtable}
\usepackage{calc}
\usepackage{booktabs}
\usepackage{showframe} % just for demo

\begin{document}
    \begin{longtable}[c]{p{0.28\textwidth-2\tabcolsep}*{6}{p{0.12\textwidth-2\tabcolsep}}}
        \toprule
        \textbf{settings} & \textbf{micro-average precision} & \textbf{micro-average recall} & \textbf{micro-average f-score} & \textbf{macro-average precision} & \textbf{macro-average recall} & \textbf{macro-average f-score} \\ 
        \bottomrule 
    \end{longtable}
\end{document}

enter image description here

Related Question