0

I'm writing a long table but the contents of the long table are separately written. How can I embed it properly to work. Please run the code to see the self-explaining problem.

\documentclass[12pt]{article}
\usepackage{longtable}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\makeatletter
\newcommand{\testfileexists}[1]{%
    \IfFileExists{#1}%
    {\def\inputtestedfile{\@@input #1 }}
    {\let\inputtestedfile\@empty}%
}
\makeatother
\usepackage{filecontents}
\begin{filecontents*}{TR2.1}
\begin{small}\begin{tabular}{|l|C{2cm}|C{2cm}|C{2cm}|C{2cm}|}
        \hline
        &\textbf{Min. [mm]}&\textbf{Max. [mm]}&\textbf{Mean [mm]}&\textbf{deviation [mm]}\\\hline
        \textbf{01.07.2014}&-0.134&-0.051&-0.104&0.019\\\hline
        \textbf{08.07.2014}&-0.147&-0.101&-0.136&0.010\\\hline
        \textbf{15.07.2014}&-0.172&-0.101&-0.142&0.018\\\hline
        \textbf{22.07.2014}&-0.182&-0.142&-0.169&0.010\\\hline
        \textbf{29.07.2014}&-0.191&-0.156&-0.180&0.009\\\hline
        \textbf{05.08.2014}&-0.196&-0.161&-0.183&0.008\\\hline
        \textbf{12.08.2014}&-0.189&-0.171&-0.183&0.004\\\hline
        \textbf{19.08.2014}&-0.188&-0.165&-0.180&0.005\\\hline
        \textbf{26.08.2014}&-0.186&-0.148&-0.177&0.008\\\hline
        \textbf{02.09.2014}&-0.189&-0.161&-0.179&0.006\\\hline
        \textbf{09.09.2014}&-0.186&-0.170&-0.180&0.003\\\hline
        \textbf{16.09.2014}&-0.188&-0.172&-0.182&0.004\\\hline
        \textbf{23.09.2014}&-0.187&-0.172&-0.179&0.003\\\hline
        \textbf{30.09.2014}&-0.185&-0.175&-0.181&0.002\\\hline
        \textbf{07.10.2014}&-0.184&-0.175&-0.179&0.002\\\hline
        \textbf{14.10.2014}&-0.182&-0.173&-0.179&0.002\\\hline
        \textbf{21.10.2014}&-0.184&-0.175&-0.179&0.002\\\hline
        \textbf{28.10.2014}&-0.183&-0.173&-0.178&0.002\\\hline
        \textbf{04.11.2014}&-0.182&-0.174&-0.179&0.002\\\hline
        \textbf{11.11.2014}&-0.178&-0.174&-0.176&0.001\\\hline
        \textbf{18.11.2014}&-0.178&-0.173&-0.176&0.001\\\hline
        \textbf{25.11.2014}&-0.180&-0.176&-0.177&0.001\\\hline
        \textbf{02.12.2014}&-0.177&-0.172&-0.175&0.002\\\hline
        \textbf{09.12.2014}&-0.179&-0.174&-0.176&0.001\\\hline
        \textbf{16.12.2014}&-0.180&-0.173&-0.176&0.002\\\hline
        \textbf{23.12.2014}&-0.183&-0.177&-0.180&0.002\\\hline
        \textbf{30.12.2014}&-0.178&-0.175&-0.177&0.001\\\hline
        \textbf{06.01.2015}&-0.182&-0.173&-0.177&0.002\\\hline
        \textbf{13.01.2015}&-0.181&-0.175&-0.178&0.002\\\hline
        \textbf{20.01.2015}&-0.179&-0.173&-0.175&0.002\\\hline
        \textbf{27.01.2015}&-0.176&-0.172&-0.175&0.001\\\hline
        \textbf{03.02.2015}&-0.177&-0.172&-0.174&0.001\\\hline
        \textbf{10.02.2015}&-0.178&-0.170&-0.175&0.002\\\hline
        \textbf{17.02.2015}&-0.176&-0.168&-0.174&0.002\\\hline
        \textbf{24.02.2015}&-0.178&-0.170&-0.174&0.002\\\hline
        \textbf{03.03.2015}&-0.177&-0.162&-0.173&0.003\\\hline
        \textbf{10.03.2015}&-0.181&-0.169&-0.176&0.003\\\hline
        \textbf{17.03.2015}&-0.179&-0.163&-0.174&0.004\\\hline
        \textbf{24.03.2015}&-0.178&-0.158&-0.174&0.004\\\hline
        \textbf{31.03.2015}&-0.178&-0.152&-0.172&0.006\\\hline
        \textbf{07.04.2015}&-0.183&-0.138&-0.171&0.010\\\hline
        \textbf{14.04.2015}&-0.183&-0.139&-0.171&0.012\\\hline
        \textbf{21.04.2015}&-0.182&-0.143&-0.172&0.009\\\hline
        \textbf{28.04.2015}&-0.184&-0.144&-0.170&0.009\\\hline
        \textbf{05.05.2015}&-0.185&-0.146&-0.176&0.008\\\hline
        \textbf{12.05.2015}&-0.186&-0.155&-0.176&0.008\\\hline
        \textbf{19.05.2015}&-0.183&-0.146&-0.172&0.008\\\hline
        \textbf{26.05.2015}&-0.183&-0.154&-0.174&0.007\\\hline
        \textbf{02.06.2015}&-0.190&-0.102&-0.172&0.016\\\hline
        \textbf{09.06.2015}&-0.191&-0.132&-0.175&0.015\\\hline
        \textbf{16.06.2015}&-0.186&-0.154&-0.179&0.007\\\hline
        \textbf{23.06.2015}&-0.187&-0.132&-0.173&0.013\\\hline
        \textbf{30.06.2015}&-0.201&-0.126&-0.175&0.019\\\hline
        \textbf{07.07.2015}&-0.196&-0.151&-0.185&0.010\\\hline
        \textbf{14.07.2015}&-0.193&-0.140&-0.180&0.012\\\hline
        \textbf{21.07.2015}&-0.193&-0.162&-0.182&0.007\\\hline
        \textbf{28.07.2015}&-0.186&-0.104&-0.170&0.021\\\hline
        \textbf{04.08.2015}&-0.191&-0.122&-0.172&0.016\\\hline
        \textbf{11.08.2015}&-0.189&-0.156&-0.181&0.008\\\hline
        \textbf{18.08.2015}&-0.191&-0.147&-0.178&0.011\\\hline
        \textbf{25.08.2015}&-0.188&-0.137&-0.175&0.012\\\hline
        \textbf{01.09.2015}&-0.192&-0.153&-0.182&0.009\\\hline
    \end{tabular}
\end{small}
\end{filecontents*}
\begin{document}
\begin{center}
\begin{longtable}{|c|c|}
\caption{A simple longtable example}\\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\endhead
\hline \multicolumn{2}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot
R1&\input{TR2.1}\\
\end{longtable}
\end{center}
\end{document}
4
  • Why are you trying to nest a tabular enviroment, which cannot be broken across pages, inside a longtable environment?
    – Mico
    Sep 11, 2015 at 10:41
  • Where should the "R1" be situated? If the inner table gets longer this is not clear. You do not need the center here, as longtablecentres by default.
    – LaRiFaRi
    Sep 11, 2015 at 10:43
  • R1 should be in right middle of the TR.1. I don't want but if I skip R1, is there any solution of my problem.
    – user31177
    Sep 11, 2015 at 10:53
  • It is not at all clear what your problem is (or what this code is intended to do) you have a longtable in a center environment (which does nothing useful) and then you are including a large normal non-breaking tabular into a single cell in the second column of the longtable so that clearly will not break over a page Sep 11, 2015 at 11:14

1 Answer 1

1

The rules for setting R1 are pretty unclear to me, are there R2, R3? What about the second page. Maybe it can be added to the header or caption of the table. Or it can be added as separate line above the data rows.

A version of the table without R1, but more nicely formatted IMHO.

Anyway, the data lines should be at top level. TeX can only break a top-level table between rows. A table cell, even if it contains another table is an unbreakable object.

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{siunitx}

\begin{document}
\begingroup
  \small
  \newcommand*{\headmm}{\textbf{[mm]}}
  \begin{longtable}{
    >{\bfseries}l
    *{3}{S[table-format=-1.3]}
    S[table-format=1.3]
  }
    \caption{A simple longtable example}\\
    \toprule
    \textbf{Date} & {\bfseries Min.} & {\bfseries Max.} &
    {\bfseries Mean} & {\bfseries Deviation} \\
    & {\headmm} & {\headmm} & {\headmm} & {\headmm} \\
    \midrule
    \endfirsthead
    \multicolumn{5}{c}{%
      \tablename\ \thetable\ -- \textit{Continued from previous page}%
    } \\
    \toprule
    \textbf{Date} & {\bfseries Min.} & {\bfseries Max.} &
    {\bfseries Mean} & {\bfseries Deviation} \\
    & {\headmm} & {\headmm} & {\headmm} & {\headmm} \\
    \midrule
    \endhead
    \bottomrule
    \multicolumn{5}{r}{\textit{Continued on next page}} \\
    \endfoot
    \bottomrule
    \endlastfoot
    01.07.2014&-0.134&-0.051&-0.104&0.019\\
    08.07.2014&-0.147&-0.101&-0.136&0.010\\
    15.07.2014&-0.172&-0.101&-0.142&0.018\\
    22.07.2014&-0.182&-0.142&-0.169&0.010\\
    29.07.2014&-0.191&-0.156&-0.180&0.009\\
    05.08.2014&-0.196&-0.161&-0.183&0.008\\
    12.08.2014&-0.189&-0.171&-0.183&0.004\\
    19.08.2014&-0.188&-0.165&-0.180&0.005\\
    26.08.2014&-0.186&-0.148&-0.177&0.008\\
    02.09.2014&-0.189&-0.161&-0.179&0.006\\
    09.09.2014&-0.186&-0.170&-0.180&0.003\\
    16.09.2014&-0.188&-0.172&-0.182&0.004\\
    23.09.2014&-0.187&-0.172&-0.179&0.003\\
    30.09.2014&-0.185&-0.175&-0.181&0.002\\
    07.10.2014&-0.184&-0.175&-0.179&0.002\\
    14.10.2014&-0.182&-0.173&-0.179&0.002\\
    21.10.2014&-0.184&-0.175&-0.179&0.002\\
    28.10.2014&-0.183&-0.173&-0.178&0.002\\
    04.11.2014&-0.182&-0.174&-0.179&0.002\\
    11.11.2014&-0.178&-0.174&-0.176&0.001\\
    18.11.2014&-0.178&-0.173&-0.176&0.001\\
    25.11.2014&-0.180&-0.176&-0.177&0.001\\
    02.12.2014&-0.177&-0.172&-0.175&0.002\\
    09.12.2014&-0.179&-0.174&-0.176&0.001\\
    16.12.2014&-0.180&-0.173&-0.176&0.002\\
    23.12.2014&-0.183&-0.177&-0.180&0.002\\
    30.12.2014&-0.178&-0.175&-0.177&0.001\\
    06.01.2015&-0.182&-0.173&-0.177&0.002\\
    13.01.2015&-0.181&-0.175&-0.178&0.002\\
    20.01.2015&-0.179&-0.173&-0.175&0.002\\
    27.01.2015&-0.176&-0.172&-0.175&0.001\\
    03.02.2015&-0.177&-0.172&-0.174&0.001\\
    10.02.2015&-0.178&-0.170&-0.175&0.002\\
    17.02.2015&-0.176&-0.168&-0.174&0.002\\
    24.02.2015&-0.178&-0.170&-0.174&0.002\\
    03.03.2015&-0.177&-0.162&-0.173&0.003\\
    10.03.2015&-0.181&-0.169&-0.176&0.003\\
    17.03.2015&-0.179&-0.163&-0.174&0.004\\
    24.03.2015&-0.178&-0.158&-0.174&0.004\\
    31.03.2015&-0.178&-0.152&-0.172&0.006\\
    07.04.2015&-0.183&-0.138&-0.171&0.010\\
    14.04.2015&-0.183&-0.139&-0.171&0.012\\
    21.04.2015&-0.182&-0.143&-0.172&0.009\\
    28.04.2015&-0.184&-0.144&-0.170&0.009\\
    05.05.2015&-0.185&-0.146&-0.176&0.008\\
    12.05.2015&-0.186&-0.155&-0.176&0.008\\
    19.05.2015&-0.183&-0.146&-0.172&0.008\\
    26.05.2015&-0.183&-0.154&-0.174&0.007\\
    02.06.2015&-0.190&-0.102&-0.172&0.016\\
    09.06.2015&-0.191&-0.132&-0.175&0.015\\
    16.06.2015&-0.186&-0.154&-0.179&0.007\\
    23.06.2015&-0.187&-0.132&-0.173&0.013\\
    30.06.2015&-0.201&-0.126&-0.175&0.019\\
    07.07.2015&-0.196&-0.151&-0.185&0.010\\
    14.07.2015&-0.193&-0.140&-0.180&0.012\\
    21.07.2015&-0.193&-0.162&-0.182&0.007\\
    28.07.2015&-0.186&-0.104&-0.170&0.021\\
    04.08.2015&-0.191&-0.122&-0.172&0.016\\
    11.08.2015&-0.189&-0.156&-0.181&0.008\\
    18.08.2015&-0.191&-0.147&-0.178&0.011\\
    25.08.2015&-0.188&-0.137&-0.175&0.012\\
    01.09.2015&-0.192&-0.153&-0.182&0.009\\
  \end{longtable}
\endgroup
\end{document}

Page 1:

Page 1

Page 2:

Page 2

2
  • I getting an error 'Package array Error: Illegal pream-token (S): `c' used. } I 'm getting this table from another function and I have to only input this table (TR2.1.tex). This code is part of a big script.
    – user31177
    Sep 11, 2015 at 11:13
  • @user31177 You need to load package siunitx for the example. This package provides column type S, which allows to align numbers at the decimal marker in table columns. Sep 11, 2015 at 11:15

You must log in to answer this question.

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