我需要在使用 mdframe 设计的 fancybox 旁边插入一些小图标或图片,如textblog.org 上的@Tom使用 mdframe 和 tikz。
我可以使用includegraphics
代码中的 tikz 和 mdfsetup 部分插入图像,但这样会将图像放在框内。但我需要将其放在标题框外,并放置在与框对齐的左侧边距中。
图标或图片的高度可调(可根据用户自定义高度和宽度),并放置在框开头左侧的空白处。以下演示图片提供了我的设计要求示例
此处已从上述链接复制了 MWE。如果能单独提供对设计的任何细微修改或美化,并尽可能提供命令的简单说明,我将不胜感激,因为我是一名初学者,所以我可以理解它们的用法,以后可能会根据我的需要使用它们。
\documentclass{book}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{titlesec}
\usepackage{amssymb}
\usepackage{tikz} % I added this extra , are this necessary please comment
\usepackage{pstricks} % I added this extra , are this necessary please comment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Theorem
\newcounter{theo}[section] \setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
\newenvironment{theo}[2][]{%
\refstepcounter{theo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut Theorem~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut Theorem~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}
\begin{document}
\section{Theorem and lemma examples with title}
\begin{theo}[Pythagoras' theorem]{thm:pythagoras}
In a right triangle, the square of the hypotenuse is equal to the sum of the squares of the two other side.
\[a^2+b^2=c^2\]
\end{theo}
In mathematics, the Pythagorean theorem, also known as Pythagoras' theorem (see theorem \ref{thm:pythagoras}), is a relation in Euclidean geometry among the three sides of a right triangle.
\end{document}
答案1
不,您不需要加载,tikz
也不会加载pstricks
。tikz
因为您说的是framemethod=TikZ
,所以不会加载,并且这里不需要 pstrics。
是的,您可以通过拨打选项轻松添加一些延伸到边距的内容overlay
。我添加了一些定理标题左侧的示例图像。为了更好地定位,我加载了定位库,这不是绝对必要的,但可以说是方便的。
\documentclass{book}
\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{positioning}
\usepackage{amsthm}
\usepackage{titlesec}
\usepackage{amssymb}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Theorem
\newcounter{theo}[section] \setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
\newenvironment{theo}[2][]{%
\refstepcounter{theo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
{\node[anchor=east,rectangle,fill=blue!20] (theo)
{\strut Theorem~\thetheo};
\node[left=0.4cm of theo,anchor=east,overlay]{
\includegraphics[width=1cm]{example-image-duck}};}}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
{\node[anchor=east,rectangle,fill=blue!20] (theo)
{\strut Theorem~\thetheo:~#1};
\node[left=0.4cm of theo,anchor=east,overlay]{
\includegraphics[width=1cm]{example-image-duck}};}}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}
\begin{document}
\section{Theorem and lemma examples with title}
\begin{theo}[Pythagoras' theorem]{thm:pythagoras}
In a right triangle, the square of the hypotenuse is equal to the sum of the squares of the two other side.
\[a^2+b^2=c^2\]
\end{theo}
In mathematics, the Pythagorean theorem, also known as Pythagoras' theorem (see theorem \ref{thm:pythagoras}), is a relation in Euclidean geometry among the three sides of a right triangle.
\end{document}