新环境在另一个环境中表现不同

新环境在另一个环境中表现不同

朋友们,

请看下面的代码。问题是环境在环境内部或直接在 下hlcard时表现不同。我直接从网上选择了卡环境,但不太清楚那些长的可选参数在做什么。请帮忙。cardframe

内部的行为frame是预期的行为

\documentclass[12pt]{beamer}
\usepackage[customcolors,shade]{hf-tikz}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes}
\RequirePackage[many]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\definecolor{BGgrey03}{RGB}{190,190,190}
\definecolor{BGgrey04}{RGB}{230,230,230}
\usecolortheme[named=dcol]{structure}
\usepackage{biblatex}

\tcbset{%
colback=BGgrey04, colbacktitle=dcol, coltitle=white, coltext=dcol,%
enhanced, sharpish corners=all,%
fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black!20!BGgrey03}, % top
fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black!40!BGgrey03}, % bottomSmall
fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black!20!BGgrey03}, % bottomBig
left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,%
title filled, boxrule=0mm, %
segmentation code={\path[draw=BGgrey01](segmentation.west) -- (segmentation.east);}%
}

\newenvironment{card}[1][pR23s2OTKY]{%
    \ifthenelse{\equal{#1}{pR23s2OTKY}}{%
      \begin{tcolorbox}%
    }{%
      \begin{tcolorbox}[colbacktitle=dcol, coltitle=white, title=#1, left=1mm, right=6mm, top=1mm,
        bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm, ]%
    }%
}{%
  \end{tcolorbox}%
}

\newenvironment{hlcard}[1][pR23s2OTKY]{%
      \begin{tcolorbox}[noparskip, breakable, colback=dcol,%
          coltitle=black,coltext=white, fonttitle={\bfseries \scshape}, left=1mm, right=6mm, top=1mm,
        bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm,]%
}{%
  \end{tcolorbox}%
}

\begin{document}
\begin{frame}
\begin{card}[Problem]
  \begin{hlcard}
    Foo
  \end{hlcard}
\end{card}
  \begin{hlcard}
    Bar
  \end{hlcard}
\end{frame}
\end{document}

在此处输入图片描述

答案1

\tcbset提供选项,即特定(或).style的集合,否则任何未“包装”在中的选项都将全局使用,并对“层”产生副作用tcolorboxtikz/pgfkeys.styletcolorbox

嵌套框reset使用默认设置和来自的全局值tcbset

我建议使用一种outerlayer样式和一种首先innerlayer调用outerlayer然后应用其自身设置的样式。

此外,应该用而不是将它们包装在宏中environments来定义。\newtcolorbox\newenvironment

\documentclass[12pt]{beamer}
\usepackage[customcolors,shade]{hf-tikz}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes}
\RequirePackage[many]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\definecolor{BGgrey03}{RGB}{190,190,190}
\definecolor{BGgrey04}{RGB}{230,230,230}
\usecolortheme[named=dcol]{structure}
\usepackage{biblatex}

% Common options
\tcbset{%
  left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{
  outerlayer/.style={
    enhanced,
    sharpish corners=all,
    colbacktitle=dcol, 
    coltitle=white, 
    left=1mm, 
    right=6mm, 
    top=1mm,
    bottom=1mm, 
    middle=4mm, 
    toptitle=1mm, 
    bottomtitle=1mm,
    fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black!20!BGgrey03}, % top
    fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black!40!BGgrey03}, % bottomSmall
    fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black!20!BGgrey03}, % bottomBig
    title filled, boxrule=0mm, %
    segmentation code={\path[draw=BGgrey01](segmentation.west) -- (segmentation.east);}
},
  innerlayer/.style={outerlayer,
    noparskip, 
    breakable, 
    colback=dcol,%
    coltitle=black,
    coltext=white, 
    fonttitle={\bfseries \scshape}, 
    bottomtitle=1mm}
}



\newtcolorbox{card}[1][]{%
  outerlayer,
  title=#1,
}


\newtcolorbox{hlcard}[1][]{%
  innerlayer,
  #1
}

\begin{document}
\begin{frame}
\begin{card}[Problem]
  \begin{hlcard}
    Foo
  \end{hlcard}
\end{card}
\begin{hlcard}
  Bar
\end{hlcard}
\end{frame}
\end{document}

在此处输入图片描述

相关内容