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 want to make a table inside another table as follows. Unfortunately, it does not work. What is wrong with it?

\documentclass{minimal}
\usepackage{array,longtable,calc}

\begin{document}

\begin{longtable}{*{2}{m{0.5\linewidth}}}
%
\begin{longtable}%
{*{2}{m{0.5\linewidth}}}
A & B\tabularnewline
C & D\tabularnewline
\end{longtable}%
                                        & E \tabularnewline
F                                 & G \tabularnewline
\end{longtable}


\end{document}

EDIT 1

Based on @Herbert's suggestion to use tabular for the inner table, here is my modification. However, the rule does not appear. :-)

\documentclass{minimal}
\usepackage{array,longtable,calc}

\begin{document}

\begin{longtable}{|*{2}{m{0.5\linewidth}|}}
\hline%
\begin{tabular}%
{|*{2}{m{0.5\linewidth}|}}
\hline%
A & B\tabularnewline\hline
C & D\tabularnewline\hline
\end{tabular}%
                                        & E \tabularnewline\hline
F                                 & G \tabularnewline\hline
\end{longtable}


\end{document}
share|improve this question
    
longtable inside longtable is not possible, use tabular for the inner one. –  Herbert Dec 30 '10 at 7:01
    
@Herbert, thanks. I have changed it. But now the rules I just added does not appear. –  xport Dec 30 '10 at 7:06
add comment

2 Answers

up vote 3 down vote accepted

use not the minimal class, then there are no font informations for the lines. Hoiwever, you cannot use for all tables vertical lines, then they are overwritten and sometiomes with a gap.

\documentclass{article}
\usepackage{array,longtable,calc}

\begin{document}

\begin{longtable}{|@{}*{2}{m{0.5\linewidth}|}}\hline
\begin{tabular}{m{0.5\linewidth-\tabcolsep}|m{0.5\linewidth-\tabcolsep}@{}}
A & B\\\hline
C & D
\end{tabular}%
     & E \tabularnewline\hline
\hspace{\tabcolsep}F       & G \tabularnewline\hline
\end{longtable}

\end{document}
share|improve this answer
    
thanks for the solution. I will make some adjustments because there are 2 box overfull warnings. –  xport Dec 30 '10 at 7:29
    
I also posted an answer based on your solution. The Fractal Tables. –  xport Dec 30 '10 at 8:39
add comment

For the sake of completeness :-)


alt text


\documentclass[final,cmyk,table]{article}
\usepackage%
[%
a0paper,
margin=0cm%
]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{array}
\usepackage{longtable}
\usepackage{calc}

\makeatletter
\newcommand\ratio[2]{%
  \strip@pt\dimexpr#1pt/#2\relax
}
\makeatother  


\setlength{\arrayrulewidth}{1pt}
\setlength{\tabcolsep}{5pt}
\arrayrulecolor{red}

\newcolumntype{S}[1]%
{%
    >{%
         \begin{minipage}%
         {%
            #1\linewidth-2\tabcolsep-2\arrayrulewidth%
         }%
         \vspace{\tabcolsep}%
    }%
    c%
    <{%
         \vspace{\tabcolsep}%
         \end{minipage}%
    }%
}%

\newcolumntype{O}[1]%
{%
    >{%
        \begin{minipage}%
        {%
             #1\linewidth-2\tabcolsep-1.5\arrayrulewidth%
        }%
        \vspace{\tabcolsep}%
    }%
    c%
    <{%
         \vspace{\tabcolsep}%
         \end{minipage}%
    }%
}%

\newcolumntype{I}[1]%
{%
    >{%
        \begin{minipage}%
        {%
            #1\linewidth-2\tabcolsep-\arrayrulewidth%
        }%
        \vspace{\tabcolsep}%
    }%
    c%
    <{%
        \vspace{\tabcolsep}%
        \end{minipage}%
    }%
}%



\newenvironment{MyCrazyTable}[3]%
{%    
    \begin{tabular}%
    {%
        |>{\centering}O{\ratio{#2}{#1}}%
        |>{\centering}O{\ratio{#3}{#1}}%
        |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{tabular}%
}



\newcommand{\myrow}{%
\includegraphics[width=\linewidth]{newton}%
&%
\includegraphics[width=\linewidth]{newton}%
\tabularnewline\hline%
}




\begin{document}
\noindent%
\begin{longtable}{|S{1}|}
\hline
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
...                & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable}
\tabularnewline\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
\begin{MyCrazyTable}{2}{1}{1}%
...                & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable} & F\tabularnewline\hline
\myrow
\end{MyCrazyTable}
\tabularnewline\hline
\end{longtable}
\end{document}

I used this image and renamed it as newton.jpg

alt text

share|improve this answer
add comment

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.