問題の概要

問題の概要

問題の概要

付録のセクション名は、論文本体のセクション名と同じにする必要があります。そのため、\namerefパッケージのコマンドを使用しましたnameref

[...]
\mainmatter
\section{My section name}
\label{mySection}
[...]
\appendix
\section{\nameref{mySection}}
[...]

これは動作します。ただし、book クラスの左ページのヘッダーには、ページの最初のセクションの名前が表示されるはずです。を使用すると\nameref、セクション名の代わりにヘッダーが表示されます??。なぜこのような動作をするのでしょうか。どうすれば回避できますか。

簡単な例

例えば、以下の内容main.texを含む新しいファイルを作成します。

\documentclass[10pt,a4paper]{book}
\usepackage{nameref}

\begin{document}

\section{Alice in wonderland}
\label{section:alice}

\pagebreak
a %Dummy text otherwise calling \pagebreak twice only skips one page
\pagebreak %Need to skip two pages, not just one because only the header of the left page of the book class displays the section name, not the one of the right page

%\section{Alice in wonderland} %Writes the header correctly
\section{\nameref{section:alice}} %Header shows "??"

\end{document}

でコンパイルします。3 ページ目の上部に、の代わりにpdflatex main.texヘッダーが表示されます。0.2 ??0.2 ALICE IN WONDERLAND

答え1

デフォルトでは、bookクラスはすべてのヘッダーを大文字にします。この大文字化の仕組みは、\nameref{section:alice}ヘッダーに書き込まれるときに実際のデータが

\nameref{SECTION:ALICE}

これは未知のラベルへの参照であり、MWEのログにも表示されます。

LaTeX Warning: Reference `SECTION:ALICE' on page 3 undefined on input line 17

汚い修正としては、\label{SECTION:ALICE}代わりに実際に使用することです。


最近では、大文字だけのヘッダーを使用すると怒鳴っているように見られる可能性があるため、通常は自動大文字変換を無効にします。

通常、私はクラスを決して使用しません。代わりに、機能が組み込まれているクラスbookを として使用します。また、次のようにデフォルトの大文字を無効にするのは非常に簡単です。memoirnameref\titlerefmemoir

\nouppercaseheads
\pagestyle{headings} % reactivate the page style (\nou.. changes an internal macro in the headers, thus the header macros has to be applied again)

このmemoirクラスは、クラスの代わりとして利用できますbook

答え2

使用できますディエゴ・ディアスのトリックはこちらパッケージからインスピレーションを得たものですrefcount

\documentclass[10pt,a4paper]{book}
\usepackage{nameref}

\makeatletter
\newcommand{\getnamereftext}[1]{%
  \@ifundefined{r@#1}{}{%
    \unexpanded\expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\@thirdoffive\csname r@#1\endcsname
    }%
  }%
}
\makeatother

\begin{document}

\section{Alice in wonderland}
\label{section:alice}

\clearpage
a %Dummy text otherwise calling \pagebreak twice only skips one page
\clearpage %Need to skip two pages

\section{\getnamereftext{section:alice}}

\end{document}

ここに画像の説明を入力してください

答え3

と同様\nameref{}に機能する は、コマンド\label{}の外側に配置する必要があります\section{}

\section{\nameref{section:alice}} %Header shows "??"

\section{ Alice in Wonderland} \nameref{section:alice} %works, returns label

daleifが指摘したように、\label{}との両方\nameref{}を大文字にすると、\label{}

関連情報