0

I have troubles with the table widths in my LTXtables. Somehow they change and I get the following info:

Column widths have changed(longtable) in table 1

Column widths have changed(longtable) in table 2

Table widths have changed. Rerun LaTeX.

However, no matter how often I run LaTex, the problem does not go away.

Does someone have an idea what is wrong with my code?

The two tables that cause the issue span at least two pages. It seems like that this causes the problem (with a smaller table I do not have the issue). In the following minimal example I have therefore kept the original length of the tables.

Here is the minimal example:

\documentclass[12pt, a4paper, notitlepage]{article}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{epsfig}
\usepackage{graphicx}
\usepackage{ragged2e,array,afterpage}
\usepackage{lscape,booktabs}
\usepackage{ltxtable}
\usepackage{pdflscape}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}  
\usepackage[english]{babel}
\usepackage{ae,aecompl} 
\usepackage{endnotes}
\usepackage[onehalfspacing]{setspace} % doublespacing singlespacing onehalfspacing
\usepackage[headsep=1cm,headheight=2cm, margin=3cm]{geometry}


%%%%%For Tables%%%%%%
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{-1}}  % define "d" column type
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}

\usepackage{lipsum}


\begin{document}


\section{Bla}

\lipsum[1-3]

\begin{landscape}
        \begin{spacing}{1}
        \begin{footnotesize}
            \LTXtable{\linewidth}{Table1}
        \end{footnotesize}  
        \end{spacing}
\end{landscape}

\lipsum[4-5]

\begin{spacing}{1}
    \begin{footnotesize}
    \LTXtable{\linewidth}{Table2}
    \end{footnotesize}  
\end{spacing}


\end{document}

This is Table 1

\begin{longtable}{X *6{d{4.4cm}}}
    \caption{Some Title 1}\label{Tab: table_1} \\ \toprule
    & \mc{1} & \mc{2}  & \mc{3} & \mc{4} & \mc{5} & \mc{6} \\ \midrule
    \endfirsthead
    \caption*{\textbf{Table~\ref{Tab: table_1}} continued} \\ \toprule
    \endhead
    \endfoot
    \multicolumn{6}{l}{\textbf{(a)}}  \\
    \midrule    
        & \mc{(3)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(7)} & \mc{(6)}\\   \midrule 
    Variable 1 & 387.374\sym{***} & -0.024\sym{***} & 0.023\sym{***} & -0.024\sym{***} & 0.088\sym{***} & 0.234\sym{***} \\
    & (2.673)    & (0.003)   & (0.003)  & (0.003)   & (0.007)  & (0.006) \\ \midrule
    Observations  & \mc{483,276}    & \mc{483,276}   & \mc{483,276}  & \mc{483,276}   & \mc{483,276}  & \mc{483,276} \\
    Mean          & \mc{3704.24}    & \mc{0.03}     & \mc{0.03}     & \mc{0.04}      & \mc{9.86} & \mc{-0.02}  \\ \midrule
    \multicolumn{6}{l}{\textbf{(b)}}  \\    \midrule
        & \mc{(3)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(7)} & \mc{(6)}\\   \midrule 
    Variable 1 & 388.432\sym{***} & -0.027\sym{***} & 0.020\sym{***} & -0.027\sym{***} & 0.374\sym{***} & 0.273\sym{***} \\
    & (2.894)    & (0.003)   & (0.003)  & (0.003)   & (0.007) & (0.007)  \\
    Variable 2 & 273.673\sym{***} & -0.042\sym{***} & 0.033\sym{***} & -0.039\sym{***} & 0.347\sym{***} & 0.434\sym{***} \\
    & (7.722)    & (0.002)   & (0.002)  & (0.002)   & (0.033) & (0.034)  \\ \midrule
    Observations  & \mc{244,624}    & \mc{244,624}   & \mc{244,624}  & \mc{244,624}   & \mc{244,624} & \mc{244,624} \\ 
    Mean          & \mc{3764.40}    & \mc{0.03}      & \mc{0.04}     & \mc{0.04}      & \mc{9.84}  & \mc{0.02}   \\
    Some Test    & \mc{2338.07}    & \mc{268.80}    & \mc{360.48}   & \mc{232.84}    & \mc{363.86}  & \mc{683.77} \\ \midrule 
    \multicolumn{6}{l}{\textbf{(c)}}  \\ \midrule
        & \mc{(3)} & \mc{(2)} & \mc{(3)} & \mc{(4)} & \mc{(7)} & \mc{(6)}\\   \midrule 
    Variable 1 & 379.777\sym{***} & -0.027\sym{***} & 0.036\sym{***} & -0.023\sym{***} & 0.363\sym{***} & 0.240\sym{***} \\
    & (7.867)    & (0.003)   & (0.002)  & (0.003)   & (0.036) & (0.036) \\
    Variable 2 & 272.462\sym{***} & -0.047\sym{***} & 0.030\sym{***} & -0.040\sym{***} & 0.337\sym{***} & 0.430\sym{***} \\
    & (9.283)    & (0.004)   & (0.004)  & (0.004)   & (0.023) & (0.024) \\
    Variable 3 & 303.779\sym{***} & -0.077\sym{***} & 0.038\sym{***} & -0.046\sym{***} & 0.726\sym{***} & 0.773\sym{***} \\
    & (33.743)   & (0.006)   & (0.007)  & (0.006)   & (0.034) & (0.036)  \\     \midrule 
    Observations  & \mc{60,630}    & \mc{60,630 }   & \mc{60,630}   & \mc{60,630}    & \mc{60,630}   & \mc{60,630} \\
    Mean          & \mc{3746.88}    & \mc{0.03}      & \mc{0.04}     & \mc{0.04}      & \mc{9.82}  & \mc{-0.02}   \\
    Some Test    & \mc{298.83}     & \mc{46.33}     & \mc{26.44}    & \mc{33.67}     & \mc{82.66} & \mc{330.62}\\   \midrule    
\multicolumn{7}{p{\linewidth}}{{\scriptsize \textbf{Notes}: \lipsum[3] }} \\
\end{longtable} 

This is Table 2

\begin{longtable}{X *4{d{4.4cm}}}
\caption{Some Title 2}\label{Tab: table_2} \\ \toprule
    & \multicolumn{4}{c}{Some column name} \\
    \cmidrule(lr{1em}){2-5}
    & \multicolumn{2}{c}{type 1} & \multicolumn{2}{c}{type 2} \\
    \cmidrule(lr{.75em}){2-3}  \cmidrule(lr{.75em}){4-5} 
                              & \mc{bla}  & \mc{bla}  & \mc{bla}  &  \mc{bla}  \\ \midrule
\multicolumn{1}{l}{(blabla)}  & \mc{(1)} & \mc{(2)} & \mc{(3)} & \mc{(4)} \\ \midrule
\endfirsthead
\caption*{\textbf{Table~\ref{Tab: table_2}} continued} \\ \toprule
\endhead                              
Variable 1  & -0.391\sym{**}                      &          & 9.766\sym{***}                     &      \\
                              & (0.179)                       &          & (0.177)                       &      \\
Variable 1  & -0.639\sym{***}                    & 0.99     & 9.313\sym{***}                      & 0.31 \\
                              & (0.117)                       &          & (0.177)                       &      \\
Variable 1   & -0.779\sym{***}                    & 0.19     & 9.101\sym{***}                      & 0.98 \\
                              & (0.139)                       &          & (0.177)                       &      \\
Variable 1  & -0.697\sym{***}                     & 0.17     & 1.873\sym{***}                     & 0.30 \\
                              & (0.133)                       &          & (0.171)                       &      \\
Variable 1  & -0.911\sym{*}                      & 0.01     & 1.180\sym{***}                      & 0.06 \\
                              & (0.198)                       &          & (0.118)                       &      \\
Variable 1  & -0.366\sym{***}                     & 0.18     & 1.369\sym{***}                      & 0.77 \\
                              & (0.193)                       &          & (0.117)                       &      \\
Variable 1   & -0.087                        & 0.10     & 0.789\sym{***}                      & 0.01 \\
                              & (0.119)                       &          & (0.170)                       &      \\
Variable 1   & -0.096                        & 0.97     & 0.881\sym{***}                      & 0.61 \\
                              & (0.119)                       &          & (0.176)                       &      \\
Variable 1   & -0.008                        & 0.60     & 1.113\sym{***}                     & 0.31 \\
                              & (0.119)                       &          & (0.161)                       &      \\
Variable 1  & 0.081                         & 0.78     & 0.701\sym{***}                      & 0.08 \\
                              & (0.118)                       &          & (0.173)                       &      \\
Variable 1  & 0.111                         & 0.73     & 0.917\sym{***}                      & 0.10 \\
                              & (0.193)                       &          & (0.187)                       &      \\
Variable 1  & 0.008                         & 0.11     & 0.731\sym{***}                      & 0.19 \\
                              & (0.197)                       &          & (0.199)                       &      \\
Variable 1  & 0.379\sym{***}                      & 0.06     & 0.708\sym{***}                      & 0.99 \\
                              & (0.136)                       &          & (0.198)                       &      \\
Variable 1  & 0.973\sym{*}                       & 0.70     & 1.008\sym{***}                      & 0.99 \\
                              & (0.173)                       &          & (0.907)                       &      \\
Variable 1  & 0.117                         & 0.79     & 1.731\sym{***}                     & 0.08 \\
                              & (0.173)                       &          & (0.990)                       &      \\
Variable 1  & 0.161\sym{**}                       & 0.91     & 1.797\sym{***}                      & 0.11 \\ 
                              & (0.187)                       &          & (0.938)                       &      \\ \midrule
Variable 2   & -0.079                        &          & 3.666\sym{***}                      &      \\
                              & (0.373)                       &          & (0.317)                       &      \\
Variable 2 & -1.191\sym{***}                     & 0.09     & 9.901\sym{***}                      & 0.09 \\
                              & (0.301)                       &          & (0.391)                       &      \\
Variable 2 & -1.100\sym{***}                     & 0.70     & 9.799\sym{***}                      & 0.89 \\
                              & (0.989)                       &          & (0.390)                       &      \\
Variable 2 & -1.131\sym{***}                     & 0.70     & 9.377\sym{***}                      & 0.39 \\
                              & (0.971)                       &          & (0.307)                       &      \\
Variable 2 & -0.167\sym{*}                       & 0.07     & 9.179\sym{***}                      & 0.68 \\
                              & (0.960)                       &          & (0.309)                       &      \\
Variable 2  & -0.699\sym{***}                    & 0.73     & 9.006\sym{***}                      & 0.68 \\
                              & (0.919)                       &          & (0.301)                       &      \\
Variable 2  & -0.316                        & 0.39     & 0.869\sym{***}                      & 0.01 \\
                              & (0.913)                       &          & (0.307)                       &      \\
Variable 2 & -0.911                        & 0.77     & 1.079\sym{***}                      & 0.69 \\
                              & (0.919)                       &          & (0.319)                       &      \\
Variable 2 & -0.131                        & 0.77     & 1.983\sym{***}                      & 0.66 \\
                              & (0.911)                       &          & (0.336)                       &      \\
Variable 2 & 0.019                         & 0.67     & 0.837\sym{**}                       & 0.36 \\
                              & (0.919)                       &          & (0.371)                       &      \\
Variable 2 & -0.007                        & 0.96     & 1.187\sym{***}                     & 0.70 \\
                              & (0.973)                       &          & (0.378)                       &      \\
Variable 2& -0.079                        & 0.81     & 1.031\sym{***}                & 0.78 \\
                              & (0.961)                       &          & (0.399)                       &      \\
Variable 2 & 0.767\sym{***}                      & 0.03     & 1.187\sym{***}                & 0.19 \\
                              & (0.980)                       &          & (0.101)                       &      \\
Variable 2 & 0.791*                        & 0.77     & 1.719\sym{***}              & 0.66 \\
                              & (0.317)                       &          & (0.191)                       &      \\
Variable 2 & 0.371                         & 0.79     & 9.378\sym{***}                & 0.39 \\
                              & (0.373)                       &          & (0.119)                       &      \\
Variable 2 & 0.913\sym{**}                       & 0.96     & 9.110\sym{***}                    & 0.90 \\
                              & (0.386)                       &          & (0.189)                       &      \\ \midrule
Variable 3  & -0.181                        &          & 7.119\sym{***}                     &      \\
                              & (0.781)                       &          & (0.791)                       &      \\
Variable 3 & -1.199\sym{***}                     & 0.09     & 1.173\sym{***}                   & 0.91 \\
                              & (0.196)                       &          & (0.737)                       &      \\
Variable 3 & -1.331\sym{***}                     & 0.81     & 3.737\sym{***}                   & 0.10 \\
                              & (0.167)                       &          & (0.799)                       &      \\
Variable 3 & -1.309\sym{***}                     & 0.96     & 3.176\sym{***}                   & 0.60 \\
                              & (0.117)                       &          & (0.707)                       &      \\
Variable 3  & -0.673                        & 0.99     & 3.977\sym{***}                     & 0.89 \\
                              & (0.198)                       &          & (0.709)                       &      \\
Variable 3  & -0.718\sym{*}                      & 0.91     & 9.119\sym{***}                   & 0.91 \\
                              & (0.108)                       &          & (0.198)                       &      \\
Variable 3  & -0.137                        & 0.69     & 0.901\sym{*}                        & 0.03 \\
                              & (0.100)                       &          & (0.707)                       &      \\
Variable 3  & -0.117                        & 0.61     & 1.179\sym{***}                    & 0.17 \\
                              & (0.101)                       &          & (0.798)                       &      \\
Variable 3 & 0.901                         & 0.71     & 1.387\sym{**}                       & 0.99 \\
                              & (0.106)                       &          & (0.776)                       &      \\
Variable 3 & -0.196                        & 0.77     & 1.919\sym{**}                       & 0.87 \\
                              & (0.101)                       &          & (0.789)                       &      \\
Variable 3 & -0.137                        & 0.98     & 1.979\sym{***}                    & 0.11 \\
                              & (0.196)                       &          & (0.611)                       &      \\
Variable 3 & 0.019                         & 0.77     & 0.706                         & 0.11 \\
                              & (0.111)                       &          & (0.661)                       &      \\
Variable 3 & 1.373\sym{***}                      & 0.01     & 1.906\sym{***}                     & 0.17 \\
                              & (0.189)                       &          & (0.696)                       &      \\
Variable 3 & 0.697                         & 0.36     & 3.390\sym{***}                    & 0.16 \\
                              & (0.717)                       &          & (0.737)                       &      \\
Variable 3 & 0.796                         & 0.91     & 3.897\sym{***}                     & 0.61 \\
                              & (0.633)                       &          & (0.781)                       &      \\
Variable 3 & 1.381\sym{**}                       & 0.73     & 1.317\sym{***}                     & 0.67 \\
                              & (0.697)                       &          & (0.860)                       &      \\ \midrule 
Observations                             & \mc{1,079,9731}                    &          & \mc{1,079,9731}                    &      \\
Mean                          & \mc{8.90}                          &          & \mc{19.37}                         &     \\ \bottomrule
\multicolumn{5}{p{\linewidth}}{\scriptsize \textbf{Notes}: \lipsum[2]}  
\end{longtable}
5
  • Dear Mona, code fragment, from which we should compose a document, which we can compile, is not funy job. Please help us to help you and make complete small document beggining with \documentclass{...} and ending with end{document} and containing only necessary package and your tables (shortened to few rows). For formatting long table are necessary two runs. After second it has final layout (which differ from obtained after first compilation).
    – Zarko
    Feb 16 '17 at 15:39
  • yes seems to be something strange, but tabularx is doing nothing useful for such a table other than make it harder to read. Why do you want to make the first column so unnaturally wide? It would be better just to use a normal longtable and use a =n l column for the first column. Feb 16 '17 at 15:45
  • unrelated to the question but don't use epsfig and ae packages (unless you are writing a document in 1989) Feb 16 '17 at 15:46
  • @Zarko that's more or less what Mona did to be honest. there are a few unneeded packages but it's not so bad, certainly small enough to easily reproduce the effect described. Feb 16 '17 at 15:56
  • Thanks David, I will delete the packages for the future.
    – Mona
    Feb 16 '17 at 16:12
4

The problem is the rows

\multicolumn{5}{p{\linewidth}}{\scriptsize \textbf{Notes}: \lipsum[2]}  

this is too wide (you can not have the inner width be \linewidth as the table needs to add \tabcolsep padding either side. So it is dominating the width of the table and there is no value tabularx can give for the width of the X column that will affect the width of the table.

However tabularx should never be used with a table such as this, as you do not want line breaking in the data cells and you should set the width of the first column either to the natural width of the text (using an l column) or to a width you fix (using p{...}) using tabularx and specifying the first column has to be widened so the whole table spans the page just produces

enter image description here

which is unreadable with the labels in column 1 disconnected from the data they are labelling.

2
  • Hi David, thanks a lot for your answer. I understand the problem and also how to solve it. Instead of using an l column or fixing the width with p{}, is there also a way to adjust the width of the multicolumn you mentioned?
    – Mona
    Feb 16 '17 at 16:11
  • @Mona yes sure p{\dimexpr\linewidth-2\tabcolsep} but the table is still unreadable with the first column so wide:-) Feb 16 '17 at 16:17

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.