排列子表的问题

排列子表的问题

这个答案,提供了用于在表格内整齐排列子表格的代码。我尝试了一下,得到了以下错误:

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

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

有人能建议如何解决这个问题吗?我已经使用过这个subcaption包了。

编辑:添加代码:

\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}

编辑:添加日志文件:

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).

答案1

您的代码有一些错误,例如缺失\end{subtable}等。修复这些问题并稍微减小子表大小即可得到预期的结果:

\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}

在此处输入图片描述

相关内容