我曾经\begin{example}
创建过示例。它生成了示例。但它没有显示任何示例编号。当我设置计数器时,它会显示编号。例如:示例。13. 示例编号可以根据章节编号自动显示吗?
\documentclass{report}
\usepacke{amsmath}
%\usepackage[utf8]{inputenc}
%\usepackage[english]{babel}
\newcounter{example}
\addtocounter{example}{10}
\newenvironment{example}[1][]{\refstepcounter{example}\par\medskip
\textbf{Example~\theexample. #1} \rmfamily}{\medskip}
\rmfamily}{\medskip}
\begin{document}
\setcounter{chapter}{11}
\chapter{Footing Design}
\section{Numerical Examples}
\refstepcounter{example}
\begin{example}
Design of footng.
\end{example}
\begin{example}
Individual footing example.
\end{example}
\end{document}
答案1
像这样吗?
\documentclass{report}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{chngcntr}
\newcounter{example}[chapter]
\counterwithin{example}{chapter} % Change the format to chapter number.example number
\newenvironment{example}[1][]{%
\noindent%
\refstepcounter{example}%
\textbf{Example~\theexample. #1}%
}{\par\medskip}
\begin{document}
\setcounter{chapter}{11}
\chapter{Footing Design}
\section{Numerical Examples}
\begin{example}
Design of footing.
And now for something completely different
\end{example}
\begin{example}
Individual footing example.
\end{example}
\chapter{Another chapter}
\begin{example}
Another example
\end{example}
\end{document}