Extender el título de la sección sobre los márgenes e impar/par no funciona con fancyhdr

Extender el título de la sección sobre los márgenes e impar/par no funciona con fancyhdr

Estoy trabajando con el siguiente código:

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

Esto produce un artículo con un estilo específico de título de sección. Mis preguntas son: 1.) ¿Cómo puedo ajustar el ancho del cuadro gris detrás del título de una sección, para que se extienda sobre las notas al margen?

2.) ¿Hay alguna razón por la cual, a pesar de especificar LO, RE para los títulos, todavía aparecen solo en el lado izquierdo, a pesar de que la página sea par o impar? Me gustaría tener el encabezado del título UNIT a la izquierda para las páginas impares y a la derecha para las páginas pares.

Respuesta1

No hay twoside=semiopción para el artículo.

Puede emular la impresión a dos caras (para encabezados alternos) utilizando los campos izquierdo y derecho.

También simplifiqué la definición de la barra gris debajo del título de la sección. No olvides configurar 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}

ingrese la descripción de la imagen aquí

Respuesta2

Esta no es una respuesta que brinde una solución completa porque no está claro qué aspectos de su diseño desea conservar y cuáles eliminar; conservarlos todos probablemente no sea lo que realmente desea.

Con respecto a su primera pregunta, defina el título como

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

Luego la barra gris se extenderá hasta el borde del margen. Sin embargo, como verá a continuación, choca con los comentarios en el margen, por lo que puede ser mejor limitar la barra al área de texto o no tener comentarios en el margen.

Con respecto a su segunda pregunta, tenga en cuenta que el archivo de registro contiene una advertencia que twoside=semise ha ignorado, ya que no existe tal opción para la clase de artículo. Y en los documentos de una sola cara, en lo que al estilo de página se refiere, sólo hay páginas impares. Si usas la opción twoside, tienes ambos tipos de encabezados, pero tendrás que adaptar los márgenes a través del paquete de geometría. Además, en este caso los comentarios al margen también saltarán.

En el siguiente código, he incluido la línea

\usepackage{showframe}

para mostrar el diseño de la página. Quítelo para el documento final.

ingrese la descripción de la imagen aquí

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

información relacionada