tcolorbox:如何将阴影添加到带有框标题的整个框中?

tcolorbox:如何将阴影添加到带有框标题的整个框中?

我正在合作tcolorbox制作方框并突出显示带有问题的文件的答案。

下面的 MWE 显示了我创建的框,将标题分成另一个框。

\documentclass[12pt]{article}
\usepackage[papersize={5.5in,8.5in},margin=1.5cm]{geometry}

\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\tcbuselibrary{skins}

\newtcolorbox{resp}[1][]{%
    enhanced jigsaw,%
    colback=gray!20!white,%
    colframe=gray!80!black,%
    size=small,%
    boxrule=1pt,%
    title=\textbf{\textit{Answer}},%
    halign title=flush center,%
    coltitle=black,%
    breakable,%
    drop shadow=black!50!white,%
    attach boxed title to top left={xshift=1cm,yshift=-\tcboxedtitleheight/2,yshifttext=-\tcboxedtitleheight/2},%
    minipage boxed title=3cm,%
    boxed title style={%
        colback=white,%
        size=fbox,%
        boxrule=1pt,%
        boxsep=2pt,%
        underlay={%
            \coordinate (dotA) at ($(interior.west) + (-0.5pt,0)$);
            \coordinate (dotB) at ($(interior.east) + (0.5pt,0)$);
            \begin{scope}[gray!80!black]
                \fill (dotA) circle (2pt);
                \fill (dotB) circle (2pt);
            \end{scope}
        }%
    },%
  #1%
}

\begin{document}
  \begin{resp}
    An exciting text {\ttfamily:)}
  \end{resp}
  \vspace{1cm}
  \begin{resp}[boxed title style={drop shadow=black!50!white}]
    Another box with shadow {\ttfamily:/}
  \end{resp}
\end{document}

上述代码的编译结果:

编译上述 MWE 代码的结果

感谢文档,我可以为文本框(没有标题的文本框)添加阴影,并且如第二个框所示,我可以对第二个框执行相同操作。不幸的是,标题框阴影与文本框重叠,我希望它与文本框阴影处于同一水平(即在文本框后面)。

我怎样才能将阴影应用于两个框作为一个组,以便标题和文本框的阴影可以合二为一,并位于文本框后面?

答案1

类似这样?您可以调整设置来改善匹配。这只是方法的说明。

带标题和阴影的框

\documentclass[12pt]{article}
\usepackage[papersize={5.5in,8.5in},margin=1.5cm]{geometry}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc,shadows.blur}
\tcbuselibrary{skins}
\newtcolorbox{resp}[1][]{%
  enhanced jigsaw,
  colback=gray!20!white,%
  colframe=gray!80!black,
  size=small,
  boxrule=1pt,
  title=\textbf{\textit{Answer}},
  halign title=flush center,
  coltitle=black,
  breakable,
  drop shadow=black!50!white,
  attach boxed title to top left={xshift=1cm,yshift=-\tcboxedtitleheight/2,yshifttext=-\tcboxedtitleheight/2},
  minipage boxed title=3cm,
  boxed title style={%
    colback=white,
    size=fbox,
    boxrule=1pt,
    boxsep=2pt,
    underlay={%
      \coordinate (dotA) at ($(interior.west) + (-0.5pt,0)$);
      \coordinate (dotB) at ($(interior.east) + (0.5pt,0)$);
      \begin{scope}
        \clip (interior.north west) rectangle ([xshift=3ex]interior.east);
        \filldraw [white, blur shadow={shadow opacity=60, shadow yshift=-.75ex}, rounded corners=2pt] (interior.north west) rectangle (interior.south east);
      \end{scope}
      \begin{scope}[gray!80!black]
        \fill (dotA) circle (2pt);
        \fill (dotB) circle (2pt);
      \end{scope}
    },
  },
  #1,
}

\begin{document}
\begin{resp}
  An box with a shadow {\ttfamily:)}
\end{resp}
\end{document}

相关内容