1

I'm writing my thesis on LaTeX.

The problem is the following: I'm trying to refer to an equation in the appendix, but the command \eqref gives me the wrong number.

I use the command \numberwithin{equation}{section} all over the document, but the equation

\appendix
\begin{fleqn}
\begin{equation}\label{app:eq_gamma-exp}
\Gamma(1+\epsilon) = 1 - \gamma\epsilon + O(\epsilon^2)
\end{equation}
\end{fleqn}

which in my text is numbered as (B.2.6), is referred only as (B.2).

Can someone help me?

Here I put an example that reproduces my problem

\documentclass[a4paper,12pt,twoside,openany]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[lighttt]{lmodern}
\usepackage[a4paper,top=2.50cm,bottom=2.50cm,left=2.50cm,right=2.50cm]{geometry}

\usepackage{amsmath,amssymb,commath,nccmath}
    \numberwithin{equation}{section}
\usepackage{siunitx}
\usepackage{physics}

\usepackage{float}
\usepackage{wrapfig}

\usepackage[pdftex]{color}
\usepackage{xcolor}
\usepackage{hyperref}
    \hypersetup{
        unicode=false,          % non-Latin characters in Acrobat’s bookmarks
        pdftoolbar=true,        % show Acrobat’s toolbar?
        pdfmenubar=true,        % show Acrobat’s menu?
        pdffitwindow=false,     % window fit to page when opened
        pdfstartview={FitH},    % fits the width of the page to the window
        pdftitle={My title},    % title
        pdfauthor={Author},     % author
        pdfsubject={Subject},   % subject of the document
        pdfcreator={Creator},   % creator of the document
        pdfproducer={Producer}, % producer of the document
        pdfkeywords={keyword1, key2, key3}, % list of keywords
        pdfnewwindow=true,      % links in new PDF window
        colorlinks=false,       % false: boxed links; true: colored links
        linkcolor=cyan,         % color of internal links (change box color with linkbordercolor)
        linkbordercolor = blue,
        citecolor=green,        % color of links to bibliography
        filecolor=magenta,      % color of file links
        urlcolor=red            % color of external links
    }
\usepackage{textcomp}
\usepackage{setspace}
    \onehalfspacing
\usepackage{caption}    
    %caption customization
    \captionsetup {
        format=plain,
        width=0.80\textwidth,
        font=normal, 
        labelfont=bf,
        figurename = Fig. ,
        tablename = Tab.
    }

\usepackage{tikz}
\usepackage{circuitikz}

\usepackage{tabularx}
\usepackage{multirow}
\usepackage{multicol}

\usepackage[sorting=none]{biblatex}

\usepackage{fancyhdr}

    \fancypagestyle{mainmatter}{%
      \renewcommand{\headrulewidth}{.4pt}% Header rule
      \renewcommand{\footrulewidth}{0pt}% No Footer rule
      \fancyhf{}% Clear header/footer
      \fancyhead[LE]{\itshape\nouppercase\leftmark}
      \fancyhead[RO]{\itshape\nouppercase\rightmark}
      \fancyhead[RE,LO]{\thepage}% 
    }

    \fancypagestyle{plain}{%
        \fancyhf{} % clear all header and footer fields
        \fancyfoot[R]{\thepage}
        \fancyhead{} 
        \renewcommand{\headrulewidth}{0pt}
        \renewcommand{\footrulewidth}{0pt}
    }

    \raggedbottom

\usepackage{titlesec}

    \titleformat{name=\chapter}[display]
        {\Large\ttfamily}
        {{\chaptertitlename} \thechapter}
        {2ex}
        {\bfseries\filcenter\Huge 
    }

    \titleformat{\section}[block]
        {\ttfamily\bfseries\boldmath\Large}
        {\thesection}{1em}{}

    \titleformat{\subsection}[block]
        {\ttfamily\bfseries\large}
        {\thesubsection}{1em}{}

    \titlespacing{\chapter}{0pt}{-10pt}{40pt}

\DeclareSIUnit{\erg}{erg}
\DeclareSIUnit\CoolR{\erg \centi \metre \cubed \per \second}

\newcommand*\mathinhead[2]{\texorpdfstring{$#1$}{#2}}

\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}

\title{problem}
\date{May 2020}

\begin{document}

\maketitle

\chapter{Renormalization}
\section{Classical physics example}
In order the renormalize the potential, $V_D(y)$ might be expanded around the correct dimension of the problem $D = 1 + \epsilon$. Then, for $\epsilon\to 0$ one has:
\begin{equation}
\left\{
    \begin{aligned}\label{eq:3_expansion}
        \left(\frac{\mu}{y}\right)^{1-D} & = \exp(-\epsilon\ln\frac{\mu}{y}) = 1 - \epsilon\ln\frac{\mu}{y} + O(\epsilon^2)  \\
        \pi^{(D-1)/2} & = \exp(\frac{\epsilon}{2}\ln\pi) = 1 + \frac{\epsilon}{2}\ln\pi + O(\epsilon^2)\\
        \Gamma\left(\frac{1-D}{2}\right) & = -\frac{2}{\epsilon}\Gamma\left(1 - \frac{\epsilon}{2} \right) = -\frac{2}{\epsilon}\left(1 + \frac{\gamma}{2}\epsilon + O(\epsilon^2)\right)
    \end{aligned}
\right.
\end{equation}
where $\gamma$ is the Euler--Mascheroni constant and the last expansion is the same of \eqref{app:eq_gamma-exp}.



\appendix

\chapter{Special functions}
\section{\mathinhead{\Gamma}{gamma}-function} \label{app:gamma_func}

If $\epsilon \ll 1$
\begin{fleqn}
\begin{equation}\label{app:eq_gamma-exp}
\Gamma(1+\epsilon) = 1 - \gamma\epsilon + O(\epsilon^2)
\end{equation}
\end{fleqn}
\end{document}

I noticed that the following code does not reproduce the error but makes the new command \mathinhead undefined. Then, I think it's a packages problem but I don't know how to manage it.

\documentclass[a4paper,12pt,twoside,openany]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[lighttt]{lmodern}
\usepackage[a4paper,top=2.50cm,bottom=2.50cm,left=2.50cm,right=2.50cm]{geometry}

\usepackage{amsmath,amssymb,commath,nccmath}
    \numberwithin{equation}{section}
\usepackage{siunitx}
\usepackage{physics}

%\newcommand*\mathinhead[2]{\texorpdfstring{$#1$}{#2}}


\title{problem}
\date{May 2020}

\begin{document}

\maketitle

\chapter{Renormalization}
\section{Classical physics example}
In order the renormalize the potential, $V_D(y)$ might be expanded around the correct dimension of the problem $D = 1 + \epsilon$. Then, for $\epsilon\to 0$ one has:
\begin{equation}
\left\{
    \begin{aligned}\label{eq:3_expansion}
        \left(\frac{\mu}{y}\right)^{1-D} & = \exp(-\epsilon\ln\frac{\mu}{y}) = 1 - \epsilon\ln\frac{\mu}{y} + O(\epsilon^2)  \\
        \pi^{(D-1)/2} & = \exp(\frac{\epsilon}{2}\ln\pi) = 1 + \frac{\epsilon}{2}\ln\pi + O(\epsilon^2)\\
        \Gamma\left(\frac{1-D}{2}\right) & = -\frac{2}{\epsilon}\Gamma\left(1 - \frac{\epsilon}{2} \right) = -\frac{2}{\epsilon}\left(1 + \frac{\gamma}{2}\epsilon + O(\epsilon^2)\right)
    \end{aligned}
\right.
\end{equation}
where $\gamma$ is the Euler--Mascheroni constant and the last expansion is the same of \eqref{app:eq_gamma-exp}.



\appendix

\chapter{Special functions}
\section{\mathinhead{\Gamma}{gamma}-function} \label{app:gamma_func}

If $\epsilon \ll 1$
\begin{fleqn}
\begin{equation}\label{app:eq_gamma-exp}
\Gamma(1+\epsilon) = 1 - \gamma\epsilon + O(\epsilon^2)
\end{equation}
\end{fleqn}
\end{document}
6
  • 2
    Welcome! It's hard to tell what's causing the problem without having a complete example. Can you make your example compilable? It should begin with \documentclass{...} and end with \end{document}, and (of course) it should reproduce your problem.
    – Vincent
    May 14, 2020 at 20:33
  • Okay, thank you for your answers! I've just edit the post :) Doing that,I find that the problem is in a package conflict, but I don't know how to solve it.
    – mcp
    May 14, 2020 at 20:56
  • How about removing the equation environment, so it's just an fleqn environment?
    – Werner
    May 14, 2020 at 21:38
  • Removing equation environment doesn't work and it gives me another error ("missing $ inserted")
    – mcp
    May 14, 2020 at 21:54
  • The problem is in the hyperref packages; if I remove it i have the correct refering but then i don't have the hyper link and i cannot use the \textorpdfstring command
    – mcp
    May 14, 2020 at 22:18

2 Answers 2

1

Invert your use of equation and fleqn. That is, use

If $\epsilon \ll 1$,
\begin{equation}
  \begin{fleqn}
    \Gamma(1 + \epsilon) = 1 - \gamma\epsilon + O(\epsilon^2)
    \label{app:eq_gamma-exp}
  \end{fleqn}
\end{equation}

enter image description here

1
  • Oh wow, it works perfectly! Thank you. However, I must invert also the environment align and fleqn?
    – mcp
    May 15, 2020 at 12:48
0

This answer is WRONG. Refer to comments made by @egerg below.


  • According to nccmath: fleqn numbering, nccmath should be loaded after hyperref.
  • It seems that, in this case, amsmath should be loaded after hyperref as well. This means move any packages that implicitly load amsmath after hyperref.

Here is the adjusted (partial) order:

\usepackage{amssymb}
% ...

\usepackage{hyperref}
% ...

\usepackage{amsmath,commath,nccmath}
    \numberwithin{equation}{section}
\usepackage{physics}
6
  • I see the same exact behavior.
    – egreg
    May 14, 2020 at 23:06
  • @egreg Answer is updated. I excessively simplified the example before. May 14, 2020 at 23:19
  • Loading amsmath after hyperref is wrong: the latter makes adjustments based on previous loading of the former and with your code the behavior would be unpredictable.
    – egreg
    May 15, 2020 at 8:26
  • @egreg Hence this answer tex.stackexchange.com/a/170569/79060 is wrong as well? (nccmath loads amsmath) May 15, 2020 at 20:10
  • 1
    There's something hairy going on. :-( Yes, if one loads amsmath before hyperref and nccmath after it, the output is wrong. If I'm asked what I'd do, I'd simply discard nccmath.
    – egreg
    May 15, 2020 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .