我有以下代码来获得一个漂亮的概念框,其中包含每个讨论的新概念的可选标题。代码使用计数器更改概念编号,但我还需要在下一章中将其重新设置为 1。代码仅取自此组,因此我并不完全理解其中的内容。请帮助我如何在下一章中将计数器变量“定理”重新设置为 1。
% Preview preamble
%% LyX 2.0.4 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\RequirePackage{fix-cm}
\documentclass[11pt,a4paper,english,oldfontcommands,openany]{memoir}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\synctex=-1
\usepackage{wrapfig}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fixltx2e}
\OnehalfSpacing
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\@ifundefined{lettrine}{\usepackage{lettrine}}{}
\theoremstyle{definition}
\newtheorem{example}{\protect\examplename}
\theoremstyle{definition}
\newtheorem{defn}{\protect\definitionname}
\theoremstyle{plain}
\newtheorem{thm}{\protect\theoremname}
\@ifundefined{date}{}{\date{}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[T1]{fontenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows,shadings}
\usepackage[a4paper]{geometry}
\geometry{
left=30mm, %% or inner=20mm
right=15mm, %% or outer=15mm
top=30mm, bottom=25mm,
headheight=\baselineskip,
headsep=7mm,
footskip=13mm
}
\usepackage{multicol}
\usepackage{polynom}
\usepackage{lettrine}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usepackage{pgf}
\usepackage{graphicx}
\usetikzlibrary{arrows,mindmap}
\usepgflibrary{arrows}
%\usepackage[framemethod=TikZ]{mdframed}
\usepackage{cwpuzzle}
%\renewcommand{\secheadstyle}{\huge\bfseries}
%\chapterstyle{demo3}
\chapterstyle{verville}
%\chapterstyle{southhall}
%chapterstyle{thatcher}
%\chapterstyle{wilsondob}
%\chapterstyle{pedersen}
%\chapterstyle{bianchi}
\setsubsubsecindent{1cm}
\setaftersubsubsecskip{1cm}
\setsubsubsecheadstyle{\Large\itshape\raggedleft
\begin{tikzpicture}
\draw[overlay,remember picture,opacity=0.5] node [right,text width=15cm, rounded corners, fill=gray!30, inner sep=2ex]{};
\draw[thick,overlay,remember picture, gray!50] (0,-.1)--(12.8,-.1);
\draw[ultra thick,overlay,remember picture, gray!70] (0,-.2)--(12.8,-.2);
\draw[thick,overlay,remember picture, gray!40] (0,-.3)--(12.8,-.3);
\draw[ultra thick,overlay,remember picture,gray!70] (0,-.2) -- (-20,-.2);
\shade[yshift=6pt,ball color=gray,overlay] (0,-.2) circle (9pt);
\end{tikzpicture}
}
\setsubsecindent{0.4cm}
\setbeforesubsecskip{0.5cm}
\setaftersubsecskip{0.5cm}
\setsubsecheadstyle{\Large\scshape\raggedright
\begin{tikzpicture}
%\draw[overlay,remember picture,opacity=0.5] node [right,text width=12cm, rounded corners, fill=gray!50, inner sep=2ex]{};
\draw[yshift=-2pt,remember picture, line width=2pt, overlay, gray!30, rounded corners] (12,-.4) -- (0,-.4) -- (0,.8) -- (12,.8) -- cycle;
\draw[thick,overlay,remember picture, gray!50] (0,-.1)--(12,-.1);
\draw[ultra thick,overlay,remember picture, gray!70] (0,-.2)--(20,-.2);
\draw[thick,overlay,remember picture, gray!40] (0,-.3)--(12,-.3);
\draw[ultra thick,overlay,remember picture,gray!70] (0,-.2) -- (-20,-.2);
\shade[ball color=gray!90,overlay] (0,-.2) circle (3pt);
\shade[ball color=gray!90,overlay] (12,-.2) circle (3pt);
\end{tikzpicture}
}
\setsecindent{0.4cm}
\setbeforesecskip{1.5cm}
\setaftersecskip{1cm}
\setsecheadstyle{\LARGE\scshape\raggedright\color{black}
\begin{tikzpicture}
\draw[yshift=6pt,overlay,remember picture,opacity=0.5] node [right,text width=15.5cm, rounded corners, fill=gray!30, inner sep=15pt]{};
\draw[yshift=-2pt,remember picture, line width=4pt, overlay, gray, rounded corners] (16,-.4) -- (-0.5,-.4) -- (-0.5,1) -- (16,1) -- cycle;
\shade[overlay,ball color=gray] (16,0.2) circle (8pt);
\end{tikzpicture}
}
\setparaindent{1cm}
\setafterparaskip{1cm}
\setparaheadstyle{\Large\itshape\raggedright
\begin{tikzpicture}
\draw[overlay,remember picture,opacity=0.5] node [right,text width=0.4\textwidth, rounded corners, fill=gray!30, inner sep=2ex]{};
\draw[thick,overlay,remember picture, gray!50] (0,-.1)--(7.5,-.1);
\draw[ultra thick,overlay,remember picture, gray!70] (0,-.2)--(7.5,-.2);
\draw[thick,overlay,remember picture, gray!40] (0,-.3)--(7.5,-.3);
%\draw[ultra thick,overlay,remember picture,gray!70] (0,-.2) -- (-20,-.2);
\shade[yshift=6pt,ball color=gray,overlay] (0,-.2) circle (8pt);
\shade[ball color=gray,overlay](7.5,0) circle (8pt);
\end{tikzpicture}
}
%%%%%%%% This is to get a Concept
\usepackage{lipsum}
% this is the start of the code which is our interest
\newcounter{theorem}
\renewcommand\thetheorem{Concept ~\arabic{theorem}}
\makeatletter
\mdf@dolist{\mdf@do@stringoption}{%
{theoremtitle=={}}%
}
\renewrobustcmd\mdfcreateextratikz{%
\node[anchor=west,rounded corners,draw,thick,shading=axis,left color=gray!20,xshift=10cm,minimum height=.7cm,minimum width=2cm] at (P-|O)
{~\mdf@frametitlefont{\thetheorem}%
\ifdefempty{\mdf@theoremtitle}%
{~}%
{:~\mdf@theoremtitle~}%
};
}
\makeatother
\mdfdefinestyle{theoremstyle}{%
outerlinewidth=1pt,
innerlinewidth=3pt,
roundcorner=5pt,
linecolor=black,
shadow=true,
tikzsetting={shading=axis,top color=gray!10},
innertopmargin=1.2\baselineskip,
skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
needspace=3\baselineskip,
frametitlefont=\sffamily\bfseries,
settings={\global\stepcounter{theorem}},
}
\newenvironment{concept}[1][]
{\begin{mdframed}[style=theoremstyle,theoremtitle={#1}]
\relax}{
\end{mdframed}
}
\makeatother
%% this is the end of the code which is of our interest
\usepackage{babel}
\providecommand{\definitionname}{Definition}
\providecommand{\examplename}{Example}
\providecommand{\theoremname}{Theorem}
\begin{document}
\chapter{chapter one}
\begin{concept}
first chapter first concept
\end{concept}
\chapter{chapter two}
\begin{concept}
second chapter first concept
\end{concept}
\end{document}
这是由 Lyx 创建的代码
计数器代码已注释为我们上面需要的代码。要重置的计数器变量名为“theorem”
答案1
我不知道如何使用 LyX 来实现这一点。但是,为了在每一章中重置定理编号,定义应该是
\newtheorem{thm}{\protect\theoremname}[chapter]
这会将定理编号为“chapter.theorem”,因此第一章中的第一个定理将是“1.1”,第二章中的第三个定理将是“2.3”。如果您只想要章节编号,请发出
\renewcommand{\thethm}{\arabic{thm}}
就在前次声明之后。
答案2
当您指定新计数器时,您可以使用可选参数在旧计数器步进时重置此新计数器:\newcounter{newcounter}[oldcounter]
。这意味着每次oldcounter
步进时,newcounter
都会重置为零。如果您想将此类行为添加到已经存在的计数器(例如由某些包提供)或想要删除此类行为(例如,即使在新章节命令之后,所有部分的数字都会增加),您可以使用更改中心包,它提供命令\counterwithin
和\counterwithout
。
代码
\documentclass[parskip]{scrreprt}
\usepackage[paperwidth=8cm,margin=1cm,paperheight=14cm]{geometry}
\newcounter{mycounter}[chapter]
\setcounter{mycounter}{0}
\begin{document}
\chapter{ONE}
\stepcounter{mycounter}\themycounter
\stepcounter{mycounter}\themycounter
\section{one}
\stepcounter{mycounter}\themycounter
\chapter{TWO}
\stepcounter{mycounter}\themycounter
\section{one}
\stepcounter{mycounter}\themycounter
\section{two}
\stepcounter{mycounter}\themycounter
\stepcounter{mycounter}\themycounter
\chapter{THREE}
\stepcounter{mycounter}\themycounter
\end{document}
输出
答案3
我无法从您的代码中确定哪个计数器需要重置,但这里有一种方法可以在章节开始时自动重置计数器。我们将现有的定义复制\chapter
到\OldChapter
:
\let\OldChapter\chapter
现在,更改章节宏,首先根据需要将的值设置myCounter
为 1,然后重新发布以前的定义chapter
(但现在可用为OldChapter
:
\renewcommand{\chapter}{\setcounter{myCounter}{1}\OldChapter}
所以在下面的例子中,我将计数器设置为50
章节之前,我们得到的输出是:
代码:
\documentclass{book}
\newcounter{myCounter}
\let\OldChapter\chapter
\renewcommand{\chapter}{\setcounter{myCounter}{1}\OldChapter}
\begin{document}
\chapter{First}
Counter at start of chapter is \arabic{myCounter}
\setcounter{myCounter}{50}
Counter before start of chapter is \arabic{myCounter}
\chapter{Second}
Counter at start of chapter is \arabic{myCounter}
\end{document}