我想以宏的形式重新创建该图像:
到目前为止我有骨架:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usepackage{amsmath,amssymb}
\newcounter{exnum}
\setcounter{exnum}{0}
\newcommand{\Example}[1]{\begin{tikzpicture} \stepcounter{exnum}
\node [mybox1] (box){%
\begin{minipage}{\textwidth}
{#1}
\end{minipage}
};
\node[fancytitle1, right=10pt] at (box.north west) {Example
\arabic{exnum}:};
\end{tikzpicture}}
\begin{document}
% Define box and box title style
\tikzstyle{mybox1} = [draw=red, fill=blue!20, very thick,
rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle1} =[fill=red, text=white]
\Example{Text}
\Example{Text}
\Example{Text}
\end{document}
得出的结果为:
我需要有关程序样式的帮助和建议。不确定为什么第一个例子略有偏移?
答案1
像这样?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\tikzset{exbox/.style = {
titlebox/.style = {draw, rounded corners, semithick, fill=white,
font=\bfseries, inner sep=5pt,
node contents={Exercise~\theex}
},
arr/.style = {{Triangle[angle=45:1pt 3]}-{Triangle[angle=45:1pt 3]},
rounded corners, semithick},
exercise/.style = {text width=\dimexpr\linewidth-19pt,
inner ysep=\baselineskip, inner xsep=5pt,
align=justify}
}
}
\newcommand\EX[1]{
\refstepcounter{ex}
\noindent%
\begin{tikzpicture}[exbox]
\node (ex) [exercise] {#1};
{\lipsum[1]};
\draw[arr] ([yshift=-\baselineskip] ex.north west) --
(ex.north west) --
(ex.north east) node[titlebox,anchor=west, pos=0.1] --
([yshift=-\baselineskip] ex.north east);
\draw[arr] ([yshift=\baselineskip] ex.south west) --
(ex.south west) --
(ex.south east) node[titlebox,anchor=east, pos=0.9] --
([yshift=\baselineskip] ex.south east);
\end{tikzpicture}
\medskip\par}% end new command
\usepackage{lipsum}
\newcounter{ex}
\begin{document}
\EX{\lipsum[1]}
\EX{\lipsum[2]}
\end{document}
答案2
一个很好的候选者是tcolorbox
。我保留了你的编号方案,exnum
但如果你使用类似定理的 tcolorbox,你可能会更好。tcolorbox
基于 Ti钾Z 并允许您执行在 Ti 中可以执行的所有操作钾Z 但另外还扩展了对盒子的支持。
\documentclass{article}
\usepackage[most]{tcolorbox}
\newcounter{exnum}
\setcounter{exnum}{0}
\newtcolorbox{exbox}[1][]{%
enhanced,
before skip=10ex,
after skip=10ex,
frame hidden,
overlay={%
\fill[yellow!10,rounded corners=3.14pt]
([yshift=2.5ex]frame.north west) rectangle ([yshift=-2.5ex]frame.south
east);
\draw[latex-latex,rounded corners=3.14pt] (frame.north west)
-- ++ (0,2.5ex) -| (frame.north east)
node[pos=0.06,fill=white,draw,rounded corners]{%
Example\refstepcounter{exnum} \theexnum};
\draw[latex-latex,rounded corners=3.14pt] (frame.south west)
-- ++ (0,-2.5ex) -| (frame.south east)
node[pos=0.44,fill=white,draw,rounded corners]{Example \theexnum};
}
}
\begin{document}
\begin{exbox}
It is not always true that
\[ \frac{\partial^2f}{\partial x\,\partial y}(a,b)=
\frac{\partial^2f}{\partial y\,\partial x}(a,b)\]
\end{exbox}
\begin{exbox}
I am another example
\end{exbox}
\end{document}