セクション タイトルを余白を超えて拡張すると、fancyhdr では奇数/偶数が機能しない

セクション タイトルを余白を超えて拡張すると、fancyhdr では奇数/偶数が機能しない

私は次のコードを使って作業しています:

\documentclass[11pt,a4paper,twoside=semi]{article}


\usepackage{kantlipsum}
\usepackage{tikz}

%*****************Margins and MarginNotes******************

\usepackage[top=2.8cm, bottom=2.8cm,outer=7cm, inner=1.75cm, marginparwidth=4.25cm, marginparsep=0.75cm]{geometry}

%*******************Header & Footer***********************
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LO,RE]{\footnotesize UNIT TITLE}
\fancyfoot[LO,RE]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\setlength{\headwidth}{\textwidth}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth}

%***********************Document*******************
\usepackage[explicit]{titlesec}

\titleformat{\section}{\sffamily \bf \Large}{}{0em}
{%
\begingroup
  \color{gray!30}%
  \titleline{\leaders\hrule height 1.75em \hskip 4pt plus 1.2 fill \kern 0pt\relax}%
\endgroup\vskip-1.323em\hskip0.5em\sffamily \thesection\hskip1em#1
\nobreak
}

\begin{document}
\section{Section 1}
\kant[12]
\marginpar{The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}
\kant[8]
\marginpar{The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}
\kant[7]\marginpar{The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}
\section{Section 1}
\kant[7]
\marginpar{The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}

\newpage

\end{document}

これにより、特定のスタイルのセクション タイトルを持つ記事が作成されます。質問は次のとおりです。1) セクション タイトルの後ろにある灰色のボックスの幅を調整して、余白の注釈の上に広げるにはどうすればよいでしょうか。

2.) 見出しに LO、RE を指定しているにもかかわらず、ページが奇数か偶数かにかかわらず、左側にしか表示されないのはなぜですか? UNIT タイトル ヘッダーを奇数ページでは左側に、偶数ページでは右側に表示したいと思います。

答え1

twoside=semi記事のオプションはありません。

左フィールドと右フィールドを使用して、両面印刷 (交互ヘッダー用) をエミュレートできます。

セクション タイトルの下の灰色のバーの定義も簡略化しました。 を設定することを忘れないでくださいheadheight

\documentclass[11pt,a4paper]{article}

\usepackage{kantlipsum}
\usepackage{tikz}

%*****************Margins and MarginNotes******************

\usepackage[
  top=2.8cm,
  bottom=2.8cm,
  outer=7cm,
  inner=1.75cm,
  marginparwidth=4.25cm,
  marginparsep=0.75cm,
  headheight=13.6pt,
  %showframe,% remove for production version
]{geometry}

%*******************Header & Footer***********************
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset[R]{\dimexpr\marginparsep+\marginparwidth}
\fancyfootoffset[R]{\dimexpr\marginparsep+\marginparwidth}
\fancyhead[L]{\ifodd\value{page}\footnotesize UNIT TITLE\fi}
\fancyhead[R]{\ifodd\value{page}\else\footnotesize UNIT TITLE\fi}
\fancyfoot[L]{\ifodd\value{page}\thepage\fi}
\fancyfoot[R]{\ifodd\value{page}\else\thepage\fi}
\renewcommand{\headrulewidth}{0pt}

%***********************Document*******************
\usepackage{titlesec}

\titleformat{\section}
  {\sffamily\bfseries\Large}
  {}
  {0em}
  {\graybackground}

\newcommand{\graybackground}[1]{%
  \makebox[\textwidth][l]{%
    \colorbox{gray!30}{%
      \parbox{\dimexpr\textwidth+\marginparsep+\marginparwidth-2\fboxsep}{
        \vspace{3pt}
        #1\par
        \vspace{3pt}
      }%
    }%
  }%
}

\begin{document}

some text to get a page
\clearpage

\section{Section 1}
\kant[12]
\marginpar{\sloppy The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}
\kant[8]
\marginpar{\sloppy The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}
\kant[7]\marginpar{\sloppy The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}
\section{Section 2}
\kant[7]
\marginpar{\sloppy The reader should be careful to observe that the objects in space and time are the clue to the discovery of, certainly, our a priori knowledge, by means of analytic unity.}

\newpage

\end{document}

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

答え2

これは完全な解決策となる答えではありません。レイアウトのどの部分を保持し、どの部分を削除するかが明確ではないためです。すべてを保持することは、おそらく本当に望んでいることではないはずです。

最初の質問に関して、タイトル行を次のように定義します。

\titleline{\makebox[0pt][l]{\rule{\headwidth}{1.75em}}}

すると、灰色のバーが余白の境界まで伸びます。ただし、以下に示すように、余白のコメントと衝突するため、バーをテキスト領域に限定するか、余白にコメントがないようにする方がよい場合があります。

2 番目の質問に関しては、ログ ファイルには警告が含まれていますがtwoside=semi、記事クラスにはそのようなオプションがないため無視されていることに注意してください。また、片面文書の場合、ページ スタイルに関する限り、奇数ページしかありません。オプションを使用するとtwoside、両方の種類の見出しを使用できますが、ジオメトリ パッケージを使用して余白を調整する必要があります。さらに、この場合、余白のコメントもジャンプします。

以下のコードには、次の行が含まれています。

\usepackage{showframe}

ページレイアウトを表示します。最終文書では削除します。

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

\documentclass[11pt,a4paper]{article}

\usepackage{kantlipsum}
\usepackage{tikz}

%*****************Margins and MarginNotes******************

\usepackage[top=2.8cm, bottom=2.8cm,outer=7cm, inner=1.75cm, marginparwidth=4.25cm, marginparsep=0.75cm]{geometry}

%*******************Header & Footer***********************
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LO,RE]{\footnotesize UNIT TITLE}
\fancyfoot[LO,RE]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\setlength{\headwidth}{\textwidth}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth}
\usepackage{showframe}

%***********************Document*******************
\usepackage[explicit]{titlesec}

\titleformat{\section}{\sffamily \bf \Large}{}{0em}
{%
\begingroup
  \color{gray!30}%
  \titleline{\makebox[0pt][l]{\rule{\headwidth}{1.75em}}}%
\endgroup\vskip-1.323em\hskip0.5em\sffamily \thesection\hskip1em#1
\nobreak
}

\begin{document}
\section{Section 1}
\kant[12] \marginpar{The reader should be careful to observe that the
  objects in space and time are the clue to the discovery of,
  certainly, our a priori knowledge, by means of analytic unity.}
\kant[8] \marginpar{The reader should be careful to observe that the
  objects in space and time are the clue to the discovery of,
  certainly, our a priori knowledge, by means of analytic unity.}
\kant[7]\marginpar{The reader should be careful to observe that the
  objects in space and time are the clue to the discovery of,
  certainly, our a priori knowledge, by means of analytic unity.}
\section{Section 1}
\kant[7] \marginpar{The reader should be careful to observe that the
  objects in space and time are the clue to the discovery of,
  certainly, our a priori knowledge, by means of analytic unity.}

\newpage

\end{document}

関連情報