1

I want to reference a sub-table in my text. However, when I use the ref command, the number of the table and the sub-table are presented without any separation. This is out of my expectation because I hope there will be a dot or space between two numbers, for example, I wish it would show "Table I.(a)" rather than "Table Ia". Therefore, is there any possible solution to fix this problem?

\ref{tab:week2}
\begin{table}[h]
  \begin{subtable}[h]{0.45\textwidth}
      \centering
      \begin{tabular}{l | l | l}
      Day & Max Temp & Min Temp \\
      \hline \hline
      Mon & 20 & 13\\
      Tue & 22 & 14\\
     \end{tabular}
     \caption{First Week}
     \label{tab:week1}
  \end{subtable}
  \hfill
  \begin{subtable}[h]{0.45\textwidth}
      \centering
      \begin{tabular}{l | l | l}
      Day & Max Temp & Min Temp \\
      \hline \hline
      Mon & 17 & 11\\
      Tue & 16 & 10\\
      \end{tabular}
      \caption{Second Week}
      \label{tab:week2}
   \end{subtable}
   \caption{Max and min temps recorded in the first two weeks of July}
   \label{tab:temps}
\end{table}

1
  • 1
    You should have provided full MWE.
    – ivankokan
    Nov 6, 2020 at 4:51

1 Answer 1

4

You should have provided full MWE.

However, here is the solution:

\documentclass{article}

\usepackage[labelformat=simple]{subcaption} % packages subfigure and subfig are obsolete

\renewcommand\thesubtable{(\alph{subtable})}
\makeatletter
\renewcommand\p@subtable{\thetable.}
\makeatother


\begin{document}

\ref{tab:week2}
\begin{table}[h]
  \begin{subtable}[h]{0.45\textwidth}
      \centering
      \begin{tabular}{l | l | l}
      Day & Max Temp & Min Temp \\
      \hline \hline
      Mon & 20 & 13\\
      Tue & 22 & 14\\
     \end{tabular}
     \caption{First Week}
     \label{tab:week1}
  \end{subtable}
  \hfill
  \begin{subtable}[h]{0.45\textwidth}
      \centering
      \begin{tabular}{l | l | l}
      Day & Max Temp & Min Temp \\
      \hline \hline
      Mon & 17 & 11\\
      Tue & 16 & 10\\
      \end{tabular}
      \caption{Second Week}
      \label{tab:week2}
   \end{subtable}
   \caption{Max and min temps recorded in the first two weeks of July}
   \label{tab:temps}
\end{table}

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