我知道这一定是一件微不足道的事情:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[svgnames]{xcolor}
\usepackage{framed} %http://www.latex-community.org/forum/viewtopic.php?f=44&t=5823
\colorlet{shadecolor}{gray!25}
\renewenvironment{leftbar}{%
\def\FrameCommand{\textcolor{shadecolor}{\vrule width 3pt} \hspace{10pt}}%
\MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\endMakeFramed}
\declaretheorem[name=Example]{exampleOri}
\newenvironment{example}[1]{\begin{leftbar}\begin{exampleOri}[#1]}{\end{exampleOri}\end{leftbar}}
\begin{document}
\begin{example}[This is a test]
Bla
\end{example}
\end{document}
结果是Example 1 ([). This is a test] Bla
。这里出了什么问题?
更新:由于它不是问题的直接答案,但仍然有用,所以我想使用以下密钥发布我的最终mdframed
方法thmtools
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[svgnames]{xcolor}
\colorlet{shadecolor}{gray!25}
\declaretheorem[name=Example,
mdframed={
hidealllines=true,leftline=true,
rightmargin=0pt,innerrightmargin=0pt,
innerlinewidth=0pt,middlelinewidth=0pt,
outerlinecolor=shadecolor,outerlinewidth=3pt,
skipabove=\topskip,skipbelow=\topskip}
]{example}
\begin{document}
\begin{example}[This is a test]
Bla
\end{example}
\end{document}
答案1
您将该参数声明为example
强制参数,因此应将其括在括号中。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[svgnames]{xcolor}
\colorlet{shadecolor}{gray!25}
\usepackage{framed}
\renewenvironment{leftbar}{%
\def\FrameCommand{\textcolor{shadecolor}{\vrule width 3pt} \hspace{10pt}}%
\MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\endMakeFramed}
\declaretheorem[name=Example]{exampleOri}
\newenvironment{example}[1][]
{\begin{leftbar}
\ifx\relax#1\relax
\begin{exampleOri}
\else
\begin{exampleOri}[#1]
\fi}
{\end{exampleOri}\end{leftbar}}
\begin{document}
\begin{example}[This is a test]
Bla
\end{example}
\begin{example}
Bla
\end{example}
\end{document}
然而,我会选择一条更简单的路线。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[svgnames]{xcolor}
\colorlet{shadecolor}{gray!25}
\usepackage[framemethod=TikZ]{mdframed}
\newmdtheoremenv[hidealllines=true,leftline=true,
innerlinewidth=0pt,middlelinewidth=0pt,
outerlinecolor=shadecolor,outerlinewidth=3pt,
skipabove=\topsep,skipbelow=\topsep,
]{example}{Example}
\begin{document}
\begin{example}[This is a test]
Bla
\end{example}
\begin{example}
Bla
\end{example}
\end{document}