2

I'm trying to create an environment that provides a framed box within a report. My current problems are:

  1. The interparagraph spacing does not match the body text spacing (the space within the box is small)
  2. The box caption prints but can't be cross-referenced (the labels aren't getting through)

\documentclass[parskip=half,twocolumn,landscape]{scrreprt}
\usepackage{lipsum}
\usepackage{caption,mdframed,newfloat,xcolor}
\usepackage{varioref}
\usepackage{cleveref}

\setkomafont{disposition}{\bfseries\color{orange}}

\RedeclareSectionCommand[
  beforeskip=-.75\baselineskip,
  afterskip=.5\baselineskip]{subsection}


\definecolor{orangeBackground}{RGB}{254,240,222}
\DeclareCaptionFont{orange}{\color{orange}}

\DeclareFloatingEnvironment[fileext=frm,placement={!ht},name=Box]{smallboxfloat}
\mdfdefinestyle{aFrameBox}{%
    linecolor=orange,
    nobreak=true, % prevents page breaking
    outerlinewidth=0.5pt,
    innertopmargin=0.5\baselineskip,
    innerbottommargin=\baselineskip,
    innerrightmargin=11pt,
    innerleftmargin=11pt,
    backgroundcolor=orangeBackground
    }

\newenvironment{smallbox}[2]{%
\begin{smallboxfloat}
\begin{mdframed}[style=aFrameBox]%
 \captionsetup{labelfont={bf,orange}, font={bf,orange}, format=plain,justification=justified,singlelinecheck=false}
 \caption{#1}\label{#2}
}{\end{mdframed}\end{smallboxfloat}}   

\begin{document}
 \begin{smallbox}{Box title}{box:label}
  \lipsum[1-2]
 \end{smallbox}
 \subsection{Title}
 \lipsum[1-2] \Vref{box:label}


\end{document}
1
  • I believe, that varioref and cleveref are not getting well with each other. I think cleveref itself is enough.
    – user31729
    Apr 15, 2015 at 3:24

1 Answer 1

1

I am not that familiar with cleveref but think what you need is

\crefname{smallboxfloat}{Box}{Boxes}
\Crefname{smallboxfloat}{Box}{Boxes}

so that cleveref knows how to refer to the smallbox environment.

The paragraph spacing is due to the fact that mdframed uses a minipage which sets \parskip to zero. This can be fixed by saving the value of \parskip before the smallboxfloat environment:

\setlength{\currentparskip}{\parskip}

and then restoring it once you are in the smallboxfloat environment:

\setlength{\parskip}{\currentparskip}

References:

enter image description here

Code:

\documentclass[parskip=half,twocolumn,landscape]{scrreprt}
\usepackage{lipsum}
\usepackage{caption,mdframed,newfloat,xcolor}
\usepackage{varioref}
\usepackage{cleveref}

\setkomafont{disposition}{\bfseries\color{orange}}
\crefname{smallboxfloat}{Box}{Boxes}
\Crefname{smallboxfloat}{Box}{Boxes}
%\RedeclareSectionCommand[
%  beforeskip=-.75\baselineskip,
%  afterskip=.5\baselineskip]{subsection}





\definecolor{orangeBackground}{RGB}{254,240,222}
\DeclareCaptionFont{orange}{\color{orange}}

\DeclareFloatingEnvironment[fileext=frm,placement={!ht},name=Box]{smallboxfloat}
\crefalias{⟨counter ⟩}{⟨type ⟩}
\mdfdefinestyle{aFrameBox}{%
    linecolor=orange,
    nobreak=true, % prevents page breaking
    outerlinewidth=0.5pt,
    innertopmargin=0.5\baselineskip,
    innerbottommargin=\baselineskip,
    innerrightmargin=11pt,
    innerleftmargin=11pt,
    backgroundcolor=orangeBackground
    }

\newlength{\currentparskip}%
\newenvironment{smallbox}[2]{%
\setlength{\currentparskip}{\parskip}% save the value
\begin{smallboxfloat}
\begin{mdframed}[style=aFrameBox]%
\setlength{\parskip}{\currentparskip}% restore the value
 \captionsetup{labelfont={bf,orange}, font={bf,orange}, format=plain,justification=justified,singlelinecheck=false}
 \caption{#1}\label{#2}
}{\end{mdframed}\end{smallboxfloat}}   

\begin{document}
 \begin{smallbox}{Box title}{box:label}
  \lipsum[1-2]
 \end{smallbox}
 \subsection{Title}
 \lipsum[1-2] \Vref{box:label}


\end{document}
2
  • What are the symbols in the argument for \crefalias?
    – Hugh
    Apr 15, 2015 at 7:35
  • @Hugh: That should be a separate question if it is not clear from the documentation. That way it can be helpful to more people as an answer for that is unlikely to be able to be easily located if it is buried in an answer regarding mdframed. Apr 15, 2015 at 22:59

You must log in to answer this question.

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