我想为一个方程式创建一个标题,使用对齐环境制作。创建了这个帖子(9 年前):对齐环境的标题,有人发布了这个解决方案:
\newcounter{captionedequationset} %numbering
\newdimen\captionlength
\newcommand{\captionedequationset}[1]{
\refstepcounter{captionedequationset}% Step counter
\setlength{\captionlength}{\widthof{#1}} %
\addtolength{\captionlength}{\widthof{Equation set~\thecaptionedequationset: }}
%If the caption is shorter than the line width then
% the caption is centred, otherwise is flushed left.
\ifthenelse{\lengthtest{\captionlength < \linewidth }} %
{\begin{center}
Equation~\thecaptionedequationset: #1
\end{center}}
{ \begin{flushleft}
Equation~\thecaptionedequationset: #1 %
\end{flushleft}}}
我遇到的问题是:
- 标题与公式不对齐。如果出现分页符(如 \clearpage 或普通页面跳转),标题就会与公式分离。
- 计数器不遵循章节号。
这是一个“最小”的 MWE:
\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, lipsum}
\usepackage{calc}
\usepackage{ifthen}
% - - - - - C O M A N D O S - - - - -
% Para poder escribir Caption en ecuaciones matemáticas:
%-- Defines a CAPTION for a set of equations and numbers
% the set of equations is numbered
% note: the caption adapts the text alignment to the length.
\newcounter{captionedequationset} %numbering
\newdimen\captionlength
\newcommand{\captionedequationset}[1]{
\refstepcounter{captionedequationset}% Step counter
\setlength{\captionlength}{\widthof{#1}} %
\addtolength{\captionlength}{\widthof{Equation set~\thecaptionedequationset: }}
%If the caption is shorter than the line width then
% the caption is centred, otherwise is flushed left.
\ifthenelse{\lengthtest{\captionlength < \linewidth }} %
{\begin{center}
Equation~\thecaptionedequationset: #1
\end{center}}
{ \begin{flushleft}
Equation~\thecaptionedequationset: #1 %
\end{flushleft}}}
% - - - - - PORTADA - - - - -
\begin{document}
\chapter{}
\section{Section 1}
The Equation \ref{eq:1} shows an equation.
\begin{align}
\begin{split}
\text{Eq 1: }&\\
& x = 0
\end{split}
\end{align}
\captionedequationset{Nice equation.\label{eq:1}}
The Equation \ref{eq:2} shows another equation.
\begin{align}
\begin{split}
\text{Eq 2: }&\\
& x^2 = 0
\end{split}
\end{align}
\captionedequationset{Another nice equation.\label{eq:2}}
\section{Section 2}
The Equation \ref{eq:3} shows another equation.
\begin{align}
\begin{split}
\text{Eq 2: }&\\
& x^2 + x = 0
\end{split}
\end{align}
\clearpage
\captionedequationset{Another nice equation.\label{eq:3}}
\end{document}
结果如下(忽略出现的 2 和 CHAPTER 1):
有没有更好的方法来完成此操作?或者,有没有什么方法可以升级此代码并解决问题?