2

Is it possible to label a nofloat figure/graphic within an adjustbox environment such that the link (using hyperref) goes to the top of the figure instead to the caption below?

The figure must be placed within the itemize with correct centering (current linewidth, not whole textwidth of the document) for both the figure and the caption and additionally a nofloat such that the link goes to the top of the figure.

I get the warning: The option `hypcap=true' will be ignored for this(caption) particular \caption

\documentclass{article}
\usepackage{caption}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{hyperref}
\usepackage{adjustbox}

\begin{document}
    \begin{itemize}
        \item \Blindtext[1][2]\Blindtext[1]
        \begin{adjustbox}{
                center=\linewidth,
                caption=Some caption,
                label=a,
                nofloat=figure,
            }
            \begin{tikzpicture}
            \clip(-5.686675053232457,-3.16893917565149) rectangle (5.579414724686105,0.6921754200738994);
            \draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105]plot(\x,{(--4.514220105043796-1.8219356725415592*\x)/1.894960446786564});
            \draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--1.6188066144426525-1.0979714604086213*\x)/-0.3751399196759637});
            \draw [line width=1.2pt,dash pattern=on 4pt off 4pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--11.463481791986391--1.2426776436313691*\x)/-5.670646727250561});
            \draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(--0.4039090361160175--0.6586822831185679*\x)/-0.27723191082856635});
            \draw [line width=1.2pt,domain=-5.686675053232457:9.579414724686105] plot(\x,{(-2.9955647165449215--0.8716146065783191*\x)/4.89799733746727});    
            \end{tikzpicture}
        \end{adjustbox}
        \item \Blindtext[1] 
    \end{itemize}
see \ref{a}
\end{document}
Thrash
  • 653
  • The code used by adjustbox does not support this feature of other packages yet. I will add this support in the next version of the package. Thank you very much for pointing this out. – Martin Scharrer Dec 30 '18 at 09:38

1 Answers1

2

According to this answer one can define a new environment, which then behaves like a (nofloat) figure environment:

\newenvironment{Figure}
  {\par\medskip\noindent\minipage{\linewidth}%
   \captionsetup{type=figure}}% \captionsetup{type=figure} added
  {\endminipage\par\medskip}

This works now. It's not necessary to use adjustbox.

Thrash
  • 653
  • You could just redefine the adjnofloat environment used by adjustbox to create the nofloat. This possibility is explained in the package manual. Based on your code: \renewenvironment{adjnofloat}[1] {\par\medskip\noindent\minipage{\linewidth}\captionsetup{type=#1}} {\endminipage\par\medskip} – Martin Scharrer Dec 30 '18 at 09:36