4

In the MWE below, I want to refer to the subtable 1a by just display a. I don't want to display the number of the parent Table 1.

In this post

How to reference subfigure in caption,

the first example shows that a solution using \subbottom. However, is there a direct setting for table and subtable to achieve what I want?

MWE is

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{caption}
\usepackage{subcaption}


\begin{document}



\begin{table}[ht]
\begin{subtable}{3cm}
$X \xrightarrow{\phantom{=======}} Y$
\caption{sub-tab}
\label{subtab}
\end{subtable}
\caption{tab}
\label{tab}
\end{table}

This is refer to subtable \ref{subtab}.

\end{document}

Thank the answer from Christian Hupfer. I am sorry not to be more careful about my question. In fact, I want to achieve the goal in beamer. I give a MWE below. Using \subref in beamer will jump to the title page. Need a way to fix this. But however, Christian Hupfer's answer for article is still helpful!

\documentclass{beamer}

\mode<presentation>
{
    \usetheme{Warsaw}
    \setbeamertemplate{headline}{}
    \setbeamertemplate{itemize item}[triangle]
    \setbeamertemplate{itemize subitem}[triangle]
    \setbeamertemplate{itemize subsubitem}[triangle]
    \setbeamercovered{transparent}
    \useoutertheme{infolines}
    \usefonttheme{professionalfonts}
}

\setbeamertemplate{section page}
{
    \begin{centering}
    \begin{beamercolorbox}[sep=12pt,center]{part title}
    \usebeamerfont{section title}\insertsection\par
    \end{beamercolorbox}
    \end{centering}
}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{caption}
\usepackage{subcaption}
\captionsetup{compatibility=false}


\begin{document}

\frame{\titlepage}
\frame{\tableofcontents}

\begin{frame}

\begin{table}[ht]
\begin{subtable}{3cm}
$X \xrightarrow{\phantom{=======}} Y$
\caption{sub-tab}
\label{subtab}
\end{subtable}
\caption{tab}
\label{tab}
\end{table}

\end{frame}

\begin{frame}

This is refer to subtable \subref{subtab}.

\end{frame}

\end{document}
user565739
  • 5,482
  • beamer and caption is a strange relationship. I am not sure that \subref can work properly here –  Dec 06 '15 at 22:40
  • Try \hyperlink{subtab}{\subref*{subtab}}. This will at least provide the correct link! –  Dec 06 '15 at 22:48
  • 1
    See the update at the end of my answer please –  Dec 06 '15 at 22:55

1 Answers1

6

The subcaption package defines the command \subref which is exactly designed for this usage:

\ref{foo} will show the full table number (or caption number) whereas \subref{foo} will only show the subtable (or subcaption number)

subcaption will define labels of type sub@foo and are stripped off driving caption numbers, e. g. a table number here.

memoir's \subcaptionref seems to be a similar command but I've never used it so far.

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{caption}
\usepackage{subcaption}



\begin{document}



\begin{table}[ht]
\begin{subtable}{3cm}
$X \xrightarrow{\phantom{=======}} Y$
\caption{sub-tab}
\label{subtab}
\end{subtable}
\caption{tab}
\label{tab}
\end{table}

This is refer to \subref{subtab}.

\end{document}

enter image description here

Update Here's the beamer version -- apparently the hyperlink isn't set correctly, so try to extract a \subref* and use an automatic hyperlink afterwards by redefinition of \subref.

\documentclass{beamer}


\mode<presentation>
{
    \usetheme{Warsaw}
    \setbeamertemplate{headline}{}
    \setbeamertemplate{itemize item}[triangle]
    \setbeamertemplate{itemize subitem}[triangle]
    \setbeamertemplate{itemize subsubitem}[triangle]
    \setbeamercovered{transparent}
    \useoutertheme{infolines}
    \usefonttheme{professionalfonts}
}

\setbeamertemplate{section page}
{
    \begin{centering}
    \begin{beamercolorbox}[sep=12pt,center]{part title}
    \usebeamerfont{section title}\insertsection\par
    \end{beamercolorbox}
    \end{centering}
}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}

\usepackage{caption}
\usepackage{subcaption}
\captionsetup{compatibility=false}

\makeatletter
\let\orig@subref\subref

\renewcommand{\subref}{%
  \@ifstar{\subref@starred}{\subref@unstarred}%
}

\newcommand{\subref@starred}[1]{%
  \orig@subref*{#1}%
}

\newcommand{\subref@unstarred}[1]{%
  \hyperlink{#1}{\orig@subref*{#1}}%
}
\makeatother


\begin{document}

\frame{\titlepage}
\frame{\tableofcontents}

\begin{frame}

\begin{table}[ht]
\begin{subtable}{3cm}
$X \xrightarrow{\phantom{=======}} Y$
\caption{sub-tab}
\label{subtab}
\end{subtable}
\caption{tab}
\label{tab}
\end{table}

\end{frame}

\begin{frame}

This is refer to subtable \subref{subtab} %\hyperlink{subtab}{\subref*{subtab}}.

\end{frame}

\end{document}
  • @user565739: It's in the manual ;-) –  Dec 06 '15 at 22:05
  • I found something strange. I use this in beamer. Using \ref is fine, but using \subref will go to the title page. I will give a MWE. – user565739 Dec 06 '15 at 22:07
  • @user565739: beamer was not in your question! You posted an article MWE, not a beamer version, that's different –  Dec 06 '15 at 22:08
  • Sorry about this. I didn't realize that this will cause the difference. I just want to give a really minimal "MWE". – user565739 Dec 06 '15 at 22:15
  • @user565739: You can of course add your MWE, but this changes the question. I'll try to get a solution for it too –  Dec 06 '15 at 22:19
  • Great again. But I can't give you 2 votes and 2 acceptance. – user565739 Dec 06 '15 at 22:58
  • @user565739: No, of course not -- but you could look around for other posts of mine ;-) (If you want to upvote in any case only, of course ;-)) –  Dec 06 '15 at 23:00