8

I have used the 'cleveref' package for a large document. It contains a lot of (tikz) figures and the 'scrreprt' class is used.

\documentclass[a4paper, onecolumn, twoside, openright, titlepage, DIV=calc, BCOR=1cm, headinclude=false,footinclude=false, draft, captions=topbeside]{scrreprt}

I'd like to place figure captions in outer margins of the pages. I tried to use the 'floatrow' package and the 'captionbeside' environment for this purpose.

KOMA-Script and sidenotes : how to format side (margin) caption and its caption label?

'cleveref' can not recognise the labels of figures and tables anymore afterwards. I can guess that this is related to some kind of changed 'labelling' but am not able to find a solution.

Would you please advice me on how to address this issue?

Chr.

EDIT: I have added this example:

\documentclass[captions=topbeside]{scrreprt}

\usepackage{graphicx}
\usepackage{cleveref}

\begin{document}
\begin{figure}[!htb]
\begin{captionbeside}{caption1}
[o]{\includegraphics[width=3cm]{example-image-a}}
\end{captionbeside}\label{fig:fig_1}
\end{figure}

\begin{figure}[!htb]
\begin{captionbeside}{caption2}
[o]{\includegraphics[width=3cm]{example-image-a}}
\end{captionbeside}\caption{caption2}\label{fig:fig_2}
\end{figure}

\begin{figure}[!htb]
\includegraphics[width=3cm]{example-image-a}
\caption{caption3}\label{fig:fig_3}
\end{figure}

\cref{fig:fig_1}, \cref{fig:fig_2}, \cref{fig:fig_3}.
\end{document}
3
  • 5
    Welcome to TeX.SE. Many thanks for listing all options being passed to the document class. To really diagnose what's going on, let alone provide a fix, it would be most helpful if you provided an MWE that generates the problem behavior you've encountered.
    – Mico
    Aug 6, 2016 at 13:42
  • I encountered the same problem when using the tufte classes several years back.
    – JPi
    Aug 6, 2016 at 14:57
  • I added an example. \ref{} can access the 'hidden' (for \cref{}) 'counter'.
    – user111486
    Aug 6, 2016 at 15:32

1 Answer 1

9

Setting the label in the caption argument works for me:

\begin{captionbeside}
  {caption1\label{fig:fig_1}}

Here is a twosided example, but I am not sure how the pictures and the captions should be positioned:

\documentclass
  [
    captions=topbeside,
    twoside
  ]
  {scrreprt}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif

\usepackage{graphicx}
\usepackage{cleveref}

\usepackage{etoolbox}
\BeforeBeginEnvironment{captionbeside}{%
  \setcapindent*{0pt}%
  \Ifthispageodd
    {\addtokomafont{caption}{\raggedright}}
    {\addtokomafont{caption}{\raggedleft}}%
}


\usepackage{lipsum}% dummy text
%\usepackage{showframe}% shows the page layout

\begin{document}
\chapter{A chapter}
\lipsum[1]
\begin{figure}[htb]
  \setcapindent*{0pt}
  \begin{captionbeside}
    {caption1\label{fig:fig_1}}
    [o]
    [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]
    [0pt]*
    \raisebox
      {\dimexpr\ht\strutbox-\totalheight\relax}
      {\makebox
        [\textwidth]
        [c]
        {\includegraphics[width=3cm]{example-image-a}%
      }%
    }
  \end{captionbeside}
\end{figure}

\begin{figure}[!htb]
\begin{captionbeside}
  {caption2\label{fig:fig_2}}
  [o]
  \includegraphics[width=3cm]{example-image-a}
\end{captionbeside}
\end{figure}


\cref{fig:fig_1}, \cref{fig:fig_2}, \cref{fig:fig_3}.

\clearpage
\lipsum[1]
\begin{figure}[htb]
  \setcapindent*{0pt}
  \begin{captionbeside}
    {caption1\label{fig:fig_3}}
    [o]
    [\dimexpr\textwidth+\marginparwidth+\marginparsep\relax]
    [0pt]*
    \raisebox
      {\dimexpr\ht\strutbox-\totalheight\relax}
      {\makebox
        [\textwidth]
        [c]
        {\includegraphics[width=3cm]{example-image-a}%
      }%
    }
  \end{captionbeside}
\end{figure}
\end{document}

Note that \Ifthispageodd may need two runs.

Result:

enter image description here

enter image description here

1
  • @user111486: Instead of saying thank you consider to accept this answer and upvote it (you've more than 15 rep, you can upvote by now!)
    – user31729
    Aug 6, 2016 at 21:26

You must log in to answer this question.

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