Vertical alignment within tcolorbox using varwidth

tcolorboxvarwidth

I'm using tcolorbox to have a "warning" box. I'd like the "warning sign" to be at the very top of it, but it's not achieved even by using the [t] option of the varwidthenvironment.

Here's the MWE :

\documentclass[a4paper, 11pt]{report}
\usepackage[T1]{fontenc} % encoding
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\usepackage{varwidth}
\usepackage{lipsum}

\newenvironment{attention}{
    \begin{varwidth}[t]{0.05\textwidth}
    \begin{tikzpicture}
        \draw [ultra thick, red, rounded corners, fill=white] (0,0) -- (1,0) -- (0.5,1)--cycle;
        \node [scale=2] at (0.5,0.4) {$ ! $};
        \pgfresetboundingbox;
        \clip (0.16,0.12) rectangle (0.83,0.80);
    \end{tikzpicture}
    \end{varwidth}
    %
    \begin{varwidth}{0.93\textwidth}
}{\end{varwidth}}

\tcbset{
    myattention_box/.style={
        blanker,
        %before skip=6pt,after skip=15pt,
        borderline west={1.5pt}{8.9pt}{red},
        grow to left by=17pt, % to have the borderline within the left margin
    },
}
\tcolorboxenvironment{attention}{myattention_box}

\begin{document}
    \begin{attention}
        \lipsum[1]
    \end{attention}
\end{document}

Notice how the "warning sign" is slightly shifted upwards, but not at the very top :
the "warning sign" is slightly shifted upwards, but not at the very top

Best Answer

Please keep option [t] in both varwidth boxes,

\documentclass[a4paper, 11pt]{report}
\usepackage[T1]{fontenc} % encoding
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\usepackage{varwidth}
\usepackage{lipsum}

\newenvironment{attention}{
    \begin{varwidth}[t]{0.05\textwidth}
    \begin{tikzpicture}
        \draw [ultra thick, red, rounded corners, fill=white] (0,0) -- (1,0) -- (0.5,1)--cycle;
        \node [scale=2] at (0.5,0.4) {$ ! $};
        \pgfresetboundingbox;
        \clip (0.16,0.12) rectangle (0.83,0.80);
    \end{tikzpicture}
    \end{varwidth}
    %
    \begin{varwidth}[t]{0.93\textwidth}
}{\end{varwidth}}

\tcbset{
    myattention_box/.style={
        blanker,
        %before skip=6pt,after skip=15pt,
        borderline west={1.5pt}{8.9pt}{red},
        grow to left by=17pt, % to have the borderline within the left margin
    },
}
\tcolorboxenvironment{attention}{myattention_box}

\begin{document}
    \begin{attention}
        \lipsum[1]
    \end{attention}
\end{document}
Related Question