如何将徽标置于 tcolorbox 框架的中心?

如何将徽标置于 tcolorbox 框架的中心?
\documentclass{article}
\usepackage[tikz]{bclogo}
\usepackage[most]{tcolorbox}
\usepackage{varwidth}

\newtcolorbox{mybox}{
    enhanced, breakable,
    colbacktitle=green, fonttitle=\large\bfseries, title=My title,
    subtitle style={empty, coltext=black},
    colback=white,
    boxrule=0.2mm, leftrule=1.7cm,
    drop lifted shadow=green!80!black,
    frame style={top color=green!80, bottom color=green!80, middle color=green!40},
    overlay={\bclampe},
    attach boxed title to top left={xshift=1cm, yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,
    boxed title style={
        frame code={
            \path[fill=tcbcolback!30!black]
            ([yshift=-1mm, xshift=-1mm] frame.north west) arc[start angle=0, end angle=180, radius=1mm]
            ([yshift=-1mm, xshift=1mm] frame.north east) arc[start angle=180, end angle=0, radius=1mm];
            \path[left color=tcbcolback!60!black, right color=tcbcolback!60!black, middle color=tcbcolback!80!black!75]
            ([xshift=-2mm] frame.north west) -- ([xshift=2mm] frame.north east)
            [rounded corners=1mm] -- ([xshift=1mm, yshift=-1mm] frame.north east) -- (frame.south east) -- (frame.south west) -- 
            ([xshift=-1mm, yshift=-1mm] frame.north west) [sharp corners] -- cycle;
        },
        interior engine=empty
    }
}

\begin{document}
    \begin{mybox}
        My tcolorbox \\ My tcolorbox \\ My tcolorbox
    \end{mybox}
\end{document}

在此处输入图片描述

答案1

overlay={\bclampe}改为

overlay={
  \node[inner sep=0pt, xshift=.85cm, anchor=center] 
    at ($ (frame.north west)!.5!(frame.south west) $) {\bclampe};
}

其中xshift=.85cm是 的一半leftrule=1.7cm

完整示例

\documentclass{article}
\usepackage[tikz]{bclogo}
\usepackage[most]{tcolorbox}
\usepackage{varwidth}

\usetikzlibrary{calc}

\newtcolorbox{mybox}{
    enhanced, breakable,
    colbacktitle=green, fonttitle=\large\bfseries, title=My title,
    subtitle style={empty, coltext=black},
    colback=white,
    boxrule=0.2mm, leftrule=1.7cm,
    drop lifted shadow=green!80!black,
    frame style={top color=green!80, bottom color=green!80, middle color=green!40},
    overlay={
      \node[inner sep=0pt, xshift=.85cm, anchor=center] 
        at ($ (frame.north west)!.5!(frame.south west) $) {\bclampe};
    },
    attach boxed title to top left={xshift=1cm, yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,
    boxed title style={
        frame code={
            \path[fill=tcbcolback!30!black]
            ([yshift=-1mm, xshift=-1mm] frame.north west) arc[start angle=0, end angle=180, radius=1mm]
            ([yshift=-1mm, xshift=1mm] frame.north east) arc[start angle=180, end angle=0, radius=1mm];
            \path[left color=tcbcolback!60!black, right color=tcbcolback!60!black, middle color=tcbcolback!80!black!75]
            ([xshift=-2mm] frame.north west) -- ([xshift=2mm] frame.north east)
            [rounded corners=1mm] -- ([xshift=1mm, yshift=-1mm] frame.north east) -- (frame.south east) -- (frame.south west) -- 
            ([xshift=-1mm, yshift=-1mm] frame.north west) [sharp corners] -- cycle;
        },
        interior engine=empty
    }
}

\begin{document}
    \begin{mybox}
        My tcolorbox \\ My tcolorbox \\ My tcolorbox
    \end{mybox}
\end{document}

在此处输入图片描述

更新

要使logo在“框架高度-标题高度”的高度垂直居中,可以更改overlay={...}

overlay={
  \node[inner sep=0pt, xshift=.85cm, anchor=center] 
    at ($ (frame.north west|-title.south)!.5!(frame.south west) $) {\bclampe};
}

这里表示 tcolorbox 中标题的边界框,一个矩形节点。请参阅用户手册 中title选项的文档。geometry nodestcolorbox在此处输入图片描述

请注意,由于标题左侧有部分左侧规则,因此从视觉上看徽标未居中。例如,比0.5中的小一点可能会有所帮助。()!0.5!()0.45

相关内容