使用 tcolorbox 或 tikz 绘制自定义框架

使用 tcolorbox 或 tikz 绘制自定义框架

我正在尝试绘制这个(它应该适应文本的宽度和高度)。

在此处输入图片描述

我想使用 tcolorbox 或 tikz。抱歉没有提供任何 MWE,我不知道如何开始。谢谢!

答案1

如果你想要一些简单的东西

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw=orange, line width=6pt, inner sep=0.5cm, postaction={draw=yellow, line width=3pt, line cap=round, dash pattern=on 0pt off 5\pgflinewidth}] {$f(x)=\ldots$};
\end{tikzpicture}
\end{document}

带橙色框和黄色圆点的公式

答案2

我认为使用tcolorbox可能会更好。但是,您可以使用以下代码编写自己的框架代码tikz

\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{fadings}
\definecolor{myyellow}{RGB}{254,225,162}
\definecolor{myorange}{RGB}{255,189,0}
\definecolor{myiframe}{RGB}{188,104,58}
\definecolor{mydframe}{RGB}{233,141,59}
\definecolor{mylframe}{RGB}{255,161,79}
\tikzfading[name=olight fade, inner color=transparent!0, outer color=transparent!100]
\tikzfading[name=light fade, inner color=transparent!0, outer color=transparent!95]
\tikzfading[name=ilight fade, inner color=transparent!0, outer color=transparent!100]
\newcommand{\addframe}[1]{{\noindent\tikz{
\node[inner sep=10pt,line width=0pt](current content){
\begin{minipage}{\dimexpr\linewidth-1cm-20pt}
#1
\end{minipage}};
\draw [myiframe,line width=4pt] (current content.south west) rectangle (current content.north east);
\fill [mydframe] (current content.south west) -- ++(-0.5,-0.5) -- ([xshift=0.5cm,yshift=-0.5cm]current content.south east) -- (current content.south east) -- cycle;
\fill [mydframe] (current content.north east) -- ++(0.5,0.5) -- ([xshift=-0.5cm,yshift=0.5cm]current content.north west) -- (current content.north west) -- cycle;
\fill [mylframe] (current content.south west) -- ++(-0.5,-0.5) -- ([xshift=-0.5cm,yshift=0.5cm]current content.north west) -- (current content.north west) -- cycle;
\fill [mylframe] (current content.north east) -- ++(0.5,0.5) -- ([xshift=0.5cm,yshift=-0.5cm]current content.south east) -- (current content.south east) -- cycle;
\begin{scope}[remember picture,overlay]
\foreach \loc/\xshift/\yshift in {
north east/-1cm/0.25cm,
north/0cm/0.25cm,
north west/1cm/0.25cm,
west/-0.25cm/0cm,
south west/1cm/-0.25cm,
south/0cm/-0.25cm,
south east/-1cm/-0.25cm,
east/0.25cm/0cm}{
    \fill [myyellow,path fading=olight fade] ([xshift=\xshift,yshift=\yshift]current content.\loc) circle (0.5cm);
    \fill [myorange,path fading=light fade] ([xshift=\xshift,yshift=\yshift]current content.\loc) circle (0.4cm);
    \fill [myyellow,path fading=ilight fade] ([xshift=\xshift,yshift=\yshift]current content.\loc) ellipse [x radius=0.3cm, y radius=0.2cm];}
\end{scope}
}\par}}

\begin{document}
\addframe{
\begin{equation}
    E=m\cdot c^2
\end{equation}
}
\lipsum[1]
\addframe{\lipsum[1]}
\begin{table}[ht]
    \addframe{\caption{Table Caption}\label{tab:label}
    \centering
    \begin{tabular}{ccc}
        1 & 2 & 3  \\
        4 & 5 & 5  \\
        7 & 8 & 9
    \end{tabular}}
\end{table}
\end{document}

在此处输入图片描述

答案3

首先,尝试一下这个代码:

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{ decorations.markings}

\begin{document}
    \begin{tikzpicture}
        \filldraw[fill=gray!20,draw=blue,line width=20pt] (0,0) rectangle (7,5);
        \foreach \i in {1,...,6}{%
            \filldraw[yellow,line width=2pt] (\i,5) circle(5pt);
            \filldraw[yellow,line width=2pt] (\i,0) circle(5pt);
        }
        \foreach \i in {0,...,5}{%
        \filldraw[yellow,line width=2pt] (0,\i) circle(5pt);
        \filldraw[yellow,line width=2pt] (7,\i) circle(5pt);
        }
        \node[cyan] at (3.5,2.5)(a) {\LARGE $f(x)=\frac{x+1}{\sqrt{x+2}}$};
    \end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

相关内容