1

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}
2
  • 1
    Regarding 1: You forgot the space between the columns. ~ 16\tabcolsep. – Ulrike Fischer Aug 13 '15 at 13:13
  • What does this mean? How much is the space? I don't see any. What is 16\tabcolsep? – anjuta Aug 13 '15 at 13:24
3

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

2
  • Thank you, this looks right. But I don't understand why. And how do I get my vertical lines back between the columns? – anjuta Aug 13 '15 at 13:33
  • 1
    Just use your MWE and substract the -2\tabcolsep. I deleted that lines as I used booktabs which I like more. The explanation for what's happening: You are setting p columns which act like parboxes. You give them a certain width which delimits the possible space for text. As you can see, there is always some white space between those blocks. Those are \tabcolseps which are set in front and behind every column. The sum of all columns plus n times 2\tabcolsep results in your \textwidth – LaRiFaRi Aug 13 '15 at 13:36
0

It is a matter of taste, but I like ltxtable (Longtable and tabularx merge). The usage might seem awkward, but it does a decent job when you want to set the width of a longtable to a fix value like \textwidth.

\documentclass{scrartcl}
\usepackage{array,longtable,ltxtable,filecontents}
\usepackage[showframe]{geometry}

\begin{document}

\begin{filecontents}{long.tex}
\begin{longtable}[c]{|p{0.26\textwidth}|*{6}{X|}}
  \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{filecontents}

\LTXtable{1.0\linewidth}{long.tex}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.