Das Erweitern des Abschnittstitels über Ränder und gerade/ungerade funktioniert nicht mit fancyhdr

Das Erweitern des Abschnittstitels über Ränder und gerade/ungerade funktioniert nicht mit fancyhdr

Ich arbeite mit folgendem Code:

\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}

Dadurch entsteht ein Artikel mit einem bestimmten Stil für Abschnittstitel. Meine Fragen sind: 1.) Wie kann ich die Breite des grauen Felds hinter einem Abschnittstitel anpassen, sodass es über die Randnotizen hinausragt?

2.) Gibt es einen Grund, warum die Überschriften trotz Angabe von LO, RE immer nur auf der linken Seite erscheinen, egal ob die Seite gerade oder ungerade ist? Ich hätte die Überschrift UNIT gerne auf der linken Seite für ungerade Seiten und auf der rechten für gerade Seiten.

Antwort1

Es gibt keine twoside=semiOption für Artikel.

Sie können beidseitigen Druck (für abwechselnde Kopfzeilen) emulieren, indem Sie die linken und rechten Felder verwenden.

Ich habe auch die Definition für den grauen Balken unter dem Abschnittstitel vereinfacht. Vergessen Sie nicht, festzulegen 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}

Bildbeschreibung hier eingeben

Antwort2

Dies ist keine Antwort, die eine vollständige Lösung bietet, da nicht klar ist, welche Aspekte Ihres Layouts Sie beibehalten und welche Sie löschen möchten. Wahrscheinlich ist es nicht das, was Sie wirklich wollen, alle Aspekte beizubehalten.

Bezüglich Ihrer ersten Frage: Definieren Sie die Titelzeile als

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

Dann wird der graue Balken bis zum Rand des Seitenrands reichen. Wie Sie unten sehen, kollidiert er jedoch mit den Kommentaren im Seitenrand. Daher ist es möglicherweise besser, den Balken auf den Textbereich zu beschränken oder keine Kommentare im Seitenrand zu haben.

Zu deiner zweiten Frage: Beachte, dass die Logdatei eine Warnung enthält, die twoside=semiignoriert wurde, da es für die Artikelklasse keine solche Option gibt. Und bei einseitigen Dokumenten gibt es vom Seitenstil her nur ungerade Seiten. Wenn du die Option verwendest twoside, hast du zwar beide Überschriftenarten, musst aber die Ränder über das Geometriepaket anpassen. Außerdem springen in diesem Fall auch die Randkommentare.

Im folgenden Code habe ich die Zeile eingefügt

\usepackage{showframe}

um das Seitenlayout anzuzeigen. Entfernen Sie es für das endgültige Dokument.

Bildbeschreibung hier eingeben

\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}

verwandte Informationen