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.

In this answer, there is a code provided for neatly arranging subtables inside a table. I tried that out and got the following error:

 Missing number, treated as zero \begin{subtable}{0.5\linewidth}

 Illegal unit of measure (pt inserted) \begin{subtable}{0.5\linewidth}

Could someone suggest how to resolve this issue? I have used the subcaption package.

EDIT: Adding the code:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{subcaption}
%opening
\title{}
\author{}

\begin{document}

\maketitle

\begin{table*}[ht]
\centering
\begin{subtable}{.5 \linewidth}\centering
{\small
\hfill{}
\begin{tabular}{|c|c|}
\hline
\textbf{Range of $I$} & \textbf{S}\\
  \hline
  1 & $A$\\
  \hline
  2 & $B$ \\
  \hline
\ldots & \ldots \\
\hline
\end{tabular}}
\begin{subtable}{.5\linewidth}\centering
{\small
\hfill{}
\begin{tabular}{|c|c|}
\hline
  \textbf{Range of $I$} & \textbf{D}\\
  \hline
  1 & $A$\\
  \hline
  2 & $B$ \\
  \hline
\ldots & \ldots \\
\hline
% \end{tabular}}
\hfill{}
\caption{S vs I}
\label{tb:sw}
\end{table*}
\end{document}

EDIT: Adding the log file:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=latex 2011.11.1)  12 JUN 2012 12:25
entering extended mode
 %&-line parsing enabled.
**ss.tex
(./ss.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, farsi, arabic, croatian, bulgarian, ukrainian, russian, czech, slov
ak, danish, dutch, finnish, french, basque, ngerman, german, german-x-2009-06-1
9, ngerman-x-2009-06-19, ibycus, monogreek, greek, ancientgreek, hungarian, san
skrit, italian, latin, latvian, lithuanian, mongolian2a, mongolian, bokmal, nyn
orsk, romanian, irish, coptic, serbian, turkish, welsh, esperanto, uppersorbian
, estonian, indonesian, interlingua, icelandic, kurmanji, slovenian, polish, po
rtuguese, spanish, galician, catalan, swedish, ukenglish, pinyin, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texmf-texlive/tex/latex/base/inputenc.sty
Package: inputenc 2008/03/30 v1.1d Input encoding file
\inpenc@prehook=\toks14
\inpenc@posthook=\toks15

(/usr/share/texmf-texlive/tex/latex/ucs/utf8x.def
File: utf8x.def 2004/10/17 UCS: Input encoding UTF-8
))
(/usr/share/texmf-texlive/tex/latex/ucs/ucs.sty
Package: ucs 2004/10/17 UCS: Unicode input support

(/usr/share/texmf-texlive/tex/latex/ucs/data/uni-global.def
File: uni-global.def 2004/10/17 UCS: Unicode global data
)
\uc@secondtry=\count87
\uc@combtoks=\toks16
\uc@combtoksb=\toks17
\uc@temptokena=\toks18
)
(/usr/share/texmf-texlive/tex/latex/caption/subcaption.sty
Package: subcaption 2008/08/31 v1.0b Adding subcaptions (AR)


! Package subcaption Error: `caption' package not loaded
(subcaption)                (which is needed by this package)

See the subcaption package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.38   \endinput}{}

If you do not understand this error, please take a closer look
at the documentation of the `subcaption' package.
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

) (./ss.aux)
\openout1 = `ss.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
 (/usr/share/texmf-texlive/tex/latex/ucs/ucsencs.def
File: ucsencs.def 2003/11/29 Fixes to fontencodings LGR, T3
)
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <12> on input line 11.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <8> on input line 11.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <6> on input line 11.


! LaTeX Error: Environment subtable undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.15 \begin{subtable}
                     {.45\linewidth}\centering
Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Missing number, treated as zero.
<to be read again> 
                   }
l.15 \begin{subtable}{.45\linewidth}
                                    \centering
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   }
l.15 \begin{subtable}{.45\linewidth}
                                    \centering
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 16.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 16.

! LaTeX Error: \begin{table*} on input line 13 ended by \end{subtable}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.27 \end{subtable}

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.


! LaTeX Error: Environment subtable undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.29 \begin{subtable}
                     {.45\linewidth}\centering
Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Missing number, treated as zero.
<to be read again> 
                   }
l.29 \begin{subtable}{.45\linewidth}
                                    \centering
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   }
l.29 \begin{subtable}{.45\linewidth}
                                    \centering
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)


! LaTeX Error: \begin{table*} on input line 13 ended by \end{subtable}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.42 \end{subtable}

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

[1

] (./ss.aux)

 *File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
inputenc.sty    2008/03/30 v1.1d Input encoding file
   utf8x.def    2004/10/17 UCS: Input encoding UTF-8
     ucs.sty    2004/10/17 UCS: Unicode input support
uni-global.def    2004/10/17 UCS: Unicode global data
subcaption.sty    2008/08/31 v1.0b Adding subcaptions (AR)
 ucsencs.def    2003/11/29 Fixes to fontencodings LGR, T3
 ***********

 ) 
Here is how much of TeX's memory you used:
 503 strings out of 493849
 7676 string characters out of 1152846
 65732 words of memory out of 3000000
 3835 multiletter control sequences out of 15000+50000
 6983 words of font info for 25 fonts, out of 3000000 for 9000
 714 hyphenation exceptions out of 8191
 23i,8n,23p,325b,224s stack positions out of 5000i,500n,10000p,200000b,50000s

Output written on ss.dvi (1 page, 1156 bytes).
share|improve this question
    
@percusse: Would be grateful if you could look into this. –  Bravo Jun 11 '12 at 8:35
1  
I get the error if, instead of \usepackage{subcaption} I use \usepackage{subfigure}. Please, remove tha latter and use the former. –  egreg Jun 11 '12 at 8:37
2  
I also get it working with subcaption package. I'll emphasize the package difference. –  percusse Jun 11 '12 at 8:41
    
@Shyam If you have \usepackage{subfigure} in your document, remove it: the subfigure package is obsolete and incompatible with subcaption. –  egreg Jun 11 '12 at 9:42
    
@egreg: I have removed \subfigure as well, but still get the same error. –  Bravo Jun 11 '12 at 9:59
show 1 more comment

1 Answer

up vote 7 down vote accepted

Your code has a few mistakes such as missing \end{subtable} etc. Fixing those and slightly decreasing the subtable sizes gives the result as expected:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{subcaption}
%opening
\title{}
\author{}

\begin{document}

\maketitle

\begin{table*}[ht]
\centering
\begin{subtable}{.45\linewidth}\centering
\begin{tabular}{|c|c|}
\hline
\textbf{Range of $I$} & \textbf{S}\\
  \hline
  1 & $A$\\
  \hline
  2 & $B$ \\
  \hline
\ldots & \ldots \\
\hline
\end{tabular}
\end{subtable}
\hfill{}
\begin{subtable}{.45\linewidth}\centering
\begin{tabular}{|c|c|}
\hline
  \textbf{Range of $I$} & \textbf{D}\\
  \hline
  1 & $A$\\
  \hline
  2 & $B$ \\
  \hline
\ldots & \ldots \\
\hline
 \end{tabular}
%\hfill{}
\end{subtable}
\caption{S vs I}
\label{tb:sw}
\end{table*}
\end{document}

enter image description here

share|improve this answer
    
Did you figure out why in your original answer, it's working without narrowing the tables? –  dgs Jun 11 '12 at 10:59
    
@dgs I'm really not sure but this example works until 0.4913 so one possibility is that the vertical lines occupying a small space and adds some padding to the width but the other one does not care anyway. So I guess I don't know. –  percusse Jun 11 '12 at 11:08
    
Leaving out the | was my first guess, too, but surprisingly it didn't change anything. –  dgs Jun 11 '12 at 11:22
2  
Sorry to disappoint you, I have pasted this very code but still get the error in the question. Is it because subcaption is not recognised in my Miktex installation? –  Bravo Jun 12 '12 at 6:25
    
@Shyam Can you put \listfiles in your preamble and update the question with the result in the log file? –  percusse Jun 12 '12 at 6:58
show 2 more comments

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.