Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have found out that longtabu inside longtabu is not possible but maybe another solution exists. I am autogenerating lots of latex code for documenting a certain binary communication protocol and I need tables to span across pages that have embedded another table which can in itself span across at most two pages. Code below is not pretty but it compiles with TexLive and TexLive extra fonts (for LY1). Any advice how to achieve that would be welcome. My

\documentclass[oneside,a4paper,12pt,notitlepage]{report}
\usepackage[top=3cm, bottom=4.5cm, left=3cm, right=3cm]{geometry}
\usepackage[LY1]{fontenc}
\usepackage{mathptmx} % Add bold and italic
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{longtable} % also needed by longtabu
\usepackage{tabu}
\usepackage{multirow}

\begin{document}

\hspace{-0.6cm}\begin{longtabu}{| l | l | l | X | l | l |}
\firsthline
\textbf{Id} & 20 & \textbf{Name}: &Settings & \textbf{Data Size}: & 26 bytes\\
\hline
\multicolumn{6}{|l|}{

\begin{minipage}[t]{0.97\textwidth}
    \textbf{Description}: This packet is being sent ..ehehe
    \vspace{1mm}
\end{minipage}
} \\
\hline
\multicolumn{6}{|c|}{ \textbf{Fields:} } \\
\multicolumn{6}{ | l |}{

% I would like to have another longtable here .. the nested table does not break across pages
    \begin{tabularx}{0.95\textwidth}{ | l | l | X |}
\firsthline
\textbf{Bits} & \textbf{Field Name} & \textbf{Description}\\
\hline
0 : 2 & SETTING\_A & 
    \begin{minipage}[t]{0.47\textwidth} 
    \textbf{Values}:\\0 - MODE\_A \\ \textit{Comment A.}\\1 - MODE\_B\\\textit{Comment B . dsdsjkhdsakjahsasd}\\2 - MODE\_C\\\textit{Comment C. asdsadasfsddssd}\\3 - MODE\_D\\\textit{Comment D. fdassdaskjdhasd}\\4 - MODE\_E\\\textit{Comment E. fdjksfdsjhgffhjjjhsfd}\\5 - MODE\_F\\\textit{Comment F}\\6 - MODE\_G\\\textit{Comment E}\\\vspace{-0.27cm}

    \end{minipage}
    \tabularnewline \hline
3 : 7 & SETTING\_B & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
8 : 10 & SETTING\_C & 
\begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
11 : 13 & SETTING\_D & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
14 : 16 & SETTING\_E & 
    \begin{minipage}[t]{0.47\textwidth} 
    \textbf{Values}:\\0 - PH\_A\\\textit{Aomment A}\\1 - PH\_B\\\textit{Comment B}\\2 - PH\_C\\\textit{Comment C dsasdjka hsdkjah dsakjsadh kjdash ksaj}\\3 - PH\_D\\\textit{Comment D fdsfdsfdsf sdsdfds}\\4 - PH\_E\\\textit{Comment E asdkhdaskjdshjsakhasdkjds}\\5 - PH\_F\\\textit{Comment F. dsajashsaddsasfdfsddsf}\\\vspace{-0.27cm}

    \end{minipage}
    \tabularnewline \hline
17 : 29 & SETTING\_F & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
30 : 42 & SETTING\_G & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
43 : 48 & SETTING\_H & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
49 : 54 & SETTING\_I & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
55 : 61 & SETTING\_J & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
62 : 77 & SETTING\_K & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
78 : 93 & SETTING\_L & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
94 : 109 & SETTING\_M & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \\\hline
110 : 125 & SETTING\_N & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
126 : 141 & SETTING\_L & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
142 : 150 & PULSE\_WIDTH & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
151 : 159 & PULSE\_WIDTH\_HIGH & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
160 : 175 & DELAY & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
176 : 188 & TOTAL\_PROGRAM\_TIME & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
189 : 201 & TOTAL\_PHASE\_TIME & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \lasthline
\end{tabularx}
} \\
\lasthline
\end{longtabu}

\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You need to make any parts that need to break be part of the outer table, something like this

\documentclass[oneside,a4paper,12pt,notitlepage]{report}
\usepackage[top=3cm, bottom=4.5cm, left=3cm, right=3cm]{geometry}
\usepackage[LY1]{fontenc}
\usepackage{mathptmx} % Add bold and italic
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{longtable} % also needed by longtabu
\usepackage{tabu}
\usepackage{multirow}

\begin{document}

\hspace{-0.6cm}

\begin{longtabu}{ | l | l | X |}
\firsthline
\multicolumn{3}{|c|}{
\begin{tabularx}{\linewidth}{ l | l | l | X | l | l }
\textbf{Id} & 20 & \textbf{Name}: &Settings & \textbf{Data Size}: & 26 bytes\\
\end{tabularx}}\\
\hline
\multicolumn{3}{|l|}{

\begin{minipage}[t]{0.97\textwidth}
    \textbf{Description}: This packet is being sent ..ehehe
    \vspace{1mm}
\end{minipage}
} \\
\hline
\multicolumn{3}{|c|}{ \textbf{Fields:} } \\


\firsthline
\textbf{Bits} & \textbf{Field Name} & \textbf{Description}\\
\hline
0 : 2 & SETTING\_A & 
    \begin{minipage}[t]{0.47\textwidth} 
    \textbf{Values}:\\0 - MODE\_A \\ \textit{Comment A.}\\1 - MODE\_B\\\textit{Comment B . dsdsjkhdsakjahsasd}\\2 - MODE\_C\\\textit{Comment C. asdsadasfsddssd}\\3 - MODE\_D\\\textit{Comment D. fdassdaskjdhasd}\\4 - MODE\_E\\\textit{Comment E. fdjksfdsjhgffhjjjhsfd}\\5 - MODE\_F\\\textit{Comment F}\\6 - MODE\_G\\\textit{Comment E}\\\vspace{-0.27cm}

    \end{minipage}
    \tabularnewline \hline
3 : 7 & SETTING\_B & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
8 : 10 & SETTING\_C & 
\begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
11 : 13 & SETTING\_D & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
14 : 16 & SETTING\_E & 
    \begin{minipage}[t]{0.47\textwidth} 
    \textbf{Values}:\\0 - PH\_A\\\textit{Aomment A}\\1 - PH\_B\\\textit{Comment B}\\2 - PH\_C\\\textit{Comment C dsasdjka hsdkjah dsakjsadh kjdash ksaj}\\3 - PH\_D\\\textit{Comment D fdsfdsfdsf sdsdfds}\\4 - PH\_E\\\textit{Comment E asdkhdaskjdshjsakhasdkjds}\\5 - PH\_F\\\textit{Comment F. dsajashsaddsasfdfsddsf}\\\vspace{-0.27cm}

    \end{minipage}
    \tabularnewline \hline
17 : 29 & SETTING\_F & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
30 : 42 & SETTING\_G & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
43 : 48 & SETTING\_H & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
49 : 54 & SETTING\_I & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
55 : 61 & SETTING\_J & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
62 : 77 & SETTING\_K & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
78 : 93 & SETTING\_L & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
94 : 109 & SETTING\_M & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \\\hline
110 : 125 & SETTING\_N & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
126 : 141 & SETTING\_L & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
142 : 150 & PULSE\_WIDTH & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
151 : 159 & PULSE\_WIDTH\_HIGH & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
160 : 175 & DELAY & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
176 : 188 & TOTAL\_PROGRAM\_TIME & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}
    \tabularnewline \hline
189 : 201 & TOTAL\_PHASE\_TIME & 
    \begin{minipage}[t]{0.47\textwidth} 

    \end{minipage}\\
    \tabularnewline
\lasthline
\end{longtabu}

\end{document}
share|improve this answer
    
A bit changes layout and I had to change one \firsthline to \hline to remove spacing but it works in this particular case! Thank you! Still interesting if it is possible with the previous layout (the table visibly being inside the other table) –  RushPL Mar 14 '12 at 14:28
    
you can add vertical spacing etc to make it look like anything but a table cell is basically a box so it's like putting something inside \mbox and so will never break unless you deconstruct the entire table. –  David Carlisle Mar 14 '12 at 15:31
    
Interesting. I will play with it. Much appreciated. –  RushPL Mar 14 '12 at 21:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.