mdframed 框、交叉引用、段落间距

mdframed 框、交叉引用、段落间距

我正在尝试创建一个在报告中提供框架的环境。我目前的问题是:

  1. 段落间距与正文间距不匹配(框内空间较小)
  2. 盒子标题可以打印,但无法交叉引用(标签无法传递)

\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

我不太熟悉,cleveref但我认为你需要的是

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

这样就cleveref知道如何引用环境smallbox了。

段落间距是由于mdframed使用了minipage设置为零的。可以通过在环境之前\parskip保存的值来修复此问题:\parskipsmallboxfloat

\setlength{\currentparskip}{\parskip}

然后进入smallboxfloat环境后再恢复它:

\setlength{\parskip}{\currentparskip}

参考:

在此处输入图片描述

代码:

\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}

相关内容