3

I have a problem with cleveref. Apparently, it does not work with mdframed.

\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2.50cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\usepackage{xcolor}
% Definition of colors
\definecolor{toc_heading}{RGB}{0 51 89}
\definecolor{toc}{RGB}{0 119 138}
\definecolor{section}{RGB}{0 113 187}
\definecolor{subsection}{RGB}{0 115 207}
\definecolor{headline}{RGB}{77 112 139}
\definecolor{citecolor}{RGB}{0 124 48}

\usepackage{amsthm}

\usepackage[framemethod=TikZ]{mdframed}
\mdfsetup{skipbelow=3ex}
\newtheorem{dummy}{dummy}[chapter]


\newmdtheoremenv [%
 hidealllines=true, leftline=true,
 linewidth = 2pt,  linecolor=section,
 leftmargin = 0,rightmargin = 0,%
 skipabove=\dimexpr\parskip+10pt\relax,
 innertopmargin = 0,splittopskip =3ex,
 innerrightmargin=2ex,splitbottomskip=3ex,innerbottommargin=2ex,
 ntheorem = false ,backgroundcolor=section!20%
]{theorem}[dummy]{Theorem}
\usepackage{hyperref}
\usepackage{cleveref}
\crefname{theorem}{theorem}{theorems}
\begin{document}
\chapter{Chapter 1}
\begin{theorem}\label{thm:1}    bla
\end{theorem}
 This is \cref{thm:1}.

\end{document}

This code produces: This is ?? 1.1.

Has anyone encountered a similar problem?

1
  • I suggest to use the more versatile tcolorbox package which has built-in support for cleveref
    – user31729
    Dec 12, 2017 at 20:44

1 Answer 1

4

The usage of \newmdtheoremenv is too early, 'fixing' the cross-reference format already before cleveref can apply with its own version of \label etc.

The definition of theorem must be shifted after loading of cleveref.

\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2.50cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}
\usepackage{xcolor}
% Definition of colors
\definecolor{toc_heading}{RGB}{0 51 89}
\definecolor{toc}{RGB}{0 119 138}
\definecolor{section}{RGB}{0 113 187}
\definecolor{subsection}{RGB}{0 115 207}
\definecolor{headline}{RGB}{77 112 139}
\definecolor{citecolor}{RGB}{0 124 48}

\usepackage{amsthm}

\usepackage[framemethod=TikZ]{mdframed}
\mdfsetup{skipbelow=3ex}
\newtheorem{dummy}{dummy}[chapter]


\usepackage{hyperref}
\usepackage{cleveref}


\newmdtheoremenv [%
 hidealllines=true, leftline=true,
 linewidth = 2pt,  linecolor=section,
 leftmargin = 0,rightmargin = 0,%
 skipabove=\dimexpr\parskip+10pt\relax,
 innertopmargin = 0,splittopskip =3ex,
 innerrightmargin=2ex,splitbottomskip=3ex,innerbottommargin=2ex,
 ntheorem = false ,backgroundcolor=section!20%
]{theorem}[dummy]{Theorem}

\crefname{theorem}{theorem}{theorems}
\begin{document}
\chapter{Chapter 1}
\begin{theorem}\label{thm:1}    bla
\end{theorem}
 This is \cref{thm:1}.

\end{document}

enter image description here

2
  • That was easy. As you may have noticed, I am simply a mathematician without any deeper understanding of the tex compiling process. Thank you very much for your help.
    – julian
    Dec 12, 2017 at 20:48
  • 1
    @julian: You're welcome. Happy TeXing!
    – user31729
    Dec 12, 2017 at 21:11

You must log in to answer this question.

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