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.

Unfortunately, it keeps bugging me with forgotten \endgroup, float(s) lost, not in outer par mode and so on.

In other words, why can't I do something like this (the actual table is significantly more complex with rules and stuff):

\documentclass{article}

\usepackage{blindtext}
\usepackage{tabularx}

\begin{document}

\begin{table}
  \begin{tabularx}{\textwidth}{X}
    \begin{table}
      \begin{tabularx}{\textwidth}{X}
        \blindtext
      \end{tabularx}
      \caption{Inner table}
    \end{table}
  \end{tabularx}
  \caption{Outer table}
\end{table}

\end{document}
share|improve this question
    
I would also love to have a tabularx inside the inner table. –  Egor Tensin Dec 17 '12 at 4:03
    
How should the inner table be enumerated (in relation to the outer one)? –  Qrrbrbirlbel Dec 17 '12 at 4:12
    
Hmm, a good question. I guess I'd like to go with no enumeration for the inner table. I'd be extremely grateful for any other option though, as I'm really tired of trying to accomplish this. –  Egor Tensin Dec 17 '12 at 4:15
    
@EgorTensin Don’t use the inner table environment (how should floating work inside a tabularx anyway?) and drop the inner \caption (no enumeration) command. –  Qrrbrbirlbel Dec 17 '12 at 4:17
    
@Qrrbrbirlbel, but I would like to have a caption, It's just the number that's useless. Or maybe you're suggesting just centering a paragraph as a caption? –  Egor Tensin Dec 17 '12 at 4:19
add comment

1 Answer

up vote 4 down vote accepted

There are two problems here:

  1. Nested table environments: Not in outer par mode

    I suggest dropping the inner table environment. (How should the concept of floating be applicable inside a tabular where the contents are fixed, anyway?)

  2. Nested tabularx environments:

    • Extra }, or forgotten \endgroup,
    • Missing \endgroup inserted and
    • Missing } inserted

    The solution is to enclose the inner tabularx by a pair of braces.
    The the tabularx manual states:

    tabular and tabular* environments may be nested with no restriction, however if one tabularx environment occurs inside another, then the inner one must be enclosed by { }.

Now the inner caption does work without problems and results in a enumerated caption:

Table 1: Inner table

If this is not preferred, one can use the starred version of \caption* for the inner caption from the caption package.


I also replaced \textwidth with \linewidth so that inner tabularx uses the correct remaining horizontal space (→ Difference between \textwidth, \linewidth and \hsize)

Further improvements  could be

  • enclosing the inner tabularx and its caption inside the center environment or
  • providing more vertical space before the inner tabularx, i.e. \\[2ex].

Code

\documentclass{article}

\usepackage{blindtext}
\usepackage{tabularx}

\begin{document}

\begin{table}
  \begin{tabularx}{\linewidth}{X}
     \blindtext \\
      {\begin{tabularx}{\linewidth}{X}
        \blindtext
      \end{tabularx}}
      \caption{Inner table}
     \\
     \blindtext
  \end{tabularx}
  \caption{Outer table}
\end{table}

\end{document}

Output

enter image description here

share|improve this answer
    
I thought the rule was one caption per one table. Seriously, how dumb am I? –  Egor Tensin Dec 17 '12 at 4:42
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.