我正在尝试使用 mdframed 包创建一个带框编号的示例环境。这是我第一次尝试环境定义,所以我可能犯了一个新手错误。为什么这个例子中的编号不正确?这些示例似乎从 0 开始编号(我不想要),但当我引用它们时,参考编号是我真正想要的(但与打印的示例编号不匹配)。
\documentclass[11pt]{book}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
%
% Example environment
%
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{xcolor}
%% set the counter for your environment
\newcounter{example}[chapter]
\renewcommand{\theexample}{\thechapter.\arabic{example}}
%% define the style
\mdfdefinestyle{example}{%
frametitle=\mbox{},
backgroundcolor=gray!8,
linecolor=gray,
outerlinewidth=1pt,
roundcorner=3mm,
skipabove=\baselineskip,
skipbelow=\baselineskip,
}
%% setup the environment
\newmdenv[%
style=example,
settings={\global\refstepcounter{example}},
frametitlefont={\bfseries Example~{\theexample}\quad},
]{example}
\begin{document}
\chapter{Blah}
qf;qiuef;iqugef;iqugef;
\begin{example}
blah blah blah
\end{example}
\begin{example}
blah blah blah
\end{example}
\chapter{Blech}
\begin{example}
Blech Blech Blech
\end{example}
\begin{example}\label{ex:blech}
Blech Blech Blech
\end{example}
Referencing Example \ref{ex:blech}
\end{document}
答案1
看来你的 LaTeX 有部分内容还没有更新。
在您的评论中,您例如说:mdframed.sty 2013/03/09
。我的比较新。
这是我的 \listfile 的结果。
*File List*
book.cls 2007/10/19 v1.4h Standard LaTeX document class
bk11.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
graphicx.sty 2014/04/25 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 2014/05/08 v1.15 key=value parser (DPC)
graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
trig.sty 1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg 2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO)
ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
amssymb.sty 2013/01/14 v3.01 AMS font symbols
amsfonts.sty 2013/01/14 v3.01 Basic AMSFonts support
amsmath.sty 2013/01/14 v2.14 AMS math features
amstext.sty 2000/06/29 v2.01
amsgen.sty 1999/11/30 v2.0
amsbsy.sty 1999/11/29 v1.2d
amsopn.sty 1999/12/14 v2.01 operator names
mdframed.sty 2013/07/01 1.9b: mdframed
kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO)
xparse.sty 2014/07/20 v5241 L3 Experimental document command parser
expl3.sty 2014/07/20 v5241 L3 programming layer (loader)
expl3-code.tex 2014/07/20 v5241 L3 programming layer
etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB)
l3unicode-data.def 2014/06/30 v5166 L3 Unicode data
l3pdfmode.def 2014/07/18 v5232 L3 Experimental driver: PDF mode
etoolbox.sty 2011/01/03 v2.1 e-TeX tools for LaTeX
zref-abspage.sty 2012/04/04 v2.24 Module abspage for zref (HO)
zref-base.sty 2012/04/04 v2.24 Module base for zref (HO)
kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO)
pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO)
auxhook.sty 2011/03/04 v1.3 Hooks for auxiliary files (HO)
atbegshi.sty 2011/10/05 v1.16 At begin shipout hook (HO)
needspace.sty 2010/09/12 v1.3d reserve vertical space
color.sty 1999/02/16
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
tikz.sty 2013/12/13 v3.0.0 (rcs-revision 1.142)
pgf.sty 2013/12/18 v3.0.0 (rcs-revision 1.14)
pgfrcs.sty 2013/12/20 v3.0.0 (rcs-revision 1.28)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v3.0.0 (rcs-revision 1.7)
pgfsys.sty 2013/11/30 v3.0.0 (rcs-revision 1.47)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2013/09/09 (rcs-revision 1.9)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
xcolor.sty 2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v3.0.0 (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v3.0.0 (rcs-revision 1.1)
pgffor.sty 2013/12/13 v3.0.0 (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
md-frame-1.mdf 2013/07/01\ 1.9b: md-frame-1
supp-pdf.mkii
***********
请与您的结果进行比较并更新相关包。
您可以在此处看到最终的编号: