2

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

1
  • Set [t] option for the varwidth that contains the text.
    – antshar
    Jun 30, 2022 at 13:51

2 Answers 2

4

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

I corrected some parameters of MadyYuvi answer:

\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 [yshift=-7pt,ultra thick, red, rounded corners, fill=white] (0,0.1) -- (.9,0.1) -- (0.45,1.1)--cycle;
            \node [scale=2] at (0.45,.2) {$ ! $};
            \pgfresetboundingbox;
            \clip (0.16,0.12) rectangle (0.83,0.80);
        \end{tikzpicture}
    \end{varwidth}
    %
    \begin{varwidth}[t]{0.9\textwidth}
    }{\end{varwidth}}

\tcbset{
    myattention_box/.style={
        blanker,
        %before skip=6pt,after skip=15pt,
        borderline west={1.5pt}{8pt}{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}

So the output is: enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .