0

How can I add a caption on top of two table in standalone document? e.g.

\documentclass[border=1pt,convert={outfile=\jobname.jpg}]{standalone}
\usepackage{color,colortbl}
\usepackage[table]{xcolor} 
\usepackage{fontspec}
\setmainfont{Kaiti TC}
\usepackage{ifthen}
%
\usepackage{caption}
\def\tand{&}
\definecolor{Gray}{gray}{0.9}
%
\begin{document}
\newcounter{zh}
\newcounter{us}
\newcolumntype{g}{>{\columncolor{Gray}}c}
%
\begin{tabular}{|c|g|}
\hline
  \setcounter{zh}{0}%
  \setcounter{us}{10}%
   China \tand US \\ \hline%
  \whiledo{\thezh<12}{%
      \thezh \tand \theus \\ \hline%
       \ifnum\value{zh}=11\hline\end{tabular}\fi
       \stepcounter{zh}%
        \stepcounter{us}%
       \ifnum\value{us}>23 \setcounter{us}{0}\fi
  }%
   \begin{tabular}{|c|g|}
\hline
  \setcounter{zh}{12}%
  \setcounter{us}{22}%
   China \tand US \\ \hline%
  \whiledo{\thezh<24}{%
      \thezh \tand \theus \\ \hline%
       \ifnum\value{zh}=23\hline\end{tabular}\fi
       \stepcounter{zh}%
        \stepcounter{us}%
       \ifnum\value{us}>23 \setcounter{us}{0}\fi
  }%
\end{document}

Current output is: enter image description here

2

The simplest is to put your tabulars in a unique tabular, and the latter in threeparttable, which has the advantage to measure the tabular width. Then use a normal caption. I take the opportunity to point that you don't have to load color since you load xcolor, nor colortbl since you load it (xcolor) with option [table]:

\documentclass[border=1pt,convert={outfile=\jobname.jpg}]{standalone}%
\usepackage{color,colortbl}
\usepackage[table]{xcolor}
\usepackage{fontspec}
\setmainfont{Kaiti TC}
\usepackage{ifthen}
%
\usepackage{caption, float, threeparttable}
\def\tand{&}
\definecolor{Gray}{gray}{0.9}
%
\begin{document}
\newcounter{zh}
\newcounter{us}
\newcolumntype{g}{>{\columncolor{Gray}}c}
%b

\begin{threeparttable}%
\captionsetup{skip=4pt}%
\caption{Some caption}%
\begin{tabular}{@{}c@{}}
  \begin{tabular}{|c|g|}
\hline
  \setcounter{zh}{0}%
  \setcounter{us}{10}%
   China \tand US \\ \hline%
  \whiledo{\thezh<12}{%
      \thezh \tand \theus \\ \hline%
       \ifnum\value{zh}=11\hline%
       \end{tabular}\fi
\stepcounter{zh}%
\stepcounter{us}%
\ifnum\value{us}>23 \setcounter{us}{0}\fi%
  }%
   \begin{tabular}{|c|g|}
\hline
  \setcounter{zh}{12}%
  \setcounter{us}{22}%
   China \tand US \\ \hline%
  \whiledo{\thezh<24}{%
      \thezh \tand \theus \\ \hline%
       \ifnum\value{zh}=23\hline%
       \end{tabular}\fi
       \stepcounter{zh}%
        \stepcounter{us}%
       \ifnum\value{us}>23 \setcounter{us}{0}\fi
  }%
\end{tabular}
\end{threeparttable}
\end{document} 

enter image description here

2

As you are using the caption package, you can use \captionof{table}{<text>} without a float. To place it on top of the two tables, you can use a minipage, that is:

\begin{minipage}{5cm}
\captionof{table}{The caption}
\centering
\begin{tabular}{...}... \end{tabular}% \hfill or \quad here?
\begin{tabular}{...}... \end{tabular}
\end{minipage}

But being a standalone class, why the hell you need the caption package and a \captionof command?

\begin{minipage}{5cm}
\centering
Table 1. The caption
\begin{tabular}{...}... \end{tabular}% 
\begin{tabular}{...}... \end{tabular}
\end{minipage}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.