2

I have some data I have put in Latex in order to make a table for a report. The table would extend over two pages but my longtable code seems not to make it to the second page. The code I am using is essentially the one mentioned on this page(http://texblog.org/2011/05/15/multi-page-tables-using-longtable/) but with my data and columns instead. I have six columns. Hopefully some one can spot a silly error here. Thanks!

\documentclass[12pt]{article}
\usepackage{longtable}
\begin{document}
\begin{center}
\begin{longtable}{cccccc}
\caption{A simple longtable example}\\
\hline
\textbf{name} & \textbf{val1} & \textbf{val2} & \textbf{val3} & \textbf{val4} & \textbf{val5}\\
\hline
\endfirsthead
\multicolumn{6}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{name} & \textbf{val1} & \textbf{val2} & \textbf{val3} & \textbf{val4} & \textbf{val5}\\
\hline
\endhead
\hline \multicolumn{6}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
a_01 & 6.75 & 30.75 & 2.75 & -20.75 & 0.05 \\
a_02 & 5.51 & 12.01 & 1.51 & -4.99 & 0.06 \\
b_02 & 11.99 & 50.99 & -0.51 & -60.01 & 0.06 \\
b_01 & 10.49 & 27.99 & 1.99 & -16.01 & 0.03 \\
c_02 & 10.50 & 18.00 & 3.00& -6.49& 0.16 \\
d_01 & 6.73 & 39.73 & -2.26 & -37.26 & 0.08 \\
d_02 & 5.740 & 42.24 & -1.75 & -55.75 & 0.05 \\
d_03 & 7.00 & 58.50 & -1.49 & -60.99 & 0.03 \\
d_04 & 5.73 & 13.73 & 1.73 & -5.26 & 0.03 \\
d_05 & 11.2 & 19.23 & 2.23 & -8.76 & 0.02 \\
d_06 & 10.00 & 33.50 & 0.50 & -34.49 & 0.09 \\
d_07 & 9.23 & 20.73 & 2.23 & -8.76 & 0.07 \\
d_08 & 11.50 & 24.00 & 3.00 & -17.99 & 0.02 \\
d_10 & 10.23 & 32.23 & 2.73 & -20.76 & 0.055 \\
d_13 & 9.23 & 22.73 & -0.76 & -8.76 & 0.05 \\
d_14 & 8.50 & 23.50 & 3.50 & -9.99 & 0.031 \\
d_15 & 8.23 & 28.23 & -0.26 & -26.76 & 0.07\\
d_16 & 8.73 & 25.23 & 3.23 & -7.76 & 0.047 \\
d_19 & 8.73 & 16.23 & 1.24 & -5.76 & 0.07 \\
d_20 & 10.74 & 49.24 & 4.24 & -15.25 & 0.07 \\
d_21 & 9.73 & 38.74 & 4.23 & -19.26 & 0.06 \\
d_22 & 10.24 & 19.74 & 5.24 & -0.25 & 0.03 \\
e_02 & 7.49 & 12.49 & 3.49  & -4.00 & 0.08 \\
f_02 & 7.49 & 12.49 & 3.49 & -4.00 & 0.08 \\
f_03 & 7.99 & 16.49 & 3.49 & -1.00 & 0.03 \\
f_04 & 7.00 & 19.50 & 4.50 & -4.99 & 0.03 \\
f_05 & 6.99 & 14.49 & 3.99 & -4.00 & 0.040 \\
f_06 & 7.50 & 17.00 & 4.50 & -4.49 & 0.027 \\
f_09 & 7.26 & 12.26 & 3.76 & -1.73 & 0.03 \\


\end{longtable}
\end{center}
\end{document}
1
  • 4
    Replace all the _ with \_. Commented Apr 19, 2014 at 12:56

1 Answer 1

2

In addition to fixing the problem with underscores pointed out by Ulrike Fischer, you might want to tidy up the layout and alignment a little. The following uses booktabs to improve the spacing and rules and dcolumn to align the columns on the decimal point. I also use \centering rather than the center environment to avoid creating additional spacing since longtable already uses spacing of its own.

\documentclass[12pt]{article}
\usepackage{dcolumn,longtable,booktabs}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\begin{document}

{\centering% don't add extra space since the longtable environment will already add its own space
\begin{longtable}{cd{3}*{3}{d{2}}d{3}}
\caption{A simple longtable example}\\
\toprule
\textbf{name} & \multicolumn{1}{c}{\textbf{val1}} & \multicolumn{1}{c}{\textbf{val2}} & \multicolumn{1}{c}{\textbf{val3}} & \multicolumn{1}{c}{\textbf{val4}} & \multicolumn{1}{c}{\textbf{val5}}\\
\midrule
\endfirsthead
\multicolumn{6}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\toprule
\textbf{name} & \multicolumn{1}{c}{\textbf{val1}} & \multicolumn{1}{c}{\textbf{val2}} & \multicolumn{1}{c}{\textbf{val3}} & \multicolumn{1}{c}{\textbf{val4}} & \multicolumn{1}{c}{\textbf{val5}}\\
\midrule
\endhead
\bottomrule \multicolumn{6}{r}{\textit{Continued on next page}} \\
\endfoot
\bottomrule
\endlastfoot
a\_01 & 6.75 & 30.75 & 2.75 & -20.75 & 0.05 \\
a\_02 & 5.51 & 12.01 & 1.51 & -4.99 & 0.06 \\
b\_02 & 11.99 & 50.99 & -0.51 & -60.01 & 0.06 \\
b\_01 & 10.49 & 27.99 & 1.99 & -16.01 & 0.03 \\
c\_02 & 10.50 & 18.00 & 3.00& -6.49& 0.16 \\
d\_01 & 6.73 & 39.73 & -2.26 & -37.26 & 0.08 \\
d\_02 & 5.740 & 42.24 & -1.75 & -55.75 & 0.05 \\
d\_03 & 7.00 & 58.50 & -1.49 & -60.99 & 0.03 \\
d\_04 & 5.73 & 13.73 & 1.73 & -5.26 & 0.03 \\
d\_05 & 11.2 & 19.23 & 2.23 & -8.76 & 0.02 \\
d\_06 & 10.00 & 33.50 & 0.50 & -34.49 & 0.09 \\
d\_07 & 9.23 & 20.73 & 2.23 & -8.76 & 0.07 \\
d\_08 & 11.50 & 24.00 & 3.00 & -17.99 & 0.02 \\
d\_10 & 10.23 & 32.23 & 2.73 & -20.76 & 0.055 \\
d\_13 & 9.23 & 22.73 & -0.76 & -8.76 & 0.05 \\
d\_14 & 8.50 & 23.50 & 3.50 & -9.99 & 0.031 \\
d\_15 & 8.23 & 28.23 & -0.26 & -26.76 & 0.07\\
d\_16 & 8.73 & 25.23 & 3.23 & -7.76 & 0.047 \\
d\_19 & 8.73 & 16.23 & 1.24 & -5.76 & 0.07 \\
d\_20 & 10.74 & 49.24 & 4.24 & -15.25 & 0.07 \\
d\_21 & 9.73 & 38.74 & 4.23 & -19.26 & 0.06 \\
d\_22 & 10.24 & 19.74 & 5.24 & -0.25 & 0.03 \\
e\_02 & 7.49 & 12.49 & 3.49  & -4.00 & 0.08 \\
f\_02 & 7.49 & 12.49 & 3.49 & -4.00 & 0.08 \\
f\_03 & 7.99 & 16.49 & 3.49 & -1.00 & 0.03 \\
f\_04 & 7.00 & 19.50 & 4.50 & -4.99 & 0.03 \\
f\_05 & 6.99 & 14.49 & 3.99 & -4.00 & 0.040 \\
f\_06 & 7.50 & 17.00 & 4.50 & -4.49 & 0.027 \\
f\_09 & 7.26 & 12.26 & 3.76 & -1.73 & 0.03 \\
\end{longtable}
}

\end{document}

tabular with <code>booktabs</code> and <code>dcolumn</code>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .