\section
ブックマークを作成すると\section*
、アンカーは異なる場所にある 2 つのセクションを指します。小さな垂直スペースが追加されます\section*
( .png
-files を参照)。アンカーが同じ場所に配置されていることを確認するにはどうすればよいでしょうか。
私は、このソリューションが必要なのは、付録一覧、エントリは と にのみ表示され、 は必要LoA
ありませんがToC
、テキストと にはセクション番号が必要ですLoA
。
\documentclass{book}
\usepackage{bookmark}
\hypersetup{bookmarksnumbered=true}
\begin{document}
\chapter{Chapter one}
References here:
ref: \ref{chap2} (chapter)
ref: \ref{chap2sec1} (section)
ref: \ref{chap2sec2} (star-section)
\chapter{Chapter two}\label{chap2}
...(contents of chapter 2)...
\section{Sec one}\label{chap2sec1}
...(contents of chapter 2 - section 1)...
\refstepcounter{section}
\section*{\thesection{}{\quad}Sec two}\label{chap2sec2}
\addcontentsline{toc}{section}{\protect\numberline{\thesection}Sec two}
...(contents of chapter 2 - section 2)...
\end{document}
編集(1):の間違ったブックマーク アンカーを示すために赤いボックスを追加しました\section*
。セクション間の間隔は正しいですが、アンカー設定だけが間違っています。
答え1
動作方法を調整し\section
、いくつかの小さな変更を加えるだけで、\section*
同じように動作させることができます。\section
\documentclass{book}
\usepackage{bookmark}
\hypersetup{bookmarksnumbered=true}
\usepackage{xparse}
\makeatletter
\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname\space}% Just for this example
\let\oldsection\section
\let\oldaddcontentsline\addcontentsline
\RenewDocumentCommand{\section}{s o m}{%
\IfBooleanTF{#1}
{{% \section*
\renewcommand{\refstepcounter}[1]{\phantomsection}% Gobble counter stepping
\renewcommand{\@seccntformat}[1]{}% Gobble section number formatting
\renewcommand{\addcontentsline}[3]{\oldaddcontentsline{toc}{section}{#3}}% Next entry _will_ be a section
\oldsection{#3}% \section*[.]{..}
}}{% \section
\IfNoValueTF{#2}
{\oldsection{#3}}% \section{..}
{\oldsection[#2]{#3}}% \section[.]{..}
}%
}
\makeatother
\begin{document}
\chapter{Chapter one}
References here:
ref: \ref{chap2} (chapter)
ref: \ref{chap2sec1} (section)
ref: \ref{chap2sec2} (star-section)
\chapter{Chapter two}\label{chap2}
...(contents of chapter 2)...
\section{Sec one}\label{chap2sec1}
...(contents of chapter 2 - section 1)...
\stepcounter{section}%
\section*{\thesection{} Sec two}\label{chap2sec2}
...(contents of chapter 2 - section 2)...
\end{document}
xparse
\section
通常は(スター付きバージョン、オプション、および必須の引数)によって管理される引数を簡単に取得するために使用されます。
が呼び出されると\section*
、 に典型的な 3 つの項目が更新されます\section*
。
カウンターステップ
\refstepcounter
は何も実行されません。セクション カウンタのフォーマット マクロ
\@seccntformat
は何も実行しないものに変換されます。コンテンツ関連の書き込みは入力に固有のものとなるように更新され、
\numberline
印刷の可能性を回避します。
\section
と\section*
はヘッダーを印刷するために同じ手順 (つまり、内部的に ) を使用するようになったため\@sect
、出力ハイパーリンクは同じ垂直位置にジャンプします。
あなたの例は、セクション 2.2 の一部としてマニュアルが含まれているため、少し不自然です\refstepcounter
。ただし、上記で定義した更新バージョンを使用したハイパーリンク ジャンプには問題はないと思います\section
。