53 Comments

  1. Alex

    Thank you for your site, that’s really helpful thing!

    I have a question according to using longtable package.

    How can I fit table with lots of thing?
    For example:

    \documentclass[12pt]{article}
    \usepackage{longtable}
    \begin{document}
    \begin{center}
    \begin{longtable}{|c|c|c|c|}
    \caption{A simple longtable example}\\
    \hline
    \textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
    \hline
    \endfirsthead
    \multicolumn{4}{c}%
    {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
    \hline
    \textbf{First entry} & \textbf{Second entry} & \textbf{Third entry} & \textbf{Fourth entry} \\
    \hline
    \endhead
    \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
    \endfoot
    \hline
    \endlastfoot
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 444444444 444444444444 4444444  44444444444444 44444444444444 444444444 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1111111111111111111111111111111111111 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\ 1 & 2 & 3 & 4 \\
    \end{longtable}
    \end{center}
    \end{document}

    I’m looking forward to your answer!

    • Hi Alex,

      There are limits to what you can fit on a single page, obviously. But using landscape as well as a smaller font size will give you quite a bit more space than in the example you provided.

      \begin{small}
      ...
      \end{small}

      footnotesize, scriptsize and tiny are other options with tiny being the smalles font size.

      Other than that, keeping the column headings short will also be beneficial, but not always satisfying.

      Cheers, Tom.

      • Alex

        That’s not really work. (by using small or footnotesize or etc.) Text still locate on one line…

        I would like to fit text in each cell in table.
        The same things are available in Tabularx with “x” option for adjust; unfortunately, this option doesn’t work here…

      • Hi Alex,

        I see. So if you want to use longtable, replace c with p{length}, e.g.:

        ...
        \begin{longtable}{|p{0.24\textwidth}|p{0.24\textwidth}|p{0.24\textwidth}|p{0.24\textwidth}|}
        ...

        If you prefer tabularx, than here is an example on how to do that:

        \documentclass[12pt]{article}
        \usepackage[landscape]{geometry}
        \usepackage[english]{babel}
        \usepackage{tabularx, blindtext}
        \begin{document}
        \begin{table}
        \centering
        \begin{tabularx}{\textwidth}{|X|X|X|X|}
        \hline
        \textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} \\
        \hline
        a&b&c&\blindtext\\
        a&b&c&d\\
        a&b&c&d\\
        a&b&c&d\\
        \hline
        \end{tabularx}
        \end{table}
        \end{document}

        Good luck!
        Tom

  2. Jose

    Hello, and thanks for this great post. I have a longtable, but this is a long-horizontal table. I need to make it a multi-page table along the horizontal axis rather than the vertical. Any suggestions?

    Thanks for your time.

  3. jessy

    hello,

    Haven’t been able to find an answer anywhere… I have a longtable that would spread out over three pages AND landscape AND the whole article is 2-column article. Simply adding \begin{longtable} and {landscape} wont’ work on the 2-column article. How can I do this?
    Thanks so much!!

    • Hi Jessy,

      You may want to give the supertabular package a try. See an example with two columns here. There is also a link to the package documentation.

      Hope it works!
      Best, Tom.

      • jessy

        Dear Tom,

        Thanks for the suggestion.. but am not getting through this. 🙁

        \begin{center}
        \begin{supertabular}{lccccccccccccl}
               \caption{All candidates}
               \tablehead{1 & 2 & 3 & 4}
               1 & 2 & d & d \\
        %       	\multicolumn{1}{c}{CAND NAME}  &
        %	\multicolumn{1}{c}{RA} &
        %	\multicolumn{1}{c}{Dec} &
        %	\multicolumn{1}{c}{S/N} &
        %	\multicolumn{1}{c}{confirmation} &
        %	\multicolumn{1}{c}{COMMENT} \\
        %	\hline
        %		\input master_table.tex
        \end{supertabular}
        \end{center}

        This is what I have. I cut off many things for testing right now. But now it’s giving me error messages like,

        This is `epsf.tex’ v2.7.3
        )) (/usr/local/texlive/2009/texmf-dist/tex/latex/supertabular/supertabular.sty
        /usr/local/texlive/2009/texmf-dist/tex/latex/supertabular/supertabular.sty:84:
        Too many }’s.
        \@stopfield -&>\color@endgroup \egroup

        l.84 \tablehead{}

        ?

        Any idea??

        Thanks!!
        Jessy

      • Hi Jessy,

        Here is a working example as a starting point. Make sure you have the right number of columns everywhere, in the definition (\begin{supertabular}), tablehead and in the table content. You generally don’t need multicolumn for a single column. Furthermore, tablehead will only be produced after the first page break.

        \documentclass[11pt, two column, landscape]{article}
        \usepackage{supertabular}
        \usepackage{pdflscape}
        \setlength{\columnseprule}{.3pt}
        \begin{document}
        \begin{table}[ht]
        \begin{center}\begin{tiny}
        \tablefirsthead{%
        \hline
        1 & 2 & 3 & 4 & 5 & 6\\
        \hline}
        \begin{supertabular}{|cccccc|}
        CAND NAME & RA & Dec &S/N & confirmation & COMMENT \\
        \hline
        \end{supertabular}
        \caption{All candidates}
        \end{tiny}\end{center}
        \end{table}
        \end{document}

        Best, Tom.

  4. jessy

    Dear Tom,

    Thanks for the detail instruction… however, I am not getting it through.. I still get the same error message. The error message same as my previous posting…

    Maybe something is wrong with my latex?

    🙁

    Thanks,
    Jessy

    • Hi Jessy,

      Have you tried running the code I posted?
      If that doesn’t work, you may want to update your version of LaTeX to the latest distribution and try again…

      Good luck! Tom.

      • jessy

        Hi Tom,

        Yes I literally copied and pasted your example on my existing latex document and it didn’t work. So I made a test file with your instruction in it and it works. So I have narrowed it down where the trouble is.. it’s the document class that I am using. emulateapj. Heard of it? probably not.. it’s really specific document class that we have to use in Astronomy.

        Well, the problem is still there, but I got to nail down where the trouble is. Thank you so much for helping me out. 🙂

        Jessy

      • Hi Jessy,

        Nope, haven’t heard of that documentclass. Hope you were able to fix the issue in the meantime. Best, Tom.

  5. saifulkhan

    Hi Tom,

    I need longtable as the table is big which spans through multiple pages. Also I have lots of column with long text. e.g. the below code actually goes out of the boundary, as the width of the text is is big, i expect the width to reduce and length of such cell to increse, in this situation.

    \begin{longtable}{|p{0.24\textwidth}|p{0.24\textwidth}|p{0.24\textwidth}|p{0.24\textwidth}|}
    \hline
    A very looooooooong text is here...............................!&A very loooooog is also here!&C&C\\
    \hline
    \end{longtable}
    • Hi!

      There is more than enough space for the cells above in landscape. You are using a fixed cell width, so LaTeX automatically adds linebreaks. Here is an example with a dynamic cell width. To keep the table width within the margins, reduce the font size, e.g. footnotesize, and/or use fixed cell width as you did in your previous example.

      \documentclass[11pt]{article}
      \usepackage{longtable, lscape}
      \begin{document}
      \begin{landscape}
      \begin{longtable}{lll}
      \hline
      A very looooooooong text is here………………………….! & A very loooooog is also here ! & C \\
      A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\
      A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\
      A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\
      A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\
      A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\A&A&A\\
      \hline
      \end{longtable}
      \end{landscape}
      \end{document}

      Btw, to reduce your typing effort, just repeat the column type as follows:

      \begin{longtable}{*{3}{|p{0.24\textwidth}}|}

      Best, Tom.

  6. saifulkhan

    Hi Tom,

    Could you please tell me how can I achieve the following?

    1. The size of the columns of the longtable is different and I want to explicitly different.
    2. What is the syntax to reduce the font size of the text of the table?

    Thank you very much.

    • Hey Saifulkhan,

      1. Just use the basic l, c, or r column type for dynamic column width.
      2. Enclose longtable with an environment that sets a different font size, e.g.

      \begin{footnotesize}
      \begin{longtable}
      ...
      \end{longtable}
      \end{footnotesize}

      List of available font sizes.

      Best, Tom.

  7. Azita

    Hi. This is my first post here.

    In my dissertation I have a long wide table. Table does not fit in lscape or sideways and I have to split a long table in several adjacent pages. I mean
    splitting both length wise and width wise.
    I was through web sites for hours and couldn’t find anything. Not sure if I have looked everywhere. So would be extremely grateful for suggestions or refers to other links.
    P.S. my table needs a two line caption as well.

    Many thanks
    Azi

    • Hi Azita,

      What you need is not easy. One possible solution I can think of is changing the page size for your table. This obviously makes it hard to print the document.

      Other than that, I found this similar question with two possible solutions. You may want to give it a try.

      Good luck,
      Tom.

  8. sarvesh

    Dear Sir, I want to display this as a column heading for my table:

    Scene
    ______
    Indoor(I)
    Outdoor(O)

    i mean Scene underline by two options Indoor(I) and Outdoor(O)
    Please suggest me appropriate command for that particular type of things.

    with regards
    sarvesh

    • How about using a tabular environment inside the table cell?

      \documentclass[11pt]{article}
      \begin{document}
      \begin{table}[ht]
      \caption{default}
      \begin{center}
      \begin{tabular}{|l|c|}
      \hline
       & \begin{tabular}{l}Scene\\\hline Outdoor (O)\\Indoor (I)\end{tabular}\\
      \hline
      First &O\\
      Second&I\\
      \hline
      \end{tabular}
      \end{center}
      \label{default}
      \end{table}%
      \end{document}

      Cheers, Tom.

  9. chandaniitd

    I have a table split over three sub tables. Two of the table fit in the page, third one exceeds the page. Below is my code:

    \begin{table}[t]
    	\centering
    	\caption{Coulombic Parameters, Equation 2}
    	\label{table:cou}
    	\begin{tabular}{    |c | c |c |c  |c |c  | c |}
    	\hline
    	Atom No. ( \ref{fig:PEI-structure}) &\multicolumn{1}{c|}{Atom name}&\multicolumn{1}{c|}{Atom type}&\multicolumn{1}{c|}{Charge, $q_i$}\\\hline\hline
    	1 & N & amber99$\_$38 (N2) & - 0.740\\\hline
    	2, 3 & H1, H2 & amber99$\_$17 (H) & 0.250\\	\hline
    	4 & CA & amber99$\_$11 (CT) & - 0.140\\\hline
    	5, 6, 8, 9 & HA1, HA2, HB1, HB2 & amber99$\_$19 (H1) & 0.115\\\hline
    	7 & CB & amber99$\_$11 (CT) & -0.080 \\\hline\hline
    	10 & N & amber99$\_$81 (NT) & -0.593 \\\hline
    	11,  & H & amber99$\_$17 (H) & 0.269\\	\hline
    	12, 15 & CA, CB & amber99$\_$11 (CT) & - 0.086\\\hline
    	13, 14, 16, 17 &HA1, HA2, HB1, HB2 & amber99$\_$19 (H1) & 0.124\\\hline\hline
    	18 & N & amber99$\_$81 (NT) & -0.500 \\\hline
    	19,  & H & amber99$\_$17 (H) & 0.280\\	\hline
    	20 & CA & amber99$\_$11 (CT) & - 0.081\\\hline
    	21, 22 &HA1, HA2 & amber99$\_$19 (H1) & 0.125\\\hline
    	23 & CB & amber99$\_$11 (CT) & - 0.300\\\hline
    	24, 25, 26 & HB1, HB2, HB3 & amber99$\_$18 (HC) & 0.117\\\hline
    	\end{tabular}
    	\vskip 1cm
    	\begin{tabular}{    |c | c |c |c  |c |c  | c |}
    	\hline
    	Atom No. ( \ref{fig:PEI-structure}) &\multicolumn{1}{c|}{Atom name}&\multicolumn{1}{c|}{Atom type}&\multicolumn{1}{c|}{Charge, $q_i$}\\\hline\hline
    	1 & N & amber99$\_$81 (NT) & - 0.417\\\hline
    	2, 3, 4 & H1, H2, H3 & amber99$\_$17 (H) & 0.36\\	\hline
    	5 & CA & amber99$\_$11 (CT) &  0.056\\\hline
    	6, 7 & HA1, HA2 & amber99$\_$19 (H1) & 0.087\\\hline
    	8 & CB & amber99$\_$11 (CT) & -0.147 \\\hline
    	9, 10 & HB1, HB2 & amber99$\_$19 (H1) & 0.127\\\hline\hline
    	11 & N & amber99$\_$81 (NT) & -0.150 \\\hline
    	12, 13  & H1, H2 & amber99$\_$17 (H) & 0.340\\	\hline
    	14, 17 & CA, CB & amber99$\_$11 (CT) & - 0.023\\\hline
    	15, 16, 18, 19 &HA1, HA2, HB1, HB2 & amber99$\_$19 (H1) & 0.129\\\hline\hline
    	20 & N & amber99$\_$81 (NT) & -0.135 \\\hline
    	21, 22  & H1, H2 & amber99$\_$17 (H) & 0.331\\	\hline
    	23 & CA & amber99$\_$11 (CT) & - 0.067\\\hline
    	24, 25 &HA1, HA2 & amber99$\_$19 (H1) & 0.120\\\hline
    	26 & CB & amber99$\_$11 (CT) & - 0.314\\\hline
    	27, 28, 29 & HB1, HB2, HB3 & amber99$\_$18 (HC) & 0.160\\\hline
    	\end{tabular}
    		\vskip 1 cm
    		\clearpage
    	\begin{tabular}{    |c | c |c |c  |c |c  | c |}
    	\hline
    	Atom No. ( \ref{fig:PEI-structure}) &\multicolumn{1}{c|}{Atom name}&\multicolumn{1}{c|}{Atom type}&\multicolumn{1}{c|}{Charge, $q_i$}\\\hline\hline
    	1 & N & amber99$\_$81 (NT) & - 0.417\\\hline
    	2, 3, 4 & H1, H2, H3 & amber99$\_$17 (H) & 0.36\\	\hline
    	5 & CA & amber99$\_$11 (CT) &  0.056\\\hline
    	6, 7 & HA1, HA2 & amber99$\_$19 (H1) & 0.087\\\hline
    	8 & CB & amber99$\_$11 (CT) & -0.147 \\\hline
    	9, 10 & HB1, HB2 & amber99$\_$19 (H1) & 0.127\\\hline\hline
    	11 & N & amber99$\_$81 (NT) & -0.150 \\\hline
    	12, 13  & H1, H2 & amber99$\_$17 (H) & 0.340\\	\hline
    	14, 17 & CA, CB & amber99$\_$11 (CT) & - 0.023\\\hline
    	15, 16, 18, 19 &HA1, HA2, HB1, HB2 & amber99$\_$19 (H1) & 0.129\\\hline\hline
    	20 & N & amber99$\_$81 (NT) & -0.135 \\\hline
    	21, 22  & H1, H2 & amber99$\_$17 (H) & 0.331\\	\hline
    	23 & CA & amber99$\_$11 (CT) & - 0.067\\\hline
    	24, 25 &HA1, HA2 & amber99$\_$19 (H1) & 0.120\\\hline
    	26 & CB & amber99$\_$11 (CT) & - 0.314\\\hline
    	27, 28, 29 & HB1, HB2, HB3 & amber99$\_$18 (HC) & 0.160\\\hline
    	\end{tabular}
    \end{table}
    \end{document}
    • You may want to try using 3 floating environments.

      Best, Tom.

      \begin{table}[ht]
      ...
      \end{table}
      \begin{table}[ht]
      ...
      \end{table}
      \begin{table}[ht]
      ...
      \end{table}
      • I have done the same thing. But this gives me different table nos viz., table 1, table 2 ….. Not as subtable 1(a), 1(b), 1(c). How can this be done. Kindly help.

      • Ok, I see. In that case, you could use the subfig package and split the table manually using the \ContinuedFloat command.

        You may also find this post on subfig helpful.

        Good luck! Tom.

        \documentclass{article}
        \usepackage{subfig}
        \begin{document}
        \begin{table}[t]
        	\centering
        	\caption{global caption}\label{tab:global}
        	\subfloat[caption1]{%
        		\begin{tabular}{c}
        		...
        		\end{tabular}
        	}
        
        	\subfloat[caption2]{%
        		\begin{tabular}{c}
        		...
        		\end{tabular}
        	}
        \end{table}
        %\clearpage
        \begin{table}
        	\centering
        	\ContinuedFloat
        	\subfloat[caption3]{%
        		\begin{tabular}{c}
        		...
        		\end{tabular}
        	}
        \end{table}
        \end{document}
  10. maxweberko

    Hi Tom,

    I am new to LaTeX and almost self-taught to learn it.
    Here is my question: I would like to use the package{longtable} to make a table spanned on two pages. Trying to use the codes below did not work. Please let me know what’s wrong with the codes.

    One more thing, I still don’t know where to insert the codes for the text “continued till next page” in the codes. Shall I insert the codes before {tabular}?

    Thank you so much!

    Best,
    Maxweberko

    %%%%%%%%%%%%Background %%%%%%%%%%%%%%
     
    \documentclass[a4paper, 12pt]{scrartcl}
    \usepackage{longtable}
    \usepackage{amsmath}
    \usepackage{booktabs}
    \usepackage{array}
    \usepackage{threeparttable}
    \usepackage{lscape}
    \usepackage{multirow}
    \usepackage{pdflscape}
    %other unrelated packages not shown %
     
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    \begin{document}
     
    \begin{center}
    \begin{longtable}{lccc}\small
    \caption{LONG TABLE}
    \begin{tabular}{lccc} \toprule
      & Model 1& Model 2& Model 3 \\
    Variables & Coeff. (Std. Err.) & Coeff. (Std. Err.) & Coeff. (Std. Err) \\\hline
    Female &  &1.37*** (0.10)& 1.37*** (0.10) \\
    Age groups & & & \\
    \ 20-30 (ref.) &  &0.00 (0.00) &0.00 (0.00) \\
    \ 30-40 &  & -0.02(0.13)&-0.05 (0.13) \\
    \ 40-50 &  &-0.40*(0.18)&-0.47** (0.18) \\
    \ \textgreater 80 &  &-0.13 (0.31) & -0.18 (0.31) \\
    Education levels &&&\\
    \ Capable of reading &  & -0.15(0.15)& -0.08 (0.16) \\
    \ Elementary school & & -0.90*** (0.16)&-0.84*** (0.16) \\
    \ Higher than middle school & &-1.91***(0.16)& -1.74*** (0.17) \\
    Have a job & &-0.75*** (0.13)&-1.01*** (0.13) \\
    Home ownership: yes &  &0.04 (0.17)&0.03 (0.17) \\
    Married & & -1.39 (0.18) &1.44*** (0.18) \\
    No. of family members & & &\\
    \ 0 (ref.) & & 0.00(0.00)&0.00 (0.00) \\
    \ 1-3& &0.41**(0.12)&0.40*** (0.12) \\
    \ \textgreater 4 & & 0.12 (0.17)&0.05 (0.17) \\
    Family size & &-0.06 (0.03)&-0.06 (0.03) \\
    Did social activity & &0.99***(0.11)& 0.93*** (0.11) \\
    Any disease & &2.15***(0.11)& 2.16*** (0.12) \\
    No. of computers & & &\\
    \ 0 (ref.) & &0.00 (0.00)&0.00 (0.00) \\
    \ 1 & &-0.83***(0.16)&-0.58*** (0.16) \\
    \ \textgreater 2 & & -1.56*** (0.25)& -1.26*** (0.25) \\
    Urban &&& -0.49 (0.29) \\
    Solar power: yes &&& -1.12*** (0.29) \\
    \% of departments &&& \\
    \ 0 (ref.)&&& 0.00 (0.00) \\
    \ 1\% - 4.9\% &&&  -0.38 (0.30) \\
    \ \textgreater 4.9 \% &&& 0.12 (0.28) \\
    \% of University degree &&&\\
    \ 0 (ref.) &&& 0.00 (0.00) \\
    \ 10\%- 20\% &&& -0.07 (0.26) \\
    \ \textgreater 20\% &&& -0.93*** (0.28) \\
    \% of community centers  &&& \\
    \ 0 -10 \%(ref.) &&&0.00 (0.00) \\
    \ 10 -20\% &&& -0.35 (0.28) \\
    \ \textgreater 20\% &&& -1.01** (0.31) \\
    Benefits (yes) &&&-0.68** (0.24) \\
    Constant &8.59*** (0.13)& 9.07***(0.38)& 10.71***  (0.46) \\
    $\sigma^2_{vu}$& 11.23 & 10.44& 10.63  \\
    $\sigma^2_{u}$ & 5.42 & 4.14 & 2.81  \\
    $\rho_{vu}$ &0.40&0.40& 0.38  \\
    $\rho_{u}$ &0.13 &0.11 & 0.08  \\
    Respondents & 20000 & 20000 & 20000  \\
    Communities &449 &449 &434 \\\bottomrule
    \multicolumn{3}{l}{ * p$<$0.05, ** p$<$0.01, *** p$<$0.001 } \\
    \end{tabular}
    \end{center}
    \end{longtable}
     
    \end{document}
    • tom

      Hi there!

      Thanks for the code, that made it easy to fix. You almost got it right. Just a few fixes:

      • You closed the center and longtable environments the wrong way round.
      • The longtable environment replaces tabular and not table. Table is a floating environment which only makes sense for content that spans less than a page.
      • I also properly defined what’s to be placed above and below the table (endfirsthead, endhead, endfoot, endlastfoot). Change it according to your needs.
      • I’d recommend aligning the data columns right
      • Added \begin{landscape}...\end{landscape} to rotate the page

      You can find the updated code below.

      Nice table by the way! Cheers, Tom

      \documentclass[a4paper, 12pt]{scrartcl}
      \usepackage{longtable}
      \usepackage{booktabs}
      \usepackage{array}
      \usepackage{threeparttable}
      \usepackage{multirow}
      \usepackage{pdflscape}
        
      \begin{document}
      \begin{landscape}
      \begin{center}
      
      \begin{longtable}{lrrr}
      \caption{\small LONG TABLE}\\
      \toprule
        & Model 1& Model 2& Model 3 \\
      Variables & Coeff. (Std. Err.) & Coeff. (Std. Err.) & Coeff. (Std. Err) \\
      \hline
      \endfirsthead
      \multicolumn{4}{c}{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
      \hline
        & Model 1& Model 2& Model 3 \\
      Variables & Coeff. (Std. Err.) & Coeff. (Std. Err.) & Coeff. (Std. Err) \\
      \hline
      \endhead
      \hline \multicolumn{4}{r}{\textit{Continued on next page}} \\
      \endfoot
      \bottomrule
      \multicolumn{4}{l}{ * p\textless 0.05, ** p\textless 0.01, *** p\textless 0.001 } \\
      \endlastfoot
      Female &  &1.37*** (0.10)& 1.37*** (0.10) \\
      Age groups & & & \\
      \ 20-30 (ref.) &  &0.00 (0.00) &0.00 (0.00) \\
      \ 30-40 &  & -0.02(0.13)&-0.05 (0.13) \\
      \ 40-50 &  &-0.40*(0.18)&-0.47** (0.18) \\
      \ \textgreater 80 &  &-0.13 (0.31) & -0.18 (0.31) \\
      Education levels &&&\\
      \ Capable of reading &  & -0.15(0.15)& -0.08 (0.16) \\
      \ Elementary school & & -0.90*** (0.16)&-0.84*** (0.16) \\
      \ Higher than middle school & &-1.91***(0.16)& -1.74*** (0.17) \\
      Have a job & &-0.75*** (0.13)&-1.01*** (0.13) \\
      Home ownership: yes &  &0.04 (0.17)&0.03 (0.17) \\
      Married & & -1.39 (0.18) &1.44*** (0.18) \\
      No. of family members & & &\\
      \ 0 (ref.) & & 0.00(0.00)&0.00 (0.00) \\
      \ 1-3& &0.41**(0.12)&0.40*** (0.12) \\
      \ \textgreater 4 & & 0.12 (0.17)&0.05 (0.17) \\
      Family size & &-0.06 (0.03)&-0.06 (0.03) \\
      Did social activity & &0.99***(0.11)& 0.93*** (0.11) \\
      Any disease & &2.15***(0.11)& 2.16*** (0.12) \\
      No. of computers & & &\\
      \ 0 (ref.) & &0.00 (0.00)&0.00 (0.00) \\
      \ 1 & &-0.83***(0.16)&-0.58*** (0.16) \\
      \ \textgreater 2 & & -1.56*** (0.25)& -1.26*** (0.25) \\
      Urban &&& -0.49 (0.29) \\
      Solar power: yes &&& -1.12*** (0.29) \\
      \% of departments &&& \\
      \ 0 (ref.)&&& 0.00 (0.00) \\
      \ 1\% - 4.9\% &&&  -0.38 (0.30) \\
      \ \textgreater 4.9 \% &&& 0.12 (0.28) \\
      \% of University degree &&&\\
      \ 0 (ref.) &&& 0.00 (0.00) \\
      \ 10\%- 20\% &&& -0.07 (0.26) \\
      \ \textgreater 20\% &&& -0.93*** (0.28) \\
      \% of community centers  &&& \\
      \ 0 -10 \%(ref.) &&&0.00 (0.00) \\
      \ 10 -20\% &&& -0.35 (0.28) \\
      \ \textgreater 20\% &&& -1.01** (0.31) \\
      Benefits (yes) &&&-0.68** (0.24) \\
      Constant &8.59*** (0.13)& 9.07***(0.38)& 10.71***  (0.46) \\
      $\sigma^2_{vu}$& 11.23 & 10.44& 10.63  \\
      $\sigma^2_{u}$ & 5.42 & 4.14 & 2.81  \\
      $\rho_{vu}$ &0.40&0.40& 0.38  \\
      $\rho_{u}$ &0.13 &0.11 & 0.08  \\
      Respondents & 20000 & 20000 & 20000  \\
      Communities &449 &449 &434 \\
      \end{longtable}
      \end{center}
      \end{landscape}
      \end{document}
      • maxweberko

        Hi Tom,
        Thank you so much for the fixes! I am so happy to see that table spanned on two pages.
        I will follow the codes you provided and add some columns in order to make them match the statistics. If I have further questions, I will post them here.
        Have a nice day!

  11. Sorry about the last post, I think it’s not clear.
    What I meant is that: is it possible to make something like a box around the text is such a way that it will automatically break to the next page. Just like in this example: https://www.dropbox.com/s/16anlu5thx8431n/tabela_exemplo.jpg

    when you type the text and there is no more space, it automatically break to next page, splitting the table, and filling the pages.

    I’d be really grateful for your help. Thanks a lot.
    Jefferson

    • tom

      Thanks for your comment, an interesting question!

      I suggest using the mdframed package. Below is a minimal example that creates roughly the output in the picture.

      \documentclass{article}
      
      \usepackage[everyline=true]{mdframed}
      \usepackage{blindtext, xcolor}
      
      \mdfdefinestyle{mystyle}{frametitlebackgroundcolor=black!10!white,
      frametitlerule=true, frametitlerulewidth=1pt, linewidth=1pt}
      
      \begin{document}
      \begin{mdframed}[style=mystyle,frametitle={Some frame title}]
      \Blindtext
      \end{mdframed}
      \end{document}
  12. kishore

    Hey Tom

    In longtable definition line below, what does @{} mean?

    \begin{longtable}[c][/c]{@{} l l l @{}}

    Thanks

    K

  13. Mary

    Hello Tom,
    well hoestly I am not sure if my question fits in here, but you seem to know the things about big tables…
    I need a table with 64 columns to fit in one text row.
    (The columns don’t include s.th. – I need to color them in different colors in the end.)
    I already tried with variable cells and \footnotesize’ing the table but it seems that the size never change and at most about 30 columns are shown…
    What can I do?!?

    • tom

      Hi Mary,

      Thanks for your question.
      I would be useful if you provided a minimal example. Could you post the code that you have for just a few columns. I will then try to propose a solution for 64 columns if possible.

      Best, Tom.

    • tom

      Would this be what you are looking for?

      \documentclass[11pt]{article}
      \usepackage{array}
      \begin{document}
      \begin{table}[ht]
      \setlength\tabcolsep{2pt}
      \caption{default}
      \begin{center}
      \begin{tabular}{|*{64}{c|}}
      \hline
      &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
      \hline
      &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\\
      \hline
      \end{tabular}
      \end{center}
      \label{default}
      \end{table}%
      \end{document}
      • Mary

        Woow yes that is exactly what I was looking for! Thank you very much!
        This made my day =)

  14. hayat khan

    Dear Sir,

    I have 7 columns , I want that Data may be wrap, is there any option in longtable. I will adjust column for complete page

    • Hi Hayat,

      You can use the array package to define cell width for every column as a fraction of linewidth. Please provide an example and some more details on the problem and I will be happy to look into it and make a suggestion.

      Best, Tom

  15. Alfonso Saera

    Hi Tom,

    I am trying to fit a very long table in landscape mode in several pages. I think I need to run the code through LaTeX several times, as you and the manual say, but I have no idea how to do this.

    This is an automatic report so I have a python script that creates the tex file with the required text and the compiles it like xelatex –interaction=nonstopmode report.tex”.

    Any help would be very appreciated.

    Thanks!

    • Hi Alfonso,

      Thanks for your question. Can you repeat the line which compiles the code in your python script multiple times or use a loop?

      Best, Tom

Leave a Reply