每章浮点计数器不起作用

每章浮点计数器不起作用

我在更改浮动标题格式时遇到了问题。我希望我的代码能够为表格、图形和公式添加每章计数器(例如“图 3.1”而不是“图 15”)。

我以前用过这个,但是我开始使用一种新的文档格式,不知为何它就不起作用了。它适用于方程式,但不适用于表格和图形。

我正在用来\numberwithin{figure}{chapter}做这件事,并且我也尝试过用\counterwithin{figure}{chapter}

有谁知道为什么这行不通吗?

这是我的序言(\numberwithin{}{}位于 % 参考文献下)

\documentclass[a4paper,twoside,article,11pt]{memoir}

% Basic setup
\usepackage[utf8]{inputenc} % Input encoding - Depending on editor
\usepackage{lmodern} % Modern LaTeX font
\usepackage[english]{babel} % Language package
\usepackage[T1]{fontenc} % Hyphenation
\usepackage{fix-cm} % Fix for cm
\usepackage{microtype}
\usepackage{lipsum} % Debugging text
\renewcommand{\familydefault}{\rmdefault}
\usepackage[document]{ragged2e}

% Graphics
\usepackage{graphicx} % To handle pictures
\graphicspath{{figures/}} % Image path
\usepackage{xcolor} % To define colors
\usepackage{tikz} % Graphical tool
\definecolor{ase_blue}{RGB}{10,55,136}

% Tables
\usepackage[flushleft]{threeparttable}
\usepackage{multirow}
\usepackage{changepage} % Changes margins locally
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{enumitem}
\usepackage{booktabs}%
\usepackage{longtable}

% Math
\usepackage{mathtools} % To use \eqref
\usepackage{calc}% Auto calculate
\usepackage{sansmath,subfig} % Gives a warning because subfig loads caption
\usepackage{amsmath,amssymb}
\usepackage{amsthm}
\usepackage{bm}
\usepackage{xfrac}
\usepackage{icomma}
\usepackage{siunitx}

% References
\usepackage{varioref} % Smarter references
\usepackage{hyperref}
\hypersetup{pdfauthor={<The authors>}, pdftitle={<The title>},pdfsubject={<The subject>}}
\numberwithin{equation}{chapter}
\numberwithin{table}{chapter}
\numberwithin{figure}{chapter}
\usepackage{url} % Use of urls in the text
\urlstyle{tt}
\usepackage{titlesec}
\setcounter{tocdepth}{1}
\setcounter{secnumdepth}{2}
\usepackage{lastpage}
\usepackage{listings}
\usepackage[numbered]{mcode}
\usepackage{nomencl}
\makenomenclature
\newcommand{\stoptocwriting}{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-5}}}
\newcommand{\resumetocwriting}{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{\arabic{tocdepth}}}}

% Caption setup
\captionsetup{font={small,rm}}
\captionsetup[subfloat]{font={small,rm}}

% Margin control
\setlrmarginsandblock{3.5cm}{2.5cm}{*}
\setulmarginsandblock{3cm}{*}{1.2}
\checkandfixthelayout[nearest]
\setlength{\evensidemargin}{\oddsidemargin}

% Frontpage
\usepackage{color,soul} % Letterspace package
\sodef\an{}{0.05em}{.5em plus.6em}{1em plus.1em minus.1em}
\newcommand\stext[1]{\an{\scshape#1}}
\newcommand{\logoHuge}{\fontsize{0.55cm}{0.8cm}\selectfont}
\newcommand{\SuperHuge}{\fontsize{1.2cm}{1.8cm}\selectfont}

% Pagestyle
%\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}}
\makepagestyle{ase_report}
\makeevenhead{ase_report}{\textsc{Auto-OMA on Hexapod}}{}{}
\makeoddhead{ase_report}{}{}{\small\scshape\leftmark}
\makeheadrule{ase_report}{\textwidth}{\normalrulethickness}
\makeevenfoot{ase_report}{\small\rmfamily\thepage/\pageref{LastPage}}{}{}
\makeoddfoot{ase_report}{}{}{\small\rmfamily\thepage/\pageref{LastPage}}

\makepagestyle{intro}
\makeevenhead{intro}{\textsc{Auto-OMA on Hexapod}}{}{}
\makeoddhead{intro}{}{}{\small\scshape\leftmark}
\makeheadrule{intro}{\textwidth}{\normalrulethickness}
\makeevenfoot{intro}{\small\rmfamily\thepage}{}{}
\makeoddfoot{intro}{}{}{\small\rmfamily\thepage}

\usepackage{fancyhdr}

\makeatletter
\makepsmarks{ase_report}{%
  \renewcommand\chaptermark[1]{%
    \markboth{%
      \ifnum \value{secnumdepth} > 1
      \if@mainmatter % 
      \@chapapp\ \thechapter. \ %
      \fi
      \fi
      ##1}{}}%
  \renewcommand\tocmark{\markboth{\contentsname}{\contentsname}}%
  \renewcommand\lofmark{\markboth{\listfigurename}{\listfigurename}}%
  \renewcommand\lotmark{\markboth{\listtablename}{\listtablename}}%
  \renewcommand\bibmark{\markboth{\bibname}{\bibname}}%
  \renewcommand\indexmark{\markboth{\indexname}{\indexname}}%
  \renewcommand\sectionmark[1]{\markright{##1}}%
  \renewcommand\subsectionmark[1]{\markright{##1}}%
  \renewcommand\subsubsectionmark[1]{\markright{##1}}}

\copypagestyle{plain}{ase_report}
\makeoddhead{plain}{}{}{}
\makeoddfoot{plain}{}{}{\small\rmfamily\thepage}

\pagestyle{ase_report}
\aliaspagestyle{chapter}{plain}

% Chapter style
\makechapterstyle{ase_chapterstyle}{
  \setlength{\beforechapskip}{-20pt}
  \setlength{\afterchapskip}{0.5cm}
  \renewcommand*{\printchaptername}{}
  \renewcommand*{\chapnumfont}{\normalfont\scshape\fontsize{60}{0}\selectfont}
  \renewcommand*{\printchapternum}{
    \flushleft
    \begin{tikzpicture}
      \draw[fill,color=ase_blue] (0,0) rectangle (2cm,2cm);
      \draw[color=white] (1cm,1cm) node {\chapnumfont\thechapter}(0.5cm,0.5cm );
    \end{tikzpicture}
  }
  \renewcommand*{\chaptitlefont}{\normalfont\scshape\huge\color{black}}
  \renewcommand*{\printchaptertitle}[1]{%
    \raggedright\chaptitlefont\parbox[t]{\textwidth}{\raggedright##1}}}

\chapterstyle{ase_chapterstyle}

% Section style
\newcommand{\ruledsec}[1]{%
\Large\scshape\raggedright #1
\color{ase_blue}\rule[15pt]{\textwidth}{1.0pt}} % Section with ruler
\setsecheadstyle{\ruledsec} % Define section head style

\setfloatlocations{figure}{htp}
\setfloatlocations{table}{htp}

% Subsection style
\addtocounter{secnumdepth}{2} % Depth numbering

\setsubsecheadstyle{\large\scshape\raggedright}
\setsubsubsecheadstyle{\normalsize\scshape\raggedright}

\setsechook{\hangsecnum} % Hang the section number in margin
\setsubsechook{\defaultsecnum} % Don't do this on the subsections
\setsubsubsechook{\defaultsecnum}
\setaftersecskip{5pt} % Default skip between the section and text

% Table of contents
\raggedbottomsectiontrue % The page may not be strected on page breaks
\setsecnumdepth{section} % Set section depth in the TOC
\maxsecnumdepth{section} % Max of section depth in the TOC
\settocdepth{section} % Up to and including subsection
\renewcommand{\cftchapterfont}{\small\scshape}
\renewcommand{\cftchapterpagefont}{\small\scshape}
\renewcommand{\cftsectionfont}{\small\scshape}
\renewcommand{\cftsectionpagefont}{\small\scshape}
\renewcommand{\cftchapterleader}{\cftdotfill{\cftdotsep}}

\setlength{\cftbeforechapterskip}{0pt} % Space from chapters
%\chapterprecistoc{Text in TOC}

\addto\captionsenglish{
  \renewcommand*{\cftchaptername}{Chapter{\space}}
  \renewcommand*{\cftfigurename}{Fig.{\space}}
  \renewcommand*{\contentsname}{Table of Contents}
  \renewcommand*{\abstractname}{Abstract}
  \renewcommand*{\listfigurename}{List{\space}of{\space}Figures}
  \renewcommand*{\listtablename}{List{\space}of{\space}Tables}
  \renewcommand*{\appendixtocname}{Appendices}
  \renewcommand*{\appendixpagename}{Appendices}
}

% Hide appendices from TOC:
\newcounter{oldtocdepth}
\newcommand{\hidefromtoc}{\setcounter{oldtocdepth}{\value{tocdepth}}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-10}}}
\newcommand{\unhidefromtoc}{
  \addtocontents{toc}{\protect\setcounter{tocdepth}{\value{oldtocdepth}}}}
\usepackage{bookmark}

 \usepackage{nomencl}
 \makenomenclature

先感谢您。

答案1

这里的问题实际上是双重的。(1)您正在使用选项article,(2)您正在使用\frontmatter\mainmatter。由于\frontmatter实际上从中删除了任何主导计数器,例如\thefigure,在序言中,对计数器主导性的任何调整都将被覆盖\frontmatter(有充分的理由,前言中没有可用的主导计数器)。

\mainmatter它出现时,它通常会运行\counterwithin{figure}{chapter}以重新获得主导地位。但它不会在选项下这样做article,因为article选项是对类行为的模拟article,即连续编号。

最简单的解决方案是修补一个内部组件\mainmatter,以便文章分支重新发出反支配地位:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@smemmain}{\ifartopt}{\ifartopt\@memmain@floats}{\typeout{patch
    done}}{\typeout{patch failed}}
\makeatother

其他一些评论:

fancyhdr由于您不使用它,因此没有理由加载。

可以\makepsmarks{ase_report}{使用更简单的代码来完成,请参阅\createmark\createplainmark

相关内容