Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have these equations with one label:

\section{This is super math section}
\begin{eqnarray}
c + d \\
\label{eq:eq2}
a + b
\end{eqnarray}

But how to do if I want get the section number where is the equation placed and make reference to this section (from the number)?

Equation \eqref{eq:eq2} on page \pageref{eq:eq2} in section \???{eq:eq2} is brilliant!

EDIT: using ref to definition environmet.

\documentclass[a4paper,11pt,twocolumn]{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{yhmath}

\usepackage{cleveref}

\theoremstyle{definition}
\newtheorem{defi}{Definition}[section]

\begin{document}

Definition \ref{def:def1} on page \pageref{def:def1} in section \cref{def:def1} is brilliant!

\section{Definitions}
\begin{defi}\label{def:def1}
This is body of definition.
\end{defi}
\end{document}

Giving: Definition 1.1 on page 1 in section Definition 1.1 is brilliant!

Need: Definition 1.1 on page 1 in section 1 is brilliant!

share|improve this question
    
Welcome to TeX.sx! –  Peter Jansson Mar 14 '13 at 19:52
1  
To make a cross-reference to the section, you first need to place a separate \label statement immediately following the \section statement. E.g., you might write \section{This is a super math section} \label{sec:supermath}. Elsewhere in the document, you'd write "as is shown in Section~\ref{sec:supermath}, ..." Incidentally, don't use the eqnarray environment. Instead, learn to use the align environment provided by the amsmath package. –  Mico Mar 14 '13 at 19:58
add comment

1 Answer 1

up vote 2 down vote accepted

There are many packages in CTAN to manage cross references. Unfortunately some are incompatible or must be loaded in some order. For your question a solution could be \cref from the cleverref package:

MWE

\documentclass{article}
% \usepackage{varioref} % before of hyperref and cleveref
\usepackage{amsmath}
\usepackage[colorlinks=true]{hyperref}
\usepackage{cleveref}

\begin{document}

Equation 
% \vref{eq:eq2} 
 \eqref{eq:eq2} 
% \vpageref{eq:eq2}
in   \cref{eq:eq2} 
named \nameref{eq:eq2} 
 is brilliant!
 \autoref{eq:eq1} is dull.



\section{This is super math section}
\begin{eqnarray}
\label{eq:eq1}
c + d \\
\label{eq:eq2}
a + b
\end{eqnarray}

\end{document}

Edit: For the added problem to the question with a \newtheorem, another solution could be the smartref package:

MWE2

\documentclass{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{defi}{Definition}[section]

\usepackage{smartref}
\addtoreflist{section}

\begin{document}

Definition \ref{def:def1}
on page \pageref{def:def1} 
in section \sectionref{def:def1} is brilliant!

\section{Definitions}
\begin{defi}\label{def:def1}
This is body of definition.
\end{defi}
\end{document}
share|improve this answer
    
This solution is great but if I use \cref to definition: \begin{defi}\label{def:grammer}Bla bla\end{defi}, it gives me definition instead of section number. –  Petr Přikryl Mar 14 '13 at 20:35
1  
It is difficult to give a solution if you do not know the problem. A defi environment? That is not defined in the standard article class, for example. Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Fran Mar 14 '13 at 21:34
    
Editted original ask. –  Petr Přikryl Mar 14 '13 at 22:06
    
Smartref gives right section number but it is not clickable. –  Petr Přikryl Mar 14 '13 at 22:50
1  
Load also the hyperref package and then change \sectionref{def:def1} by \hyperref[def:def1]{\sectionref{def:def1}} –  Fran Mar 15 '13 at 1:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.