更新

更新

我不知道如何准确调用我想要实现的功能。它就像一个用线包围的框,根据上下文,我想在右上角放置一个图形,例如灯泡或问号。

我想将这些框放在多个地方,因此如果有一个链接解释如何自动化这些事情 - 我猜是一个宏 - 那也会很感激。

在此处输入图片描述

答案1

更新

在评论中提出新要求后,现在只有一个coolbox带有强制参数(要使用的文件图像)和两个可选参数的环境:

\begin{coolbox}[<options for the box>]{<image-file>}[<options for the image>]
(contents)
\end{coolbox}

代码:

\documentclass[12pt]{article}
\usepackage[many]{tcolorbox}
\usepackage{graphicx}

\definecolor{boxbg}{RGB}{179,222,255}

\tcbset{
  common/.style={
    before=\vskip2\baselineskip\noindent,
    after=\vskip2\baselineskip,
    enhanced,
    frame code={},
    fontupper=\LARGE,
    fontlower=\LARGE,
    segmentation empty,
    middle=0.7cm,
    top=0.5cm
  }
}

\DeclareTColorBox{coolbox}{O{}mO{}}{
common,
interior code={
  \filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt,#1] (interior.north west) rectangle (interior.south east);
  \node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[#3]{#2}};
  },
}

\begin{document}

\begin{coolbox}{lightbulb}[height=2cm]
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{coolbox}

\begin{coolbox}{questionmark}[width=1cm,angle=-20]
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{coolbox}

\begin{coolbox}[fill=red!20,draw=red]{exclamationmark}[width=1.5cm,angle=-20]
Did you know that adding some more text
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{coolbox}

\end{document}

在此处输入图片描述

使用tcolorbox;根据您的需要调整设置:

在此处输入图片描述

代码:

\documentclass[12pt]{article}
\usepackage[many]{tcolorbox}
\usepackage{graphicx}

\definecolor{boxbg}{RGB}{179,222,255}

\tcbset{
  common/.style={
    before=\vskip2\baselineskip\noindent,
    after=\vskip2\baselineskip,
    enhanced,
    colback=boxbg,
    frame code={},
    fontupper=\LARGE,
  }
}

\newtcolorbox{ideabox}{
common,
interior code={
  \filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
  \node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=2.5cm]{lightbulb}};
  }
}
\newtcolorbox{questionbox}{
common,
interior code={
  \filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
  \node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=1.5cm,angle=-30]{questionmark}};
  }
}

\begin{document}

\begin{ideabox}
Did you know:\par\vskip1cm

Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{ideabox}

\begin{questionbox}
Did you know:\par\vskip1cm

Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{questionbox}

\end{document}

如果所有盒子都具有这种结构(即,上部和下部),那么(如休斯建议his comment)可以使用\tcblowermiddle来避免手动产生垂直分离:

\documentclass[12pt]{article}
\usepackage[many]{tcolorbox}
\usepackage{graphicx}

\definecolor{boxbg}{RGB}{179,222,255}

\tcbset{
  common/.style={
    before=\vskip2\baselineskip\noindent,
    after=\vskip2\baselineskip,
    enhanced,
    colback=boxbg,
    frame code={},
    fontupper=\LARGE,
    fontlower=\LARGE,
    segmentation empty,
    middle=0.7cm
  }
}

\newtcolorbox{ideabox}{
common,
interior code={
  \filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
  \node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=2.5cm]{lightbulb}};
  }
}
\newtcolorbox{questionbox}{
common,
interior code={
  \filldraw[ultra thick,densely dashed,fill=boxbg,draw=black,rounded corners=10pt] (interior.north west) rectangle (interior.south east);
  \node at  ([xshift=-30pt,yshift=5pt]interior.north east) {\includegraphics[width=1.5cm,angle=-30]{questionmark}};
  }
}

\begin{document}

\begin{ideabox}
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{ideabox}

\begin{questionbox}
Did you know:
\tcblower
Once upon a time there was a latch \\
that wanted to be a flip-flop?
\end{questionbox}

\end{document}

在此处输入图片描述

答案2

在此处输入图片描述

\documentclass[border=2pt]{standalone}
\usepackage{tikz,xcolor}                   
\usetikzlibrary{calc}
\definecolor{skyblue}{HTML}{B9E1FD}

\begin{document}

\begin{tikzpicture}[line width=.7pt, inner sep=7pt]
  \node [draw,rounded corners,dashed,fill=skyblue,text width=.6\textwidth] (B){%
  \bfseries Did you know? \par \bigskip  
  Once upon a time there was a latch that wanted to be a flip.flop};
  \node [rotate=-30]at($(B.north)!.65!(B.north east)$) {\includegraphics[scale=.09]{bulb}};
\end{tikzpicture}

\end{document} 

TikZ也可以用来制作这种花式盒子。宽度可以根据需要调整(我.65\textwidth在这里使用)。颜色也是你自己选择的(我{HTML}{B9E1FD}在这里使用)。

最后,可以从以下网址下载灯泡图像本网站

在此处输入图片描述

现在问题块的获取方式与上面相同,最后一行改为:

\node at ($(B.north)!.72!(B.north east)$) {\includegraphics{quest}};

再次获得问号图像从这里

相关内容