6

The \ref command can refer only the number of the table, like the following code.

\documentclass{article}
\begin{document}
According to Table \ref{table} [[HERE]], we blah blah.
\begin{table}[tb]
  \caption{The caption of the table}
  \label{table}
  \begin{center}
    \begin{tabular}{ll}\hline foo & bar \\ \hline\end{tabular}
  \end{center}
\end{table}
\end{document}

I would like to insert the caption text into body after \ref (the position [[HERE]]).

like

According to Table 1: "The caption of the table", we blah blah.

Not

According to Table 1, we blah blah.

Are there any ways to insert caption text into body?

4

For example, packages nameref or titleref provides to reference the title of captions (and sections, ...):

\documentclass{article}
\usepackage{booktabs}% nicer table lines
\usepackage{nameref}
\usepackage{csquotes}% quotes with multilingual support
\usepackage{caption}% fixes the spacing around caption for tables
\begin{document}
According to Table \ref{table} \enquote{\nameref{table}}, we blah blah.
\begin{table}[tb]
  \centering % avoids additional vertical space of environment center
  \caption{The caption of the table}
  \label{table}
  \begin{tabular}{ll}
    \toprule
    foo & bar \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

Result

With package titleref:

\usepackage{titleref}
...\titleref{...}...

See also the comments for additional hints.

  • Thank you very much! Your answer works in my environment, too. – Nyoho Mar 27 '16 at 11:13
  • LyX users only: Simply select the "Textual reference" format in the Cross-reference dialog (this use nameref in the background, do not mess with the LaTeX preamble for this). – Fran Mar 27 '16 at 11:24
  • And I found that you are one of the main­tainers of nameref! Thank you again for making useful pakcage! (and one of my friends also appreciates that.) – Nyoho Mar 27 '16 at 13:24

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.