Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

References with text in LaTeX

Tags:

latex

In LaTeX you can easily reference a section by using \label{} next to a section and then \ref{} to create the reference. However, the reference only includes the number of the section, or the page with \pageref{}. I would like to insert a reference containing the text of the section.

Example:

\section{My Section}
\label{section:my}

This is a reference to Section~\ref{section:my}.

The output is the following:

1. My Section

This is a reference to Section 1.

I would like to have:

This is a reference to 1. My Section.
like image 546
ssn Avatar asked Sep 29 '09 10:09

ssn


People also ask

How do you reference text in overleaf?

Referencing the page of an element Elements usually are referenced by a number assigned to them, but if you need to, you can insert the page where they appear. \section{Math references} \label{mathrefs} As mentioned in section \ref{introduction}, different elements can be referenced within a document.

How do you cite a paragraph in LaTeX?

It is well-known that \section environment may be assigned a label \label{refname} and then the refname may be used in order to reference this section: \section{My nice section} \label{sec:my-nice-section} Definitely the section is nice!

How do you reference a label in LaTeX?

One of the most useful features of LaTeX is its ability to handle cross-references. To use this, we first define a label at the section (or equation, table, etc.) we want to reference, using the \label{} command, e.g. The argument to the \label command is just a text string that you'll use to reference that part.


3 Answers

Have a look to this wiki: LaTeX/Labels and Cross-referencing:

The hyperref package automatically includes the nameref package, and a similarly named command. It inserts text corresponding to the section name, for example:

\section{MyFirstSection}
\label{marker}
\section{MySecondSection} In section \nameref{marker} we defined...
like image 61
enguerran Avatar answered Oct 20 '22 05:10

enguerran


I think you can do this with the hyperref package, although I've not tried it myself. From the relevant LaTeX Wikibook section:

The hyperref package introduces another useful command; \autoref{}. This command creates a reference with additional text corresponding to the targets type, all of which will be a hyperlink. For example, the command \autoref{sec:intro} would create a hyperlink to the \label{sec:intro} command, wherever it is. Assuming that this label is pointing to a section, the hyperlink would contain the text "section 3.4", or similar (capitalization rules will be followed, which makes this very convenient). You can customize the prefixed text by redefining \typeautorefname to the prefix you want, as in:

\def\subsectionautorefname{section}

like image 22
ire_and_curses Avatar answered Oct 20 '22 06:10

ire_and_curses


Using the hyperref package, you could also declare a new command by using \newcommand{\secref}[1]{\autoref{#1}. \nameref{#1}} in the pre-amble. Placing \secref{section:my} in the text generates: 1. My section.

like image 13
user5011146 Avatar answered Oct 20 '22 05:10

user5011146