
このようなコードを書いてみました
\documentclass[8pt,a4paper,dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,hmargin=2cm,vmargin={2cm,2.5cm}]{geometry}
\usepackage[colorlinks=false]{hyperref}
\hypersetup{
pdftitle={...},
pdfauthor={...},
pdfsubject={...},
pdfkeywords={...},
}
\usepackage{enumitem}
\usepackage{chngcntr}
\usepackage{cleveref}
\usepackage{etoolbox,cancel,mathtools,physics}
\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\counterwithin*{equation}{enumi}
\newif\ifinenumerate
\AtBeginEnvironment{enumerate}{\inenumeratetrue}
\makeatletter
\renewcommand\theequation{%
\ifnum\value{subsection}>0 \thesubsection.\else
\ifnum\value{section}>0 \thesection.\fi\fi
\ifinenumerate \theenumi\fi
\arabic{equation}}
\makeatother
\begin{document}
\section{Test 1}
\subsection{Test 1.1}
\begin{enumerate}[label=\alph*.]
\item item a
\begin{itemize}
\item item a case 1
\begin{equation*}
a = b
\end{equation*}
\begin{itemize}
\item item a case 1 subcase 1
\begin{equation}
a = b \label{eq:Eq1.1.a.1}
\end{equation}
\end{itemize}
\end{itemize}
\begin{equation}
a = b \label{eq:Eq1.1.a.2}
\end{equation}
\end{enumerate}
\subsection{Test 1.2}
\begin{equation}
\underbrace{
\cancel{\pdv{t}\delta n}
}_{
\mathclap{\substack{\text{stationary} \\ \text{case}}}
}
+
\underbrace{
\cancel{\mu^*\va{E}\grad_{\va{r}}{\var n}}
}_{
\substack{\mu^* = 0 \\ \text{if} \\ n_0 = p_0 = n_i}
}
-
D^*\laplacian_{\va{r}}\delta n
-
\underbrace{
\frac{\delta n}{\tau^*}
}_{
\mathclap{\substack{\text{it vanishes for} \\ \text{lengths less than}\ L}}
}
-
g_L = 0 \label{eq:AmbipEq}
\end{equation}
\subsection{Test 1.3}
Cross reference to \eqref{eq:AmbipEq} which is not properly anchored
\end{document}
また、なぜ適切に固定されないのか知りたいのですがeq:AmbipEq
、それは使用によるものでしょうか\mathclap
?\substack
本当にありがとうございます!
答え1
あなたの例をテストしたところ、次の行が得られました
\newlabel{eq:AmbipEq}{{1.2.1}{1}{Test 1.2}{equation.1.1}{}}
.aux ファイルに入力します。
つまり、ラベルを参照すると、名前が であるアンカーにリンクしながらeq:AmbipEq
番号が「印刷」されることになります。1.2.1
equation.1.1
.log ファイルにはいくつかの警告が含まれています。そのうちの 1 つは次のとおりです。
pdfTeX warning (ext4): destination with the same identifier (name{equation.1.1}) has been already used, duplicate ignored
これは、何らかの理由で、 という名前のアンカーを配置する試みが 2 回あったことを意味しますequation.1.1
。
すべてのハイパーリンクは、そのアンカーを配置する試みが最初に行われた .TeX 入力ファイル/ソース ファイル内の場所に対応する出力ファイル/.pdf ファイル内の場所にリンクします。
その理由は何でしょうか?
このマクロは、\theequation
方程式カウンターの値を「印刷」する方法を指定するために使用されます。
hyperref パッケージを使用する場合、値を印刷する以外に別の問題が発生します。
番号付きの「ルブリフィケーション項目」の新しいインスタンスが出力ファイル (PDF ファイル) に配置されると (つまり、番号付きのセクション見出し、番号付きの画像のキャプション、番号付きの表のキャプション、または数式/方程式の番号)、対応するカウンターの値が印刷され、ハイパーリンクのアンカーが配置されます。そのアンカーには、ドキュメント全体で一意の名前が必要です。
このマクロは、\theHequation
ハイパー参照パッケージの使用時に、方程式番号に関連するアンカー名が自動的に生成される方法を指定するために使用されます。
マクロは、\theHequation
アンカー名の一意性を保証する方法で指定する必要があります。
再定義/変更する場合は、アンカー名の一意性を確保するために、同様に\theequation
調整/再定義する必要がある可能性があります。\theHequation
したがって、私は平行して配置することを提案する
\renewcommand\theequation{%
\ifnum\value{subsection}>0 \thesubsection.\else
\ifnum\value{section}>0 \thesection.\fi\fi
\ifinenumerate \csname theenum\romannumeral\the\@enumdepth\endcsname\fi
\arabic{equation}%
}
次のようなものを置く
\AtBeginDocument{%
\renewcommand\theHequation{%
\ifnum\value{subsection}>0 \theHsubsection.\else
\ifnum\value{section}>0 \theHsection.\fi\fi
\ifinenumerate \csname theHenum\romannumeral\the\@enumdepth\endcsname.\fi
\arabic{equation}%
}%
}
文書の序文に挿入します。
(どちらのコードスニペットも@
文字 (→ \makeatletter..\makeatother
) が想定されています。)
これを実行すると、.auxファイルにエントリが入ります
\newlabel{eq:AmbipEq}{{1.2.1}{1}{Test 1.2}{equation.1.2.1}{}}
つまり、ラベルを参照すると 、名前が であるアンカーにリンクしながらeq:AmbipEq
番号が「印刷」されることになります。1.2.1
equation.1.2.1
同じ識別子を持つ宛先に関する対応する pdfTeX 警告は、.log ファイル内では発生しません。
\documentclass[8pt,a4paper,dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,hmargin=2cm,vmargin={2cm,2.5cm}]{geometry}
\usepackage[colorlinks=false]{hyperref}
\hypersetup{
pdftitle={...},
pdfauthor={...},
pdfsubject={...},
pdfkeywords={...},
}
\usepackage{enumitem}
\usepackage{chngcntr}
\usepackage{cleveref}
\usepackage{etoolbox,cancel,mathtools,physics}
\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\counterwithin*{equation}{enumi}
\newif\ifinenumerate
\AtBeginEnvironment{enumerate}{\inenumeratetrue}
\newcommand{\prr}{\\[0.5cm]} %
\makeatletter
\renewcommand\theequation{%
\ifnum\value{subsection}>0 \thesubsection.\else
\ifnum\value{section}>0 \thesection.\fi\fi
\ifinenumerate \csname theenum\romannumeral\the\@enumdepth\endcsname\fi
\arabic{equation}%
}
\AtBeginDocument{%
\renewcommand\theHequation{%
\ifnum\value{subsection}>0 \theHsubsection.\else
\ifnum\value{section}>0 \theHsection.\fi\fi
\ifinenumerate \csname theHenum\romannumeral\the\@enumdepth\endcsname.\fi
\arabic{equation}%
}%
}
\makeatother
\begin{document}
\section{Test 1}
\subsection{Test 1.1}
\begin{enumerate}[label=\alph*.]
\item item a
\begin{itemize}
\item item a case 1
\begin{equation*}
a = b
\end{equation*}
\begin{itemize}
\item item a case 1 subcase 1
\begin{equation}
a = b \label{eq:Eq1.1.a.1}
\end{equation}
\end{itemize}
\end{itemize}
\begin{equation}
a = b \label{eq:Eq1.1.a.2}
\end{equation}
\end{enumerate}
\subsection{Test 1.2}
\begin{equation}
\underbrace{
\cancel{\pdv{t}\delta n}
}_{
\mathclap{\substack{\text{stationary} \\ \text{case}}}
}
+
\underbrace{
\cancel{\mu^*\va{E}\grad_{\va{r}}{\var n}}
}_{
\substack{\mu^* = 0 \\ \text{if} \\ n_0 = p_0 = n_i}
}
-
D^*\laplacian_{\va{r}}\delta n
-
\underbrace{
\frac{\delta n}{\tau^*}
}_{
\mathclap{\substack{\text{it vanishes for} \\ \text{lengths less than}\ L}}
}
-
g_L = 0 \label{eq:AmbipEq}
\end{equation}
\begin{align}
n &= N_C e^{\left(\frac{E_F-E_C}{K_B T}\right)} \nonumber
\prr
\frac{N_D^+}{N_D^0} &= \frac{1}{g_D}e^{\left(\frac{E_D-E_F}{K_BT}\right)} \label{eq:EqToLabeling}
\end{align}
\subsection{Test 1.3}
Cross reference to \eqref{eq:AmbipEq} which is hopefully properly anchored
Cross reference to \eqref{eq:EqToLabeling} which is hopefully properly anchored as well.
\end{document}
ところで:
(La)TeX の読み取り装置について、および入力ファイルでスペース文字に遭遇したときに (La)TeX がスペース トークン (出力ファイルに水平スペースを生成する) を生成する状況について学習することは重要だと思います。
たとえば、入力ファイルで開き中括弧文字の後または閉じ中括弧文字の後にスペース文字があると、出力ファイルに水平スペースをもたらすスペース トークンが生成されます (そのスペース トークンが (La)TeX が垂直モードのいずれでもないときに検出された場合)。
たとえば、開き中括弧文字の後または閉じ中括弧文字の後の改行でも、スペース トークンが生成されます。これは、入力を読み込むときに (La)TeX が各行の末尾にスペース文字を挿入するためです。これは、整数パラメータと関係があります\endlinechar
。
出力ファイル/pdf ファイル内で不要な水平スペースを回避するために、%
行末の開始中括弧文字の後と行末の終了中括弧文字の後、つまり{%
または のコメント文字を使用することを検討してください。}%
\documentclass{article}
\newcommand\TeXA{\TeX{
}\TeX}
\newcommand\TeXB{\TeX{}
\TeX}
\newcommand\TeXC{\TeX{%
}\TeX}
\newcommand\TeXD{\TeX{}%
\TeX}
\begin{document}
\noindent There are subtle differences in spacing:
\noindent \TeXA
\noindent \TeXB
\noindent \TeXC
\noindent \TeXD
\end{document}