0

I have a .text homework with lots of images and tables, this ones are well numerated below the figure and table but when I refer these in the text dont show the number of the table or figure instead of two questions mark symbols. I haven't got this problem with the equations, How can I solve it?

I write below the code;

\documentclass[11pt,onside]{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{bm}
\usepackage{upgreek}

\usepackage{graphicx}
\usepackage{longtable}



\usepackage{amsmath}
% mathtools for: Aboxed (put box on last equation in align envirenment)
\usepackage{microtype} %improves the spacing between words and letters

%% COLOR DEFINITIONS

\usepackage[svgnames]{xcolor} % Enabling mixing colors and color's call by 'svgnames'

\definecolor{MyColor1}{rgb}{0.2,0.4,0.6} %mix personal color
\newcommand{\textb}{\color{Black} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\blue}{\color{MyColor1} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\blueb}{\color{MyColor1} \usefont{OT1}{lmss}{b}{n}}
\newcommand{\red}{\color{LightCoral} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\green}{\color{Turquoise} \usefont{OT1}{lmss}{m}{n}}

\DeclareMathOperator{\trace}{trace}
\DeclareMathOperator{\diag}{diag}

%% FONTS AND COLORS

%    SECTIONS

\usepackage{titlesec}
\usepackage{sectsty}
%%%%%%%%%%%%%%%%%%%%%%%%
%set section/subsections HEADINGS font and color
\sectionfont{\color{MyColor1}}  % sets colour of sections
\subsectionfont{\color{MyColor1}}  % sets colour of sections
\subsubsectionfont{\color{MyColor1}}  % sets colour of sections

%set section enumerator to arabic number (see footnotes markings alternatives)
\renewcommand\thesection{\arabic{section}.} %define sections numbering
\renewcommand\thesubsection{\thesection\arabic{subsection}} %subsec.num.


%define new section style
\newcommand{\mysection}{
\titleformat{\section} [runin] {\usefont{OT1}{lmss}{b}{n}\color{MyColor1}} 
{\thesection} {3pt} {} } 


%   CAPTIONS
\usepackage{caption}
\usepackage{subcaption}
%%%%%%%%%%%%%%%%%%%%%%%%
\captionsetup[figure]{labelfont={color=Turquoise}}
\captionsetup[table]{labelfont={color=Turquoise}}

%       !!!EQUATION (ARRAY) --> USING ALIGN INSTEAD
%using amsmath package to redefine eq. numeration (1.1, 1.2, ...) 
\renewcommand{\theequation}{\thesection\arabic{equation}}



\makeatletter
\let\reftagform@=\tagform@
\def\tagform@#1{\maketag@@@{(\ignorespaces\textcolor{red}{#1}\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\reftagform@{\ref{#1}}}}
\makeatother
\usepackage{hyperref}
\hypersetup{colorlinks=true}

% For labeling top of page on every page but first one:
\usepackage{fancyhdr}


\renewcommand{\rmdefault}{phv} % Arial Font
\renewcommand{\sfdefault}{phv} % Arial Font


\begin{document}

\renewcommand{\tablename}{Tabla} 
\renewcommand{\figurename}{Figura}
%\renewcommand\thefigure{\arabic{section}.\arabic{figure}} % Genera numeración X.Y
%\renewcommand\thetable{\arabic{section}.\arabic{table}} % Genera numeración X.Y
\numberwithin{figure}{section} %Hace que la primera figura de cada sección X sea X.1
\numberwithin{table}{section} %Hace que la primera tabla de cada sección X sea X.1


\maketitle

The code with an example of figure;

\documentclass[11pt,onside]{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{bm}
\usepackage{upgreek}

\usepackage{graphicx}
\usepackage{longtable}



\usepackage{amsmath}
% mathtools for: Aboxed (put box on last equation in align envirenment)
\usepackage{microtype} %improves the spacing between words and letters

%% COLOR DEFINITIONS

\usepackage[svgnames]{xcolor} % Enabling mixing colors and color's call by 'svgnames'

\definecolor{MyColor1}{rgb}{0.2,0.4,0.6} %mix personal color
\newcommand{\textb}{\color{Black} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\blue}{\color{MyColor1} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\blueb}{\color{MyColor1} \usefont{OT1}{lmss}{b}{n}}
\newcommand{\red}{\color{LightCoral} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\green}{\color{Turquoise} \usefont{OT1}{lmss}{m}{n}}

\DeclareMathOperator{\trace}{trace}
\DeclareMathOperator{\diag}{diag}

%% FONTS AND COLORS

%    SECTIONS

\usepackage{titlesec}
\usepackage{sectsty}
%%%%%%%%%%%%%%%%%%%%%%%%
%set section/subsections HEADINGS font and color
\sectionfont{\color{MyColor1}}  % sets colour of sections
\subsectionfont{\color{MyColor1}}  % sets colour of sections
\subsubsectionfont{\color{MyColor1}}  % sets colour of sections

%set section enumerator to arabic number (see footnotes markings alternatives)
\renewcommand\thesection{\arabic{section}.} %define sections numbering
\renewcommand\thesubsection{\thesection\arabic{subsection}} %subsec.num.


%define new section style
\newcommand{\mysection}{
\titleformat{\section} [runin] {\usefont{OT1}{lmss}{b}{n}\color{MyColor1}} 
{\thesection} {3pt} {} } 


%   CAPTIONS
\usepackage{caption}
\usepackage{subcaption}
%%%%%%%%%%%%%%%%%%%%%%%%
\captionsetup[figure]{labelfont={color=Turquoise}}
\captionsetup[table]{labelfont={color=Turquoise}}

%       !!!EQUATION (ARRAY) --> USING ALIGN INSTEAD
%using amsmath package to redefine eq. numeration (1.1, 1.2, ...) 
\renewcommand{\theequation}{\thesection\arabic{equation}}



\makeatletter
\let\reftagform@=\tagform@
\def\tagform@#1{\maketag@@@{(\ignorespaces\textcolor{red}{#1}\unskip\@@italiccorr)}}
\renewcommand{\eqref}[1]{\textup{\reftagform@{\ref{#1}}}}
\makeatother
\usepackage{hyperref}
\hypersetup{colorlinks=true}

% For labeling top of page on every page but first one:
\usepackage{fancyhdr}


\renewcommand{\rmdefault}{phv} % Arial Font
\renewcommand{\sfdefault}{phv} % Arial Font




\begin{document}

\renewcommand{\tablename}{Tabla} 
\renewcommand{\figurename}{Figura}
%\renewcommand\thefigure{\arabic{section}.\arabic{figure}} % Genera numeración X.Y
%\renewcommand\thetable{\arabic{section}.\arabic{table}} % Genera numeración X.Y
\numberwithin{figure}{section} %Hace que la primera figura de cada sección X sea X.1
\numberwithin{table}{section} %Hace que la primera tabla de cada sección X sea X.1


\maketitle



\section{section 1}

Es es un ejemplo podemos ver la Figura \ref{etiqueta_archivo}.

\begin{figure}[!htbp]
\label{etiqueta_archivo}
\begin{center}
\includegraphics[scale=0.45]{nnombre_archivo}
\end{center}
\caption{dedescripcion figura.}
\end{figure}

\end{document}
Martin Scharrer
  • 262,582
  • 2
    ?? is the expected output on the first run, have you run latex enough times to resolve the references? – David Carlisle Jan 06 '19 at 18:14
  • Is there more code? You don't have an \end{document} or any figures provided. – whatisit Jan 06 '19 at 19:41
  • David Carlisle. yes, I have run many times but the question marks keep appearing. – user178955 Jan 06 '19 at 20:11
  • whatisit. Yeah there is more code, I have wrote only the header, but i have text, figures, tables , equarions and it finish with an \end{document} – user178955 Jan 06 '19 at 20:13
  • @user178955: Well, it would pretty useful if you would the minimal version of your document that has this issue, i.e. throw all packages and code that is not relevant for the particular problem that the references show up as ??. Have you considered David Carlisle's comment about compiling more than once as well? –  Jan 06 '19 at 20:24
  • 1
    if you get ?? after multiple runs then there is an error in your code but if you do not show that no one can help you. start from a copy of your document, delete everything except the place where you have the \label and the place where you refer to that label with \ref and you should end up with a small one-page document that shows the problem and you can add to your question. If you delete something and the problem goes, then you have found the solution yourself.... – David Carlisle Jan 06 '19 at 23:48
  • 1
    none of the code that you show above is related to referencing figures so it does not help anyone answer your question. – David Carlisle Jan 06 '19 at 23:50

1 Answers1

3

You need to place the \label command after (or in) \caption (I also had to add a \title in order to compile your code)

Unrelated to the problem, but instead of \begin{center}...\end{center} inside a figure environment, it is better to use \centering to avoid additional vertical spaces.

\documentclass[11pt,onside]{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{bm}
\usepackage{upgreek}

\usepackage{graphicx}
\usepackage{longtable}



\usepackage{amsmath}
% mathtools for: Aboxed (put box on last equation in align envirenment)
\usepackage{microtype} %improves the spacing between words and letters

%% COLOR DEFINITIONS

\usepackage[svgnames]{xcolor} % Enabling mixing colors and color's call by 'svgnames'

\definecolor{MyColor1}{rgb}{0.2,0.4,0.6} %mix personal color
\newcommand{\textb}{\color{Black} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\blue}{\color{MyColor1} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\blueb}{\color{MyColor1} \usefont{OT1}{lmss}{b}{n}}
\newcommand{\red}{\color{LightCoral} \usefont{OT1}{lmss}{m}{n}}
\newcommand{\green}{\color{Turquoise} \usefont{OT1}{lmss}{m}{n}}

\DeclareMathOperator{\trace}{trace}
\DeclareMathOperator{\diag}{diag}

%% FONTS AND COLORS

%    SECTIONS

\usepackage{titlesec}
\usepackage{sectsty}
%%%%%%%%%%%%%%%%%%%%%%%%
%set section/subsections HEADINGS font and color
\sectionfont{\color{MyColor1}}  % sets colour of sections
\subsectionfont{\color{MyColor1}}  % sets colour of sections
\subsubsectionfont{\color{MyColor1}}  % sets colour of sections

%set section enumerator to arabic number (see footnotes markings alternatives)
%\renewcommand\thesection{\arabic{section}.} %define sections numbering
%\renewcommand\thesubsection{\thesection\arabic{subsection}} %subsec.num.


%define new section style
\newcommand{\mysection}{
\titleformat{\section} [runin] {\usefont{OT1}{lmss}{b}{n}\color{MyColor1}} 
{\thesection} {3pt} {} } 


%   CAPTIONS
\usepackage{caption}
\usepackage{subcaption}
%%%%%%%%%%%%%%%%%%%%%%%%
\captionsetup[figure]{labelfont={color=Turquoise}}
\captionsetup[table]{labelfont={color=Turquoise}}

%       !!!EQUATION (ARRAY) --> USING ALIGN INSTEAD
%using amsmath package to redefine eq. numeration (1.1, 1.2, ...) 
%\renewcommand{\theequation}{\thesection\arabic{equation}}


%
%\makeatletter
%\let\reftagform@=\tagform@
%\def\tagform@#1{\maketag@@@{(\ignorespaces\textcolor{red}{#1}\unskip\@@italiccorr)}}
%\renewcommand{\eqref}[1]{\textup{\reftagform@{\ref{#1}}}}
%\makeatother
\usepackage{hyperref}
\hypersetup{colorlinks=true}

% For labeling top of page on every page but first one:
\usepackage{fancyhdr}


\renewcommand{\rmdefault}{phv} % Arial Font
\renewcommand{\sfdefault}{phv} % Arial Font


\renewcommand{\tablename}{Tabla} 
\renewcommand{\figurename}{Figura}
%\renewcommand\thefigure{\arabic{section}.\arabic{figure}} % Genera numeración X.Y
%\renewcommand\thetable{\arabic{section}.\arabic{table}} % Genera numeración X.Y
\numberwithin{figure}{section} %Hace que la primera figura de cada sección X sea X.1
\numberwithin{table}{section} %Hace que la primera tabla de cada sección X sea X.1
\numberwithin{equation}{section} %Hace que la primera tabla de cada 

\title{text}

\begin{document}



\maketitle



\section{section 1}

\subsection{title}

Equation \ref{foo}

Es es un ejemplo podemos ver la Figura \ref{etiqueta_archivo}.

\begin{figure}[!htbp]
%\begin{center}
\centering
\includegraphics[scale=0.45]{example-image-duck}
%\end{center}
\caption{dedescripcion figura.}\label{etiqueta_archivo}
\end{figure}

\begin{equation}
a^{2} + b^{2} = c^{2}
\label{foo}
\end{equation}

\end{document}

enter image description here

  • samcarter. You are right. Thanks so much!!! Watching another problem I dont know why LaTeX writes two points in the figure numeration, This is Figure 1..1 – user178955 Jan 07 '19 at 17:51
  • @user178955 You add the additional period in the command \renewcommand\thesection{\arabic{section}.}. If you want only one period, remove this definition. – samcarter_is_at_topanswers.xyz Jan 07 '19 at 19:20
  • @user178955 I updated my code. If I remove the redefinitions of \thesection and \thesubsection I get a period between section and subsection number as expected. – samcarter_is_at_topanswers.xyz Jan 07 '19 at 23:56
  • @user178955 well, same as for section and subsection: remove the line with \renewcommand{\theequation}... -> maybe you notice some pattern emerging: changing the appearance by changing \the<whatever> is not a good idea. In addition you should make the equation counter also to be numbered with each section if you want the section number to be part of the label. – samcarter_is_at_topanswers.xyz Jan 09 '19 at 00:27