我正在尝试制作一个小样式包,以便制作一些带有图标等的漂亮块。我正在使用environ
package + tikz
。实际上,文档编译并向我显示了我的框,但出现错误,指出某些环境未关闭。
我创建了一个带有包的“iconbox”环境environ
,它可以接受一些参数(标题、图标、颜色……),我想用它来概括一些框:info
框、danger
框……
当我想创建一个使用我创建的图标框的新环境时,问题就开始了。
如果我想使用\NewEnviron
它来调用另一个,LaTeX 会在递归中崩溃。
如果我使用旧版newenvironment
,LaTeX 会说我没有关闭图标框块。
当然,我尝试过\beginiconbox
在\endiconbox
开始和结束块中但它不起作用。
这是一个“复制/粘贴”应该给你的问题
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ} % NewEnviron
\usepackage{fontawesome} % font awesome icons
%Options: Sonny, Lenny, Glenn, Conny, Rejne, Bjarne, Bjornstrup
\usepackage[Sonny]{fncychap}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{shadows.blur}
\usepackage{color}
\usepackage{pbsi} % for handwriting
\usepackage{bera}
\definecolor{m3dorange}{HTML}{ff9966}
\definecolor{m3dred}{HTML}{c9453e}
\definecolor{m3dgreen}{HTML}{4f9c45}
\definecolor{m3dblue}{HTML}{2499d0}
% title, icon, color, title color
\NewEnviron{iconbox}[4]{%
\begin{center}
\begin{tikzpicture}
\node [
top color=#3!10,
bottom color = white,
inner sep=2em,
rounded corners=1em,
draw=#3!60,
inner sep=1.2em,
text width=\textwidth*.7,
drop shadow = {opacity=.4},
shadow yshift = -4,
shadow xshift = 4,
font=\par\itshape
] (frame) at (0, 0) {\hspace{1.5em}\textbf{\bsifamily{\centering\Large\textcolor{#4}{#1}}}\vspace{.8em}\par\BODY};%
\node [
shape=circle,
top color=#4!90,
bottom color=white!50,
color=white,
circular drop shadow={opacity = .7},
font=\Huge,
inner sep=6pt] at (frame.north west) {\centering\textbf{#2}};
\end{tikzpicture}
\end{center}
}
\newenvironment{danger}[1]
{\begin{iconbox}{#1}{\faExclamation}{m3dorange}{red}}
{\end{iconbox}}
\newenvironment{success}[1]
{\begin{iconbox}{#1}{\faStickyNoteO}{m3dgreen}{m3dgreen}}
{\end{iconbox}}
\newenvironment{info}[1]
{\begin{iconbox}{#1}{\faBookmark}{m3dblue}{m3dblue}}
{\end{iconbox}}
\begin{document}
\begin{danger}{Warning}
You do it wrong.
\end{danger}
\end{document}
它会生成这样的框:
但是...有错误...
那么我该怎么办?
多谢。
答案1
这似乎有效......
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ} % NewEnviron
\usepackage{fontawesome} % font awesome icons
%Options: Sonny, Lenny, Glenn, Conny, Rejne, Bjarne, Bjornstrup
\usepackage[Sonny]{fncychap}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{shadows.blur}
\usepackage{color}
\usepackage{pbsi} % for handwriting
\usepackage{bera}
\definecolor{m3dorange}{HTML}{ff9966}
\definecolor{m3dred}{HTML}{c9453e}
\definecolor{m3dgreen}{HTML}{4f9c45}
\definecolor{m3dblue}{HTML}{2499d0}
% title, icon, color, title color
\NewEnviron{iconbox}[4]{%
\begin{center}
\begin{tikzpicture}
\node [
top color=#3!10,
bottom color = white,
inner sep=2em,
rounded corners=1em,
draw=#3!60,
inner sep=1.2em,
text width=\textwidth*.7,
drop shadow = {opacity=.4},
shadow yshift = -4,
shadow xshift = 4,
font=\par\itshape
] (frame) at (0, 0) {\hspace{1.5em}\textbf{\bsifamily{\centering\Large\textcolor{#4}{#1}}}\vspace{.8em}\par\BODY};%
\node [
shape=circle,
top color=#4!90,
bottom color=white!50,
color=white,
circular drop shadow={opacity = .7},
font=\Huge,
inner sep=6pt] at (frame.north west) {\centering\textbf{#2}};
\end{tikzpicture}
\end{center}
}
\NewEnviron{danger}[1]
{\let\oldBODY\BODY
\def\BODY{\empty}
\begin{iconbox}{#1}{\faExclamation}{m3dorange}{red}
\oldBODY
\end{iconbox}}
\NewEnviron{success}[1]
{\let\oldBODY\BODY
\def\BODY{\empty}
\begin{iconbox}{#1}{\faStickyNoteO}{m3dgreen}{m3dgreen}
\oldBODY
\end{iconbox}}
\NewEnviron{info}[1]
{\let\oldBODY\BODY
\def\BODY{\empty}
\begin{iconbox}{#1}{\faBookmark}{m3dblue}{m3dblue}
\oldBODY
\end{iconbox}}
\begin{document}
\begin{danger}{Warning}
You do it wrong.
\end{danger}
\begin{info}{Yes}
I agree. I tried to improve.
\end{info}
\begin{success}{;-)}
This seems to work.
\end{success}
\end{document}
答案2
将外部主体作为参数传递:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{environ} % NewEnviron
\usepackage{fontawesome} % font awesome icons
%Options: Sonny, Lenny, Glenn, Conny, Rejne, Bjarne, Bjornstrup
\usepackage[Sonny]{fncychap}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{shadows.blur}
\usepackage{color}
\usepackage{pbsi} % for handwriting
\usepackage{bera}
\definecolor{m3dorange}{HTML}{ff9966}
\definecolor{m3dred}{HTML}{c9453e}
\definecolor{m3dgreen}{HTML}{4f9c45}
\definecolor{m3dblue}{HTML}{2499d0}
% title, icon, color, title color
\newenvironment{iconbox}[5]{%
\begin{center}
\begin{tikzpicture}
\node [
top color=#3!10,
bottom color = white,
inner sep=2em,
rounded corners=1em,
draw=#3!60,
inner sep=1.2em,
text width=\textwidth*.7,
drop shadow = {opacity=.4},
shadow yshift = -4,
shadow xshift = 4,
font=\par\itshape
] (frame) at (0, 0) {\hspace{1.5em}\textbf{\bsifamily{\centering\Large\textcolor{#4}{#1}}}\vspace{.8em}\par\BODY};%
\node [
shape=circle,
top color=#4!90,
bottom color=white!50,
color=white,
circular drop shadow={opacity = .7},
font=\Huge,
inner sep=6pt] at (frame.north west) {\centering\textbf{#2}};
\end{tikzpicture}
\end{center}
}
\NewEnviron{danger}[1]
{\begin{iconbox}{#1}{\faExclamation}{m3dorange}{red}{\BODY}\end{iconbox}}
\NewEnviron{success}[1]
{\begin{iconbox}{#1}{\faStickyNoteO}{m3dgreen}{m3dgreen}{\BODY}\end{iconbox}}
\NewEnviron{info}[1]
{\begin{iconbox}{#1}{\faBookmark}{m3dblue}{m3dblue}{\BODY}\end{iconbox}}
\begin{document}
\begin{danger}{Warning}
You do it wrong.
\end{danger}
\end{document}