17

I am trying to make a complicated table, where each cell itself can be a table.

I found I can include tabularx inside tabular*, but unable to figure out why I get an error with the outer table is tabularx as well. May be someone can see what I am doing wrong.

This MWE works. The one below it does not work.

\documentclass[10pt,notitlepage]{article}%
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}

\begin{tabular*}{\textwidth}{p{\textwidth}}\hline
 \begin{tabularx}{\textwidth}{@{}|Y|Y|Y|@{}}\hline

    \href{foo/index.htm}{A}
    \begin{enumerate}
      \item item 1
      \item item 2
    \end{enumerate}& 
    \href{foo/index.htm}{B}& 
    \href{foo/index.htm}{C}\\\hline
 \end{tabularx}

\end{tabular*}
\end{document}

Mathematica graphics

Now I change the outer table to tabularX and it failed:

\documentclass[10pt,notitlepage]{article}%
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}

\begin{tabularx}{\textwidth}{@{}Y@{}}\hline
 \begin{tabularx}{\textwidth}{@{}|Y|Y|Y|@{}}\hline

    \href{foo/index.htm}{A}
    \begin{enumerate}
      \item item 1
      \item item 2
    \end{enumerate}& 
    \href{foo/index.htm}{B}& 
    \href{foo/index.htm}{C}\\\hline
 \end{tabularx}

\end{tabularx}
\end{document}

error is

(./foo2.out) (./foo2.out)
! Extra }, or forgotten \endgroup.
\TX@trial ...er \tabular \the \toks@ \endtabular }
                                                  \TX@ckpt \TX@typeout@ {\@s...
l.18  \end{tabularx}

? 

Using texlive 2013 on linux

1 Answer 1

18

The nested tabularx should be surrounded by { and }

\documentclass[10pt,notitlepage]{article}%
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}

\begin{tabularx}{\textwidth}{@{}Y@{}}\hline
 {\begin{tabularx}{\textwidth}{@{}|Y|Y|Y|@{}}\hline
    \href{foo/index.htm}{A}
    \begin{enumerate}
      \item item 1
      \item item 2
    \end{enumerate}& 
    \href{foo/index.htm}{B}& 
    \href{foo/index.htm}{C}\\\hline
 \end{tabularx}}

\end{tabularx}
\end{document}

This is per the documentation. I found it by doing a search on nest in the documentation.

You should probably make a couple changes though. Using \textwidth within the inner tabularx is most likely going to result in columns being too wide. Instead use \linewidth. Here is a modified nested tabularx construction:

\documentclass[10pt,notitlepage]{article}%
\usepackage[margin=0.5in]{geometry}
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\usepackage{lipsum}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tabularx}{\textwidth}{@{}lY@{}}\hline
 Hello &
 {\begin{tabularx}{\linewidth}{@{}|Y|Y|Y|@{}}\hline
    \href{foo/index.htm}{A}
    \begin{enumerate}
      \item item 1 \lipsum[1]
      \item item 2
    \end{enumerate}
    & 
    \href{foo/index.htm}{B}

     \lipsum[2]
    & 
    \href{foo/index.htm}{C}

    3:\lipsum[3] \\\hline
 \end{tabularx}}
\end{tabularx}
\end{document}

enter image description here

You must log in to answer this question.

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