我有这个可以工作的MWE:
\documentclass{article}
\newcounter{example}
\counterwithin*{example}{section}
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\fbox{\textbf{Example~\thesection.\theexample}}%
\hrulefill\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\hrulefill\vrule}
\begin{document}
\section{First section}
Some introductory text...
\begin{example}
\begin{equation}
f(x)=\frac{x}{1+x^2}
\end{equation}
\end{example}
\end{document}
但是我如何添加变量示例标题?
答案1
像这样吗?
\documentclass{article}
\newcounter{example}
\counterwithin{example}{section}
\newenvironment{example}[1][]{%
\refstepcounter{example}%
\par\vspace{5pt}%
\noindent\fbox{\textbf{Example \theexample #1}}%
\hrulefill\par}%
{\par\noindent\hrulefill\vrule}
\begin{document}
\section{First section}
Some introductory text\dots
\begin{example}[: Hello World]
\begin{equation}
f(x)=\frac{x}{1+x^2}
\end{equation}
\end{example}
\end{document}