2

I have finally faced a problem when all googling, this forum and any wittiness could not help me out. I have been working in a \longtable environment when in seemingly the most simple table I have ever made an unwanted extra spacing appeared with no visible for me reason. Here is the code:

\usepackage{longtable}
\usepackage{polyglossia}
\setdefaultlanguage{latvian}

\begin{longtable}{ccccc}
 \caption{Virknes slēguma bezdimensionālie lielumi} \\ %fixed
  \hline
   npk & $\omega$ & $i$ & $u_C$ & $u_L$ \\
  \hline
  \endfirsthead

   \multicolumn{5}{c}
    {{\tablename\ \thetable{} (turpināta no iepriekšējas lappuses)}} \\ \\
  \hline
   npk & $\omega$ & $i$ & $u_C$ & $u_L$ \\
 \hline 
 \endhead

 \hline \multicolumn{5}{l}{{Tabulas turpinājums nākamā lappusē}} \\
 \endfoot

\hline
\endlastfoot
  %just data
  1  & 1,71 & 0,891 & 0,522 & 1,52 \\
  2  & 1,68 & 0,923 & 0,551 & 1,55 \\
  3  & 1,62 & 0,995 & 0,614 & 1,61 \\
  4  & 1,45 & 1,32 & 0,911 & 1,91 \\
  5  & 1,30 & 1,86 & 1,43 & 2,42 \\
  6  & 1,21 & 2,51 & 2,07 & 3,05 \\
  7 & 1,16 & 3,32 & 2,87 & 3,84 \\
  8  & 1,10 & 4,94 & 4,49 & 5,43 \\
  9  & 1,01 & 12,8 & 12,6 & 12,9 \\
  10 & 0,984 & 12,3 & 12,5 & 12,1 \\
  11 & 0,955 & 8,47 & 8,87 & 8,09 \\
  12  & 0,941 & 6,98 & 7,42 & 6,57 \\
  13  & 0,926 & 5,87 & 6,33 & 5,43 \\
  14  & 1,04 & 9,07 & 8,71 & 9,45 \\
  15  & 0,868 & 3,41 & 3,93 & 2,96 \\
  16  & 0,752 & 1,71 & 2,28 & 1,29 \\
  17  & 0,665 & 1,19 & 1,79 & 0,790 \\
  18  & 0,578 & 0,867 & 1,50 & 0,501 \\
\end{longtable}

I need to use Latvian language, I don't think, that it is important, but just prefered to show my problem as it is. Will appreciate any help and advice.

unwanted gap between 4th and 5th column

  • please always post a complete document, if I guess a preamble for your document I get ! Misplaced \noalign.\hline ->\noalign from teh missing \\ after \caption – David Carlisle Dec 17 '13 at 1:25
  • I have fixed the code. Thank you very much, because this was another problem that I was facing, it just did not bothered me, because compiler created a good pdf file anyway. – Max Dec 17 '13 at 1:35
  • The error corrections that tex makes after an error are more or less entirely arbitrary, a pdf file may be made but really it's not worth looking at except for debugging. Certainly on a forum like this, don't describe one problem and post code that generates unrelated errors:-) – David Carlisle Dec 17 '13 at 1:48
4

If you don't want the extra padding, you could use this solution instead which makes use of longtable's caption facilities:

\documentclass{article}
\usepackage{longtable}
\usepackage{polyglossia}
\setdefaultlanguage{latvian}
\begin{document}
      \begin{longtable}{ccccc}
          \caption{Virknes slēguma bezdimensionālie lielumi}\\
          \hline
          npk & $\omega$ & $i$ & $u_C$ & $u_L$\\
          \hline
        \endfirsthead
          \caption[]{(turpināta no iepriekšējas lappuses)}\\ \\
          \hline
          npk & $\omega$ & $i$ & $u_C$ & $u_L$\\
          \hline
        \endhead
          \hline \multicolumn{5}{l}{{Tabulas turpinājums nākamā lappusē}}\\
        \endfoot
          \hline
        \endlastfoot
        %just data
        1  & 1,71 & 0,891 & 0,522 & 1,52 \\
        2  & 1,68 & 0,923 & 0,551 & 1,55 \\
        3  & 1,62 & 0,995 & 0,614 & 1,61 \\
        4  & 1,45 & 1,32 & 0,911 & 1,91 \\
        5  & 1,30 & 1,86 & 1,43 & 2,42 \\
        6  & 1,21 & 2,51 & 2,07 & 3,05 \\
        7 & 1,16 & 3,32 & 2,87 & 3,84 \\
        8  & 1,10 & 4,94 & 4,49 & 5,43 \\
        9  & 1,01 & 12,8 & 12,6 & 12,9 \\
        10 & 0,984 & 12,3 & 12,5 & 12,1 \\
        11 & 0,955 & 8,47 & 8,87 & 8,09 \\
        12  & 0,941 & 6,98 & 7,42 & 6,57 \\
        13  & 0,926 & 5,87 & 6,33 & 5,43 \\
        14  & 1,04 & 9,07 & 8,71 & 9,45 \\
        15  & 0,868 & 3,41 & 3,93 & 2,96 \\
        16  & 0,752 & 1,71 & 2,28 & 1,29 \\
        17  & 0,665 & 1,19 & 1,79 & 0,790 \\
        18  & 0,578 & 0,867 & 1,50 & 0,501 \\
  \end{longtable}
\end{document}

png converted from pdf showing solution using longtable's caption handling

This, by the way, is how longtable tells you to manage a variant caption if you need a different caption on later pages. Passing the empty optional command to \caption will prevent the table being added to the list of tables a second time.

  • Does anybody know how to stop the image being that big? I converted the pdf using convert from ImageMagick. (I only just figured out how to do this at all so perhaps not surprising I'm clearly doing something wrong.) – cfr Dec 17 '13 at 2:01
  • I edited it in gwenview but that's a pain. Surely there's a more automatic solution? – cfr Dec 17 '13 at 2:06
  • +1 for reading the longtable manual, I should try that one day:-) – David Carlisle Dec 17 '13 at 2:07
3

If I correct for the omitted \\ after \caption. The problem is that LT caption is a \multicolumn and if a spanning cell is wider than the natural width of the cells it spans, TeX puts all the space in the final column. If you add extra padding, things work better.

      \begin{longtable}{@{\extracolsep{10pt}}ccccc@{}}

enter image description here

Or perhaps better align on the decimal ,

enter image description here

      \usepackage{dcolumn}
       \newcolumntype{,}{D{,}{{,}}{3.4}}
\begin{document}

      \begin{longtable}{r,,,,}
        \caption{Virknes slēguma bezdimensionālie lielumi}\\
        \hline
        npk & \multicolumn{1}{c}{$\omega$} & 
\multicolumn{1}{c}{$i$} & \multicolumn{1}{c}{$u_C$} &
\multicolumn{1}{c}{ $u_L$} \\
        \hline
        \endfirsthead

        \multicolumn{5}{c}
        {{\tablename\ \thetable{} (turpināta no iepriekšējas lappuses)}} \\
        \hline
        npk &\multicolumn{1}{c}{$\omega$}&
\multicolumn{1}{c}{$i$} & 
\multicolumn{1}{c}{$u_C$}&
\multicolumn{1}{c}{$u_L$}\\
        \hline 
        \endhead

        \hline \multicolumn{5}{l}{{Tabulas turpinājums nākamā lappusē}} \\
        \endfoot

        \hline
        \endlastfoot
        %just data
        1  & 1,71 & 0,891 & 0,522 & 1,52 \\
  • Thank you. Personally I prefered the first solution, because I have all my other tables in the document with centered cell elements. By the way, I thought of that a problem was with a caption size, I have tried to change it before but it have not worked for me. – Max Dec 17 '13 at 1:57
  • The problem is that your "caption" is not given as a caption, I think. So longtable adjusts for it whereas if it was specified with \caption, it wouldn't have this effect. – cfr Dec 17 '13 at 2:02
  • @cfr oops well spotted:-) – David Carlisle Dec 17 '13 at 2:03
1

Here is an implementation using the S column construction from siunitx.

\documentclass{article}

\usepackage{longtable}
\usepackage{booktabs}
\usepackage[
  locale = DE % comma instead of full stop as decimal separator
]{siunitx}
\usepackage{polyglossia}
\setdefaultlanguage{latvian}

\newcommand*\mc[1]{\multicolumn{1}{c}{#1}}

\begin{document}

\begin{longtable}{
  S[table-format = 2]
  S[table-format = 1.3]
  S[table-format = 2.3]
  S[table-format = 2.3]
  S[table-format = 2.3]
}
  \caption{Virknes slēguma bezdimensionālie lielumi}
  \label{tbl:something}
  \\
    \toprule
     \mc{npk} & \mc{$\omega$} & \mc{$i$} & \mc{$u_C$} & \mc{$u_L$} \\
    \midrule
   \endfirsthead
    \caption[]{Virknes slēguma bezdimensionālie lielumi (turpināta no iepriekšējas lappuses)}
  \\
    \toprule
     \mc{npk} & \mc{$\omega$} & \mc{$i$} & \mc{$u_C$} & \mc{$u_L$} \\
    \midrule
   \endhead
    \bottomrule
     \multicolumn{5}{l}{Tabulas turpinājums nākamā lappusē} \\
     \endfoot
    \bottomrule
     \endlastfoot
      1 & 1.71  &  0.891 &  0.522 &  1.52  \\
      2 & 1.68  &  0.923 &  0.551 &  1.55  \\
      3 & 1.62  &  0.995 &  0.614 &  1.61  \\
      4 & 1.45  &  1.32  &  0.911 &  1.91  \\
      5 & 1.30  &  1.86  &  1.43  &  2.42  \\
      6 & 1.21  &  2.51  &  2.07  &  3.05  \\
      7 & 1.16  &  3.32  &  2.87  &  3.84  \\
      8 & 1.10  &  4.94  &  4.49  &  5.43  \\
      9 & 1.01  & 11.8   & 12.6   & 12.9   \\
     10 & 0.984 & 12.3   & 12.5   & 12.1   \\
     11 & 0.955 &  8.47  &  8.87  &  8.09  \\
     12 & 0.941 &  6.98  &  7.42  &  6.57  \\
     13 & 0.926 &  5.87  &  6.33  &  5.43  \\
     14 & 1.04  &  9.07  &  8.71  &  9.45  \\
     15 & 0.868 &  3.41  &  3.93  &  2.96  \\
     16 & 0.752 &  1.71  &  2.28  &  1.29  \\
     17 & 0.665 &  1.19  &  1.79  &  0.790 \\
     18 & 0.578 &  0.867 &  1.50  &  0.501 \\
\end{longtable} 

\end{document}

output

Note the use of booktabs to get the correct horizontal lines.

P.S. Complie three times using xelatex.

  • The reasin I have not used siuntix is exactly because I did not know how to change decimal separator to coma, so thank you very much. I would lika to ask, if it is a common thing that columns are aligned to coma. For example, in this particular case it seems to me that columns are better centered, because rows number 9 and 10 look kind of messy. Am I guessing correctly, saying that this kind of alignment used for scientific notation? – Max Dec 17 '13 at 17:18
  • 1
    @Max The alignment depends on the context; normally physical quantities (where the unit usually is set globally on top of the column) are aligned at the decimal separator. I know that it looks somewhat messy, but that again, it is much easier to recognize the relative value of the numbers. – Svend Tveskæg Dec 17 '13 at 17:30

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.