GeneralCross Reference for a Section by Name

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
dagoss
Posts: 2
Joined: Fri Jul 15, 2011 7:40 pm

Cross Reference for a Section by Name

Post by dagoss »

Hello,

I feel like this should be a simply (and common) operation but I haven't figured out how to do it. It may simply be that I don't understand this documenation.

I want to cross references sections of my document such that I can have this:

Code: Select all

\section{Building Framing}
\label{frame}

[...]

Please refer to \autoref{frame} for more information.
Which would output:

"Please refer to 3.2 Building Framing for more information."

By default, autoref gives "Section 3.2", but I want it to pull the name of the chapter/section/subsection that the label is in, along with the number. How can I do that?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Cross Reference for a Section by Name

Post by meho_r »

Here's one way:

Code: Select all

\documentclass{article}

\usepackage{hyperref}

\newcommand{\myref}[1]{\ref{#1} -- \nameref{#1}}

\begin{document}

\section{A section}\label{test}

``Plain'' ref:~\ref{test},\\ 
Autoref:~\autoref{test},\\
Nameref:~\nameref{test},\\
Custom ref:~\myref{test}.

\end{document}
Post Reply