以下工作:
description
在mdframed
。foreach
在description
。
但是在标签 的环境中foreach
使用时会出现一些奇怪的行为description
mdframed
\item
第一个之后 \item
被狼吞虎咽:
\listfiles
:
article.cls 2014/09/29 v1.4h Standard LaTeX document class
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
xcolor.sty 2007/01/21 v2.11 LaTeX color extensions (UK)
color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
xetex.def 2014/07/25 v4.03 LaTeX color/graphics driver for XeTeX (RRM/JK)
mdframed.sty 2013/07/01 1.9b: mdframed
kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO)
keyval.sty 2014/10/28 v1.15 key=value parser (DPC)
ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO)
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (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/11/25 v5471 L3 Experimental document command parser
expl3.sty 2014/11/25 v5471 L3 programming layer (loader)
expl3-code.tex 2014/11/25 v5471 L3 programming layer
etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB)
l3unicode-data.def 2014/11/23 v5465 L3 Unicode data
l3xdvipdfmx.def
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
md-frame-0.mdf 2013/07/01\ 1.9b: md-frame-0
pgffor.sty 2013/12/13 v3.0.0 (rcs-revision 1.25)
pgfrcs.sty 2013/12/20 v3.0.0 (rcs-revision 1.28)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
代码:
\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{pgffor}
\newcommand*{\MyForEachLoop}{%
\foreach \x/\y in {
First/{item A in list},
Second/{item B in list},
Third/{item C in list}} {%
\item [\x] \y.
}%
}
\mdfsetup{frametitlerule=true}
\listfiles
\begin{document}
\begin{mdframed}[backgroundcolor=green!25, frametitle={description in mdframed (works):}]
\begin{description}
\item [First] item A in list.
\item [Second] item B in list.
\item [Third] item C in list.
\end{description}
\end{mdframed}
\noindent\textbf{foreach in description (works):}\par
\begin{description}
\MyForEachLoop%
\end{description}%
\begin{mdframed}[backgroundcolor=red!25,frametitle={foreach in description in mdframed (does NOT work):}]
\begin{description}
\MyForEachLoop%
\end{description}%
\end{mdframed}
\end{document}
答案1
这是在组中执行其工作时通常会遇到的问题\foreach
。我不太明白为什么它在中不起作用mdframed
,但我想这是因为trivlist
使用了。\item
执行时,标签被存储以供稍后排版(这允许\label
使用),显然存储箱被覆盖,使其为空。
此代码显示了所涉及的分组,其排版description
正确:
\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{pgffor,etoolbox}
\newcommand*{\MyForEachLoop}{%
\foreach \x/\y in {
First/{item A in list},
Second/{item B in list},
Third/{item C in list}} {%
\xdef\realitem{\noexpand\item[\expandonce{\x}] \expandonce{\y}.}%
\aftergroup\realitem
}%
}
\mdfsetup{frametitlerule=true}
\begin{document}
\begin{mdframed}[backgroundcolor=red!25,frametitle={foreach in description in mdframed}]
\begin{description}
\MyForEachLoop
\end{description}
\end{mdframed}
\end{document}
部分\item[\x]\y.
存储在 中\realitem
,在组之后执行。