0

I have a figure with some subfloats. The figure es something like that:

enter image description here

I have not each subfloat separately, I have a single picture.

For linking the picture with the reference in text I used hyperref:

\documentclass{article}
\usepackage{subfig}
\usepackage{hyperref}
\usepackage{graphicx}

\begin{document}

Figures \ref{Fig1a} and \ref{Fig1b} are in Figure \ref{Fig1}

\begin{figure}[htb]
\centering
\subfloat{
\includegraphics{example-image}
\label{Fig1a}
}
\subfloat{\label{Fig1b}}
\caption{Image description:
\textbf{(a)}~figure 1a and 
\textbf{(b)}~figure 1b
}
\label{Fig1}
\end{figure}
\end{document}

When I click on Fig1a and Fig1 in the .pdf document inmediatelly I am conduced to the figure, but when I click on Fig1b I'm conduced to the caption. How can I click on Fig1b and get conduced to the image and not to the caption?

  • 2
    The problem is that you're using subfig and it is known for its issues with hyperref. You could e.g. switch to subcaption. – TeXnician Jul 12 '17 at 15:48
  • It's not exactly a solution, but if you put \leavevmode in front of the first \subfloat, it will also go to the bottom (same as the second). – John Kormylo Jul 12 '17 at 16:38
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Sep 26 '17 at 16:40
1

The problem is how to get the second \subfloat into vmode, since that only happens at the end of a line. Then I thought, a minipage effectively starts a new page (in vmode).

Of course, putting a \subfloat inside a minipage is sort of redundant, since it basically is a minipage.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{hyperref}

\begin{document}

Figures \ref{Fig1a} and \ref{Fig1b} are in Figure \ref{Fig1}

\begin{figure}[htb]
\centering
\subfloat{
  \includegraphics[width={\dimexpr 0.5\textwidth-0.5\columnsep}]{example-image-a}
  \label{Fig1a}
}\hfil
\begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep}
  \subfloat{
    \includegraphics[width=\textwidth]{example-image-b}
    \label{Fig1b}
  }
\end{minipage}
\caption{Image description:
\textbf{(a)}~figure 1a and 
\textbf{(b)}~figure 1b
}
\label{Fig1}
\end{figure}
\end{document}

This solution uses minipages only. It still uses some definitions from the subfig package.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{hyperref}

\makeatletter
\newcommand{\stepsubfigure}{%
  \advance\c@figure by 1 %local
  \refstepcounter{subfigure}%
}
\makeatother

\begin{document}

Figures \ref{Fig1a} and \ref{Fig1b} are in Figure \ref{Fig1}

\begin{figure}[htb]
\begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep}
  \stepsubfigure
  \includegraphics[width=\textwidth]{example-image-a}
  \label{Fig1a}
\end{minipage}\hfill
\begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep}
  \stepsubfigure
  \includegraphics[width=\textwidth]{example-image-b}
  \label{Fig1b}
\end{minipage}
\caption{Image description:
\textbf{(a)}~figure 1a and 
\textbf{(b)}~figure 1b
}
\label{Fig1} 
\end{figure}
\end{document}
  • it works, but duplicated th image. Supose that the image already has the image a and the image b – Daniel Valencia C. Jul 12 '17 at 17:18
  • I added the image to the second \subfloat so that it would actually have some height. – John Kormylo Jul 13 '17 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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