Graphics, Figures & Tableslongtable | Creating a Table with Page Breaks

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
microman
Posts: 1
Joined: Thu Jul 12, 2012 10:55 am

longtable | Creating a Table with Page Breaks

Post by microman »

Hi there,

I have a big table that does not fit in one page. I used longtable package in order to make it roll to other pages. However, it seems that it is not working and all of my table contents appear in one page and it is violating the margins. I am putting the code here.

Code: Select all

\begin{table}
\begin{footnotesize}
\begin{center}
\begin{longtable}{| p{2.2cm} || p{1cm} p{1cm} p{4cm} | p{0.9cm} p{1.1cm} p{1.1cm} p{1.1cm} 	|}
\caption{Variables of social capacities\label{tab:capacity}} \\
\hline \hline 
\multicolumn{4}{|c}{ } & \multicolumn{4}{|c|}{ASSUMED Relationship with costs} \\ \hline
Variables & Adaptive capacity & Coping Capacity & Indicators/proxies & Direct Tang. & Direct Intang. & Indirect Tang. &  Indirect Intang. \\ \hline \endfirsthead

\hline \hline
\multicolumn{4}{|c}{ } & \multicolumn{4}{|c|}{ASSUMED Relationship with costs} \\ \hline
Variables & Adaptive capacity & Coping Capacity & Indicators/proxies & Direct Tang. & Direct Intang. & Indirect Tang. &  Indirect Intang. \\ \hline
 \endhead

\hline \multicolumn{8}{|r|}{{Continued on next page}} \\ \hline
\endfoot

\hline \hline
\endlastfoot

\textbf{Age} & & X &  Percent of population under five years old; Percent of population over 65 years; Median age; & &  & + & + \\
\textbf{Gender} &   & X  & Percent of females; Percent of female headed households; & & + & + & \\
\textbf{Family structure} &  &  X  & Percent of single parents households; Percent of households with more than 4 individuals; & & + & & + \\
\textbf{Disabled} &  X  & X  & Percent residents in nursing homes; Percent ill or disabled residents; & & + & & +\\
\textbf{Income level}  & X  &  X  & Per capita income; Median monetary value of owner-occupied housing; Median rent for renter-occupied housing units; Credit rating of inhabitants" & + & & + & \\
\textbf{Social disparity} & X  & X  & Gini index of income; Percent of households earning more than X; Percent of households earning les than Y; Dependents on social services & + & + & & \\
\textbf{Education }&  X  &  & Negative of percent of population 25 years or older with no high school diploma; Percent of population with higher education; & & & & \\
\textbf{Employment} &  X  & & Percent of civilian labour force unemployed; Type of employment (full time, part time, self employed, etc) & & & & \\
\textbf{Safety network} &   & X  & Negative of quality of relationships within the community; Percent of isolated population; Percent population change; Negative of percent with 1st to 2nd level connections to civil protection; & & + & & +\\
\textbf{Trust} &  & X  & experts elicitation / measure of trust & + &  &  & - \\
\textbf{Risk perception} & X  & X  & experts elicitation /  measure of perception & & & & \\
\textbf{Risk governance }& X  & X  & Per capita number of community  hospitals; Per capita number of physicians;  Local gov. debt to revenue ratio;  Access to places (number) of safety during the event; Number of red cross volunteers; Hours spent on training and manoeuvre  & - & - & - & - \\
\textbf{Early warning capacity} & X  & X  & Number of early warning systems in place for typology of hazard;  & - & - & - & - \\
\textbf{Risk spreading} & X  & X  & \% of hazard insured households;  \% of hazard insured economic activities; & -  &   &   &  \\
\textbf{Economic diversification} & X  &X  & Normalised Herfindahl index of sectoral (i.e. coarse: primary, secondary, tertiary) contribution to GDP and or to employment;    & +    &  +    &  &  \\
\textbf{Interconnectivity of economy} & X  &X  & Net trade in goods and services (exports +); Percent of resident that travel to work outside the modelled area;   & -   &    & +  & + \\
\textbf{New comers} &  & X  & Percent renter-occupied  housing units; Percent of recent residents/immigrants; Percent of people living in informal houses; &  -  & +  &   & + \\
\end{longtable}
\end{center}
\end{footnotesize}
\end{table}
I followed the example of this page

http://users.sdsc.edu/~ssmallen/latex/longtable.html

and the example perfectly works. At this moment I am not able to find what is the reason that it is not working for my table. Any help is appreciated.


Cheers,
Vahid
Last edited by localghost on Thu Jul 12, 2012 11:08 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

GerlofVito
Posts: 27
Joined: Wed May 16, 2012 8:24 pm

longtable | Creating a Table with Page Breaks

Post by GerlofVito »

First, when you post code, it's best to post all the code that someone needs to typeset the document. So in your case, I added at the top:

Code: Select all

\documentclass{article}
\usepackage{longtable}
\begin{document}
And I added at the bottom:

Code: Select all

\end{document}
Okay, now on to your question: You need to get rid of the \begin{table} and \end{table} lines. When you wrap longtable in a regular table, it prevents longtable from making the page breaks.

As far as intruding into the margins, that's because you're manually setting the width of all the table columns, and the sum of those widths (the table width) is larger than the width of the text block. I personally like the tabu package, which you can also use with longtable, because you can use it to specify a total table width and let it automatically set column widths to arrive at that width.

I put your table in a longtabu (attached). But basically your table has a lot of width just based on the text that's in it. So you'll need to manually go in and set some line breaks and maybe think about how to take out some of the text that's increasing the width of the table.

Alternatively, you could make it a landscape table: Use the lscape package and enclose the table in the landscape environment:

Code: Select all

\begin{landscape}
    Your table
\end{landscape}
Attachments
longtabu.pdf
Your table in a longtabu
(15.37 KiB) Downloaded 924 times
longtabu.tex
Your table in a longtabu
(3.78 KiB) Downloaded 1063 times
Post Reply