我创建了新的对齐环境,在公式数字前面放置一个“I.”(或“II.”)(例如,我想在文档的第一部分使用 I.1、I.2 等,在第二部分使用 II.1、II.2 等)。但是,超链接无法正常工作。例如,如果我单击对 II.2 的引用,我最终会到达 I.1。
在一个简化的示例中,它的工作原理是:
\documentclass[
12pt,
a4paper,
titlepage]{article}
\usepackage{amsmath}
\usepackage{hyperref}
%*********************************************************
%****Define new align-environments
%*********************************************************
% I.
\newcommand{\thealignedIal}{I.\arabic{equation}}
\makeatletter
\newenvironment{romanalignI}{%
\let\theequation\thealignedIal
}{}
\makeatother
%% II.
\newcommand{\thealignedIIal}{II.\arabic{equation}}
\makeatletter
\newenvironment{romanalignII}{%
\let\theequation\thealignedIIal
}{}
\makeatother
\begin{document}
This is part I of my document, so I would like to use \textit{romanalignI}:
\begin{romanalignI}
\begin{align}
1+1 = 2 \label{eq1}
\end{align}
\end{romanalignI}
Now a second equation:
\begin{romanalignI}
\begin{align}
2+2 = 4 \label{eq2}
\end{align}
\end{romanalignI}
It works fine when referencing them: \eqref{eq1} and \eqref{eq2}. \\
\newpage
Now, let's move on to part II and use \textit{romanalignI}:
\begin{romanalignII}
\begin{align}
1+1 = 2 \label{eq3}
\end{align}
\end{romanalignII}
Now a second equation:
\begin{romanalignII}
\begin{align}
2+2 = 4 \label{eq4}
\end{align}
\end{romanalignII}
Again, the referencing works fine: \eqref{eq3} and \eqref{eq4}.
\end{document}
但在“真实”文档中,它停止正常工作:
主控文档
\documentclass[
12pt,
titlepage]{article}
% Space before/after align
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[normalem]{ulem} % strike through text
\usepackage{scrextend}
\usepackage{color}
\usepackage{xcolor}
\definecolor{primary}{HTML}{08457E}
\usepackage{colortbl}
\usepackage{graphicx}
\usepackage{amsmath, bm}
\usepackage{physics} % for partial derivatives with \pdv
\usepackage{microtype} % für die Mikrotypografie (besseres Schriftbild)
\usepackage{lscape} %singles pages as landscape
\usepackage{rotating} % for 'sidewaystable' environment
\usepackage{tikz} %econ drawing
\usepackage{ragged2e}
\usepackage{subfig} %tables next to each other
% allow for different spacing options
\usepackage{setspace}
\doublespacing
% allow for different spacing options in enumerate/itemize
\usepackage{enumitem}
%Formatierung Bilder
\usepackage{caption}
\DeclareCaptionLabelSeparator{just_a_colon}{: }
\captionsetup[figure]{
position=below,
labelsep=just_a_colon
}
\makeatletter
\renewcommand*\l@figure{\@dottedtocline{1}{0em}{1em}}
\makeatother
%Hyperlinks
\usepackage{hyperref}
% colored links
\hypersetup{
colorlinks=true,%set true if you want colored links
linktoc=all,
%set to all if you want both sections and subsections linked
filecolor=black,
citecolor={blue!40!black},
linkcolor={blue!40!black},
urlcolor=black,
%linktocpage,
%only link the page numbers and not the entire table of contents
}
% For Tables
\usepackage[labelfont=bf]{caption}
\captionsetup[table]{labelsep=space,
justification=raggedright, singlelinecheck=off}
\usepackage{caption,threeparttable}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{adjustbox}
\usepackage{array} %center with m{}
%-> ">{\centering\arraybackslash}p{0.3\linewidth} | >{\centering\arraybackslash}p{0.3\linewidth}"
\usepackage{tablefootnote}
% Appendix
\usepackage[title]{appendix}
%Gliederungsebenen
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\usepackage[bottom, hang, flushmargin]{footmisc} % put footnote as much to the bottom as possible AND no indent
% no indentation of new lines
\usepackage[parfill]{parskip}
\setlength{\parindent}{0pt}
% set font to Times New Roman
\usepackage{times}
% add table of figures/tables to table of contents
\usepackage[nottoc]{tocbibind}
% widow / orphan control
\usepackage[all]{nowidow}
\usepackage[
a4paper,
left=20mm,
right=20mm,
top=10mm,
bottom=30mm,
scale=1 %,
%showframe
]{geometry} % Seitenränder und Bindungskorrektur einstellen
\setlength{\headsep}{0.3in} % add space between header and text
%*********************************************************
%****CUSTOM COMMANDS
%*********************************************************
\newcommand{\submissiondate}{INSERT SUBMISSION DATE}
% Define checkmark
\usepackage{pifont}
\newcommand{\checkmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}
\usepackage{accents}
\newcommand{\ubar}[1]{\underaccent{\bar}{#1}}
%*********************************************************
%****Define new align-environments
%*********************************************************
% Römisch Erstens
\newcommand{\thealignedIal}{I.\arabic{equation}}
\makeatletter
\newenvironment{romanalignI}{%
\let\theequation\thealignedIal
}{}
\makeatother
%% Römisch Zweitens
\newcommand{\thealignedIIal}{II.\arabic{equation}}
\makeatletter
\newenvironment{romanalignII}{%
\let\theequation\thealignedIIal
}{}
\makeatother
%*********************************************************
%****Formatierung des Titelblatts
%*********************************************************
\title{%
This is the title}
\newcommand*\mytitle{}
\makeatletter
\let\mytitle\@title
\makeatother
%\linespread{1.5}
\pagestyle{myheadings}
\setlength{\headheight}{1.8\baselineskip}
\usepackage{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearscrheadfoot
% Colorboxes
\usepackage{tcolorbox}
\newtcolorbox{mybox}[3][]
{
colframe = #2!25,
colback = #2!10,
coltitle = #2!20!black,
title = {#3},
#1,
}
%*********************************************************
%****BEGIN DOCUMENT
%*********************************************************
\begin{document}
%*********************************************************
%****GENERATE TITLEPAGE
%*********************************************************
\begin{titlepage}
\begin{center}
\vspace*{0.5cm}
{\bfseries\Large\textsc{\mytitle}}\\
\vspace*{2.5cm}
{more text}\\
\vspace{1cm}
Name of Institution \\
\vspace{2cm}
City, \submissiondate
\end{center}
\end{titlepage}
\newgeometry{
left=33mm,
right=23mm,
top=23mm,
bottom=23mm,
scale=1}
%*********************************************************
%****ABSTRACT
%*********************************************************
\vspace*{2cm}
\section*{\centering{Abstract}} \label{Abstract}
%\begin{center}
\begin{addmargin}[10pt]{10pt}
\input{./Kapitel/Abstract}
\end{addmargin}
%\end{center}
\newpage
%*********************************************************
%****GENERATE TABLE OF CONTENTS
%*********************************************************
\thispagestyle{empty} %no header/footer
{
\onehalfspacing
\hypersetup{linkcolor=black}
\tableofcontents
\makeatletter
\renewcommand*{\ext@figure}{lot}
\let\c@figure\c@table
\let\ftype@figure\ftype@table
\let\listoftableandfigures\listoftables
\renewcommand*\listtablename{List of Tables and figures}
\makeatother
}
%*********************************************************
%****List of Figures / Tables
%*********************************************************
{
\hypersetup{linkcolor=black}
\listoffigures
%\listoftables
}
%*********************************************************
%**** Manual Glossary
%*********************************************************
\newpage
\section*{Glossary}
\begin{table}[h!]
\begin{tabular}{ll}
c.p. & ceteris paribus
\\ ~ \\
\end{tabular}
\end{table}
%*********************************************************
%****BEGINN MAIN SECTION
%*********************************************************
%*********************************************************
%****PAGE NUMBERING
%*********************************************************
\pagenumbering{gobble}
\cleardoublepage
\pagenumbering{arabic}
\setcounter{page}{1}
%*********************************************************e
%****SET HEADER/FOOTER
%*********************************************************
\chead{\normalfont Title} %{Kopfzeile Mitte}
\ihead{{\normalfont Name}}%{Kopfzeile innen} %not italic
\ohead{\pagemark}%{Kopfzeile außen}
\ifoot%{Fußzeile innen}
\cfoot%{Fußzeile Mitte}
\ofoot%{Fußzeile außen}
\section{Introduction} \label{Introduction}
\input{./Kapitel/Introduction}
\newpage
\section{Models} \label{Main}
\input{./Kapitel/Main}
\newpage
\section{Conclusion} \label{Conclusion}
\input{./Kapitel/Conclusion}
\newpage
\end{document}
章节名称 我将其称为单独章节。它们位于名为“Kapitel”的文件夹中。
摘要.tex
Abstract
结论.tex
Conclusion
引言.tex
Introduction
主文本
\subsection{Model 1}
\setcounter{equation}{0}
\input{./Kapitel/Model1}
\newpage
blabla
\newpage
blabala
\newpage
\subsection{Model 2}
\setcounter{equation}{0}
\input{./Kapitel/Model2}
模型1.tex
\subsubsection{Equ1}
\begin{romanalignI}
\begin{align}
1+1 = 2
\label{eq I.1}
\end{align}
\end{romanalignI}
\subsubsection{Eq 2}
\begin{romanalignI}
\begin{align}
1+1 = 2
\label{eq I.2}
\end{align}
\end{romanalignI}
\subsubsection{Referencing both}
\eqref{eq I.1} and \eqref{eq I.2}.
模型2.tex
\subsubsection{Equ1}
\begin{romanalignII}
\begin{align}
1+1 = 2
\label{eq II.1}
\end{align}
\end{romanalignII}
\subsubsection{Eq 2}
\begin{romanalignII}
\begin{align}
1+1 = 2
\label{eq II.2}
\end{align}
\end{romanalignII}
\subsubsection{Referencing both}
\eqref{eq II.1} and \eqref{eq II.2}.
我不知道是什么导致了这样的混乱,如果能得到任何帮助我将非常非常感谢!
答案1
修改定义成
% Römisch Erstens
\newcommand{\thealignedIal}{I.\arabic{equation}}
\makeatletter
\newenvironment{romanalignI}{%
\let\theequation\thealignedIal
\renewcommand\theHequation{\thealignedIal\arabic{equation}}%
}{}
\makeatother
%% Römisch Zweitens
\newcommand{\thealignedIIal}{II.\arabic{equation}}
\makeatletter
\newenvironment{romanalignII}{%
\let\theequation\thealignedIIal
\renewcommand\theHequation{\thealignedIIal\arabic{equation}}%
}{}
\makeatother
\pagenumbering{Alph}
我还建议在之前titlepage
和之后添加\pagenumbering{alph}
,这样您就不会得到重复的锚点(页码无论如何都不会出现)。切勿使用\pagenumbering{gobble}
when hyperref
。