여러 장의 상호 참조

여러 장의 상호 참조

장/섹션...etc에 대한 명령을 갱신했습니다. 따라서 모든 (하위)섹션 이름에 장 번호가 표시되지 않습니다. 또한 요점은 내가 한 장에 있을 때 \ref현재 장의 섹션을 참조할 때 섹션 번호만 표시된다는 것입니다(그 이전 장 번호는 표시되지 않음). 제가 사용하고 있는 것은 다음과 같습니다 \renewcommand.

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}

하지만 이제는 다른 장의 섹션을 참조할 수도 있고 이 경우 해당 장의 번호가 표시되기를 원합니다. 나는 그렇게 할 방법을 찾을 수 없습니다... 이 문제를 해결하기 위한 나의 필사적인 시도는 현재 다음을 사용하는 것입니다:

\newcommand\fullref[2]{\ref{#1}.\ref{#2}}

여기서 두 인수는 장의 레이블과 이 장의 섹션 레이블입니다. 따라서 해당 명령을 사용하면 참조가 어떻게 보이길 원하는지 알 수 있지만 분명히 2개의 하이퍼텍스트 링크가 있습니다. 어쨌든 그것과 비슷한 것이 있지만 섹션을 가리키는 하나의 고유한 링크가 있습니까?

다음은 완전한 독립 실행형 예입니다.

\documentclass[a4paper]{report}
\usepackage{hyperref}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}

\newcommand\fullref[2]{\ref{#1}.\ref{#2}}

\begin{document}

\begin{titlepage}
\end{titlepage}


\chapter{Hello}
\label{chapter: Hello}

\section{I'm Brian}
\label{section: Brian}

\section{I'm from the US}
\label{section: US}

A section from this chapter don't need to have the chapter number in it's reference : \ref{section: Brian}.

But a section from an other chapter should have it : \fullref{Chapter: Welcome}{section: Bob}


\chapter{Welcome}
\label{Chapter: Welcome}

\section{I'm Bob}
\label{section: Bob}

\section{I'm from the Canada}
\label{section: Canada}


\end{document}

답변1

나는 이것이 자주 발생하지 않는다고 가정합니다. 그렇지 않으면 처음부터 장을 포함하여 섹션 번호의 기본 계층 정의를 고수했을 것입니다. 이를 위해 다음을 사용하여 평소처럼 참조할 수 있는 기존 레이블 앞에 추가되는 새 \label매크로를 정의합니다 .\totallabel\thechapter.\ref

여기에 이미지 설명을 입력하세요

\documentclass[a4paper]{report}
\usepackage{hyperref}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}

\newcommand\fullref[2]{\ref{#1}.\ref{#2}}

\makeatletter
\newcommand{\totallabel}[1]{% \totallabel{<label>}
  \edef\@currentlabel{\thechapter.\@currentlabel}% Prepend \thechapter. to current label
  \label{#1}%
}
\makeatother

\begin{document}

\chapter{Hello}
\label{chap:Hello}

\section{I'm Brian}
\label{sec:Brian}

\section{I'm from the US}
\label{sec:US}

A section from this chapter don't need to have the chapter number in it's reference : \ref{sec:Brian}.

But a section from an other chapter should have it: \fullref{chap:Welcome}{sec:Bob} \ref{chap:sec:Bob}


\chapter{Welcome}
\label{chap:Welcome}

\section{I'm Bob}
\label{sec:Bob}\totallabel{chap:sec:Bob}% Insert a \totallabel

\section{I'm from the Canada}
\label{sec:Canada}

\end{document}

답변2

이것은 '해킹'을 사용합니다

레이블은 카운터 형식 출력 매크로 \@currentlabel의 현재 설정을 평가하는 접근 방식을 사용하여 저장됩니다.\the....

나는 그것을 일시적으로 복원하고, 사용하고 \@currentchapterlabel, 강제로 사용하고, \@currentlabel접두사가 붙은 자동 추가 레이블을 추가했습니다 chapterfullabel::. 이 레이블은 유사하게 모두 그룹으로 작성되어 외부 매크로가 영향을 받지 않습니다.

참조는 자동으로 label 태그를 사용하는 \fullref{labelname}을 사용하여 수행됩니다. 나는 \ref그러한 것들을 재정의하는 것을 권장하지 않습니다 .

\documentclass{book}

\usepackage{xpatch}

\usepackage[hypertexnames=true]{hyperref}

% Save the definitions of \the.... macros first 

\let\latexthechapter\thechapter
\let\latexthesection\thesection
\let\latexthesubsection\thesubsection
\let\latexthesubsubsection\thesubsubsection

% Now redefine
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}

\makeatletter

% Generate a user-defined tag for the full chapter label
\newcommand{\fullreftagname}{chapterfulllabel::}

% Command for restoring \the.... macros
\newcommand{\@@restorechapterformat}{%
  \let\thechapter\latexthechapter
  \let\thesection\latexthesection
  \let\thesubsection\latexthesubsection
  \let\thesubsubsection\latexthesubsubsection
}%

\xapptocmd{\refstepcounter}{%
  \begingroup%
  \@@restorechapterformat%  Temporarily use the full format
  \protected@xdef\@currentchapterlabel
  {\csname p@#1\endcsname\csname the#1\endcsname}%
  \endgroup}{\typeout{Great Success}}{\typeout{Miserable fail}}

\AtBeginDocument{%  Must be here due to hyperref`s change
  \let\LaTeXLabel\label%
  \renewcommand{\label}[1]{%
    \begingroup
    \let\@currentlabel\@currentchapterlabel%
    \LaTeXLabel{\fullreftagname#1}% Write another label with \fullreftagname prefix
    \endgroup
    \LaTeXLabel{#1}% regular label
  }%
}

\newcommand{\fullref}[1]{%
  \ref{\fullreftagname#1}%
}
\makeatother


\begin{document}
\tableofcontents
\chapter{First}

\section{Introduction} \label{sec::introduction}

\subsection{Background} 

\chapter{Other chapter}

\section{Solution of everything} \label{sec::solution_of_everything}

\subsection{The world formula -- at last}

\subsubsection{More down} \label{subsubsec::something}

\chapter{Last chapter}

In \fullref{sec::introduction} we saw... whereas in \fullref{sec::solution_of_everything}, however in 
\fullref{subsubsec::something}

\end{document}

여기에 이미지 설명을 입력하세요

답변3

이건 어떻습니까? 그런데 여전히 목차 문제가 있습니다.

\documentclass[a4paper]{report}
\usepackage{hyperref}

\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname\quad}% 
{\csname #1@cntformat\endcsname}}

\def\section@cntformat{\arabic{section}\quad}
\def\subsection@cntformat{\arabic{section}.\arabic{subsection}\quad}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection.\arabic{subsubsection}}
\makeatother

\begin{document}

\begin{titlepage}
\end{titlepage}

\tableofcontents
\chapter{Hello}
\label{chapter: Hello}

\section{I'm Brian}
\label{section: Brian}
\subsection{I'm Brian}

\section{I'm from the US}
\label{section: US}

A section from this chapter don't need to have the chapter number in it's reference : \ref{section: Brian}.

But a section from an other chapter should have it : \ref{section: Bob}

\chapter{Welcome}
\label{Chapter: Welcome}

\section{I'm Bob}
\label{section: Bob}

\section{I'm from the Canada}
\label{section: Canada}

\end{document}

관련 정보