Latex 中的格式化示例数字

Latex 中的格式化示例数字

在我的写作中,我做了很多例子,这些例子分为不同的部分。我试图通过写出例子编号和章节编号来使它们整齐地编号。我是这样做到的:

\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{exmp}{Ex}[section]

在其中一个部分里我写了以下内容:

\begin{exmp}
This is my first example
\end{exmp}

\begin{exmp}
This is my second example
\end{exmp}

输出为:

在此处输入图片描述

我需要将这些示例的编号写成:

(5.1.1)这是我的第一个示例 \label{1st}

(5.1.2)这是我的第二个例子 \label{2nd}

(5.1.2-a)这是我的第二个示例的子示例 \label{sub-2nd}

而不是在大胆的

答案1

因为从评论中可以看出,您使用它来对语言示例进行编号,所以使用其中一个包来做这件事可能更有意义,因为它们还附带了注释宏。以下是使用的示例gb4e

\documentclass{book}
\usepackage{chngcntr}
\usepackage{gb4e}

\counterwithin{xnumi}{section} % the chngcntr way (preferred)
\exewidth{(5.1.234)} % leave enough room for the example number
\begin{document}
\setcounter{chapter}{4}
\chapter{}
\section{A section}

\begin{exe}
\ex First example
\label{ex:first}
\end{exe}
\begin{exe}
\ex Second example
\label{ex:second}
\end{exe}

This is a reference to (\ref{ex:first}).
\end{document}

代码输出

答案2

你可以这样做thmtools

\documentclass[12pt, a4paper, french]{book}
%***************************************packages***************************************
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} %
\usepackage{stmaryrd}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz,tkz-tab}
\usepackage{textgreek}
\usepackage{babel}
%***************************************entête***************************************
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\renewcommand{\sectionmark}[1]{\markright{\thesection{} \ #1}}
\fancyhead[RO]{\textsl{\rightmark}}
\fancyhead[LE]{\textsl{\leftmark}}
\fancyhead[LO]{\textsl{\thepage}}
\fancyhead[RE]{\thepage}

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\tableofcontents}{%
\@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}{%
\@mkboth{%
 \contentsname}{\contentsname}}{}{}%
\makeatother
\begin{document}
%***************************************couverture***************************************
\begin{titlepage}
\Huge\bfseries \centering
Mon joli titre
\end{titlepage}
%*********************

\chapter{Un premier chapitre}
\section{Première section}
\section{Deuxième section}
\section{Troisième section}
\section{Quatrième section}
\section{Cinquième section}

\chapter{Un autre chapitre}
\section{Première section}
\section{Deuxième section}
\section{Troisième section}
\section{Quatrième section}
\section{Cinquième section}

\chapter{Encore un autre}
\section{Première section}
\section{Deuxième section}
\section{Troisième section}
\section{Quatrième section}
\section{Cinquième section}

\chapter{Un autre encore}
\section{Première section}
\section{Deuxième section}
\section{Troisième section}
\section{Quatrième section}
\section{Cinquième section}



\chapter{Un dernier chapitre}
\section{Première section}
\section{Deuxième section}
\section{Troisième section}
\section{Quatrième section}
\section{Cinquième section}


%%*****************table des matières***************************************
\tableofcontents

\end{document}*

在此处输入图片描述

相关内容