带框的文本上方带有图片

带框的文本上方带有图片

大家好,我是 LaTeX 新手,但在网上搜索后,我发现可以创建适合文本和图像的框和框架。我想实现类似图像的效果,你会推荐什么?我看到你可以使用、、、\ovalbox……我的主要问题是将标题框mdframed在所需的位置并插入图像。非常感谢!:)beamerTiKZ

答案1

tcolorboxtikz

\documentclass{article}
\usepackage{tikz}
    \usetikzlibrary{shadows}
\usepackage{tcolorbox}
    \tcbuselibrary{skins}

\definecolor{mygreen}{rgb}{0.61,0.73,0.35}


\newcommand{\mytitle}[1]{
    \node[fill=mygreen,
        rounded corners,
        draw=white,
        line width=2pt,
        drop shadow,
        text width=4cm,
        inner sep=8pt,
        xshift=-2cm]
    at (frame.north){\bfseries\textcolor{white}{#1}};
}

\newtcolorbox{mybox}[2][]{
    enhanced,
    overlay={\mytitle{#2}},
    borderline={2pt}{0mm}{mygreen},
    borderline={.7pt}{1mm}{mygreen},
    frame hidden,
    arc=3mm,
    sidebyside,
    lefthand width=2.5cm,
    segmentation hidden,
    top=15pt,
    #1
}

\begin{document}

\begin{mybox}{Political Factors}
    \includegraphics[scale=.1]{lion.jpg}
    \tcblower
    Analyses to what degree the government intervenes
\end{mybox}

\end{document}

在此处输入图片描述

newtcolorbox如果您需要将不同的自定义设置应用于特定的框(例如,您可以使用具有不同背景颜色的相同框),则可以选择其中的可选参数。\begin{mybox}[colback=red]{Political Factors}否则,它将被忽略,如在给定的 MWE 中一样。

答案2

这是一个可行的mdframed方法。我使用该包mwe只是为了使代码能够编译。不过,我已经充分使用了您提供的图片作为图像。

\documentclass{article}

\usepackage{mwe}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows}

\definecolor{mygreen}{rgb}{0.61,0.73,0.35}

\mdfdefinestyle{mystyle}{%
    innerlinewidth = 0.5pt,
    outerlinewidth = 2pt,
    linecolor = mygreen,
    tikzsetting = {draw = white, line width = 0.5pt},
    roundcorner=15pt,
    linecolor=mygreen,
    linewidth=2pt,
    topline=true,
    frametitleaboveskip=1.5\dimexpr-\ht\strutbox\relax,
}

\newenvironment{definition}[1][]{%
\ifstrempty{#1}%
    {\mdfsetup{%
    style = mystyle,
    }}%
    {\mdfsetup{%
    style = mystyle,
    frametitle={%
    \tikz{[baseline=(current bounding box.east),outer sep=0pt]
    \node[draw = white, line width = 2pt, text = white, anchor=east,rectangle,
    fill=mygreen, rounded corners, drop shadow]
    {\strut #1};
    }}}}%
    \begin{mdframed}[]\relax%
}{\end{mdframed}}

\begin{document}
\begin{definition}[Political Factors]
\begin{minipage}{0.25\linewidth}
\includegraphics[width = \linewidth]{example-image-a}
\end{minipage}%
\hfill
\begin{minipage}{0.7\linewidth}
Analyses to what degree the government intervenes in the
economy. It includes regulations and legal issues and defines
both formal and informal rules under which the firm must
operate. Political factors include: tax policy, employment laws,
environmental regulations, trade restriction tariffs and political
stability.
\end{minipage}%
\end{definition}
\end{document}

在此处输入图片描述

相关内容