當 head 為 textwithmarginpar 時,影像寬度 = headwidth

當 head 為 textwithmarginpar 時,影像寬度 = headwidth

使用scrbookscrpage2的 headwith textwithmarginpar,我嘗試將文字正文中的各個圖像設定為更寬的頭寬。\hoffset0pt。然而,將\textwidth,\marginparwidth\marginparsep相加得到的不僅僅是頭寬:圖像和頁碼並不在同一行結束。似乎還有另一個長度影響頭寬。感謝您的任何想法!

\documentclass[10pt]{scrbook}
\usepackage{xltxtra}
\usepackage[paperwidth=170mm,paperheight=240mm]{geometry}
\usepackage{scrpage2}
\usepackage{mwe}
\usepackage{ifoddpage}

\KOMAoptions{DIV=calc,BCOR=15mm}   

\newlength{\TextwithMargin}
\setlength{\TextwithMargin}{\textwidth}
\addtolength{\TextwithMargin}{\marginparwidth}
\addtolength{\TextwithMargin}{\marginparsep}

\pagestyle{scrheadings}
\clearscrheadfoot
\lehead[]{{\pagemark}\quad\rightmark}
\rohead[]{{\rightmark}\quad\pagemark}
\setheadwidth[]{textwithmarginpar} % As expected, I get the same result when using \TextwithMargin.


\begin{document}
\thispagestyle{scrheadings}
\addsec{Section}
\begin{figure}[hptp]
\checkoddpage
\edef\side{\ifoddpage l\else r\fi}%
\makebox[\textwidth][\side]{%
\parbox{\TextwithMargin}{%
\includegraphics[width=\linewidth]{example-image}
\caption{Example image.}
}}
\end{figure}
\end{document}

答案1

我將使用 aheadsepline來顯示標題的寬度。

scrlayer-scrpage選項headwidth=textwithmarginpar按預期工作:

\documentclass[10pt]{scrbook}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{xltxtra}
\usepackage[paperwidth=170mm,paperheight=240mm]{geometry}
\KOMAoptions{DIV=calc,BCOR=15mm}

\newlength{\TextwithMargin}
\setlength{\TextwithMargin}{%
  \dimexpr\textwidth+\marginparwidth+\marginparsep\relax}

\usepackage[headwidth=textwithmarginpar,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\lehead{{\pagemark}\quad\rightmark}
\rohead{{\rightmark}\quad\pagemark}

\usepackage{mwe}
\begin{document}
\addsec{Section}
\blindtext[4]
\begin{figure}[htb]
\Ifthispageodd{\edef\side{l}}{\edef\side{r}}%
\makebox[\textwidth][\side]{%
\parbox{\TextwithMargin}{%
\includegraphics[width=\linewidth]{example-image}
\caption{Example image.}
}}
\end{figure}
\end{document}

在此輸入影像描述

請注意,使用scrlayer-scrpagewith 選項headwidth=textwithmarginpar標題不會在文字區域上方居中。

另外,KOMA-Script 類別定義了一個命令\Ifthispageodd


這裡還有一個關於過時包的建議scrpage2

\documentclass[10pt]{scrbook}
%\providecommand*\Ifthispageodd{\ifthispageodd}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{xltxtra}
\usepackage[paperwidth=170mm,paperheight=240mm]{geometry}
\KOMAoptions{DIV=calc,BCOR=15mm}

\newlength{\TextwithMargin}
\setlength{\TextwithMargin}{\dimexpr\textwidth+\marginparwidth+\marginparsep\relax}

\usepackage[headsepline]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\lehead{{\pagemark}\quad\rightmark}
\rohead{{\rightmark}\quad\pagemark}
\setheadwidth[0pt]{textwithmarginpar}

\usepackage{mwe}
\begin{document}
\addsec{Section}
\blindtext[4]
\begin{figure}[htb]
\Ifthispageodd{\edef\side{l}}{\edef\side{r}}%
\makebox[\textwidth][\side]{%
\parbox{\TextwithMargin}{%
\includegraphics[width=\linewidth]{example-image}
\caption{Example image.}
}}
\end{figure}
\end{document}

結果與上面相同。

請注意,您必須使用可選參數:

\setheadwidth[0pt]{textwithmarginpar}

如果缺少可選偏移量,0pt標題將位於文字區域上方的中心。

在此輸入影像描述

相關內容