如何使各部分之间相互引用?

如何使各部分之间相互引用?

平均能量损失

\documentclass{book}
\begin{document}

\part{ONE}
\chapter{One}
a\label{sec:a}

\section{1-One}
c \pageref{sec:e} [please see Part II page 3] %< what I'm trying to write

d \pageref{sec:a} [please see page 3] %< what I'm trying to write

\newpage\setcounter{page}{1}

\part{TWO}
\chapter{One}
e\label{sec:e}

\section{1-One}
f \pageref{sec:e} [please see page 3] %< what I'm trying to write

g \pageref{sec:a} [please see Part I page 3] %< what I'm trying to write

\end{document}

如果参考文献在同一部分,则只写页码;如果参考文献在另一部分,则写出该部分和页码。

答案1

平均能量损失

\documentclass[english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

%\setcounter{secnumdepth}{5} % fünf Ebenen

\usepackage{zref-user,zref-counter}
\usepackage{expl3}
\makeatletter
\zref@newprop{chapter}[1]{\the\c@chapter}
\zref@newprop{part}[1]{\the\c@part}
\zref@newprop{section}[1]{\the\c@section}
\zref@newprop{subsection}[1]{\the\c@subsection}
\zref@addprop{main}{chapter}
\zref@addprop{main}{part}
\zref@addprop{main}{section}
\zref@addprop{main}{subsection}
\ExplSyntaxOn

\newcommand\myref[1]{%
    %\hyperref[#1]{
        \int_compare:nTF
        {
            \zref@extractdefault {#1} {part} {0} = \the\c@part
        }
        {
            %ref is from current section
            \int_compare:nTF
            {\zref@extractdefault {#1} {part} {0}  = 0 }
            {Was~nun?}
            {
[Please\ see\ page\ \pageref{#1}]
}
        }
        {
            %ref is from other section
[please\ see\ Part\ \int_to_Roman:n {\zref@extractdefault {#1} {part} {0}}\
 Chapter\ \int_to_Roman:n {\zref@extractdefault {#1} {chapter} {0}}\
Section\ \int_to_Roman:n {\zref@extractdefault {#1} {section} {0}}\ page\ \pageref{#1}]
        }}%}
        \ExplSyntaxOff
        \makeatother
        \newcommand\Label[1]{\zlabel{#1}\label{#1}}
               
        \begin{document}
    
\part{ONE}
\chapter{One}
\Label{part:a}
\section{1-One}
\myref{part:secondofsecond}
    
\myref{part:a}
\newpage\setcounter{page}{1}
    
\part{TWO}
\chapter{One}
\Label{part:e}
\section{1-One}
\myref{part:a}
\section{First}
\myref{part:e}
\section{Second}
\subsection{Firstofsecond}
\myref{part:a}
\subsection{Secondofsecond}
\Label{part:secondofsecond}
                
\end{document}

我稍微改变了一下这个例子,https://tex.stackexchange.com/a/325319/3307h5。但还有多余的空间,如下图所示:

在此处输入图片描述

在此处输入图片描述

除了这个问题,我没有其他问题。这个代码对我有用。当然,我改变了 Ulrike Fischer 的解决方案。我无法想象将来会发生什么。

答案2

我希望这有帮助:

\documentclass{book}
\begin{document}

\part{ONE} \label{part:1}

\chapter{One}\label{part:1:ch:1}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et.

\section{1-One}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et, please see Part \ref{part:1}, Chapter \ref{part:1:ch:1}

\newpage
\setcounter{page}{1}        % Page Number to 1
\setcounter{chapter}{0}     % Next Chapter Number to 1

\part{TWO} \label{part:2} 

\chapter{One}\label{part:2:ch:1}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et, please see Part \ref{part:1}, Chapter \ref{part:1:ch:1}.

\section{1-One}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et, please see Part \ref{part:1}, Chapter \ref{part:1:ch:1} and Part \ref{part:2}, Chapter \ref{part:2:ch:1}.


\end{document}

生成结果:

在此处输入图片描述

相关内容