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}
  • beamer and caption is a strange relationship. I am not sure that \subref can work properly here – user31729 Dec 6 '15 at 22:40
  • Try \hyperlink{subtab}{\subref*{subtab}}. This will at least provide the correct link! – user31729 Dec 6 '15 at 22:48
  • 1
    See the update at the end of my answer please – user31729 Dec 6 '15 at 22:55
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}
|improve this answer|||||
  • @user565739: It's in the manual ;-) – user31729 Dec 6 '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 6 '15 at 22:07
  • @user565739: beamer was not in your question! You posted an article MWE, not a beamer version, that's different – user31729 Dec 6 '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 6 '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 – user31729 Dec 6 '15 at 22:19

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.