將部分標題擴展到邊距和奇數/偶數不與 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 標題位於左側,偶數頁的 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}}}

然後灰色條將延伸到頁邊距的邊界。但是,如下所示,它與頁邊空白中的註釋發生衝突,因此最好將該欄限制在文字區域,或在頁邊空白中沒有註釋。

關於第二個問題,請注意日誌檔案包含已被忽略的警告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}

相關內容