我以前tcolorbox
有一个“警告”框。我希望“警告标志”位于其最顶部,但即使使用[t]
环境选项也无法实现varwidth
。
这是 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}
答案1
请保留[t]
两个varwidth
框中的选项,
\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
我修正了MadyYuvi回答的一些参数:
\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}