Cómo iniciar capítulo en la misma página y mantener mi encabezado y pie de página (ya tengo códigos disponibles)

Cómo iniciar capítulo en la misma página y mantener mi encabezado y pie de página (ya tengo códigos disponibles)

Configuración

Por el momento aquí está mi código para mi primera página y el diseño general de mi proyecto:

\documentclass[12pt, oneside]{book}

\usepackage{sectsty,fancyhdr}
\sectionfont{\LARGE\bfseries}
\usepackage{geometry}

\usepackage{lipsum}%remove 


% *******************************Margin Settings*******************************

\geometry{% margin settings, has to go first before \pagestyle{}
    paper=a4paper, 
    inner=2.5cm, % Inner margin
    outer=2.5cm, % Outer margin
    bindingoffset=0.0cm, % Binding offset
    top=2.5cm, % Top margin
    bottom=2.5cm, % Bottom margin
    headsep=3.5mm,% controles header  
    footskip=6.4mm,% controles footer
    %showframe,% show how the type block is set on the page
}

% ***************************Header/Footer Settings****************************

\sectionfont{\LARGE\bfseries}%this will keep the formattings of sections
\pagestyle{fancy}
\fancyhf{} % sets all head and foot elements empty.
\rhead{} % right side of upper footer 
\lhead{Project title} %left side 
\renewcommand{\headrulewidth}{2.0pt} % Width of the top line
\renewcommand{\footrulewidth}{1.0pt} % Bottom line 
\setlength{\headheight}{14.5pt}%used to remove the \fancyhf{} \headheight error
\rfoot{Page \thepage} % vice versa with the page number 
\lfoot{\leftmark} % Should show the name of section 

\makeatletter
\renewcommand{\sectionmark}[1]{%this avoids the \makecaptical of footers
  \markboth{\ifnum \c@secnumdepth>\z@ %this allowes symbols in foorters
      \thesection\hskip 1em\relax
    \fi #1}{}}
\makeatother


%****************************ADD NEW CODE HERE**********************



%***************************Title************************************
\newcommand{\mytitle}{
\begin{center}
{\Huge{\textbf{Project of...}}} 
\end{center}

\begin{center}
\textsc{\Large My name}\\[0.5cm] 
\end{center}

\begin{center}
{\large My ID number}\\[0.5cm] 
\end{center}
}

%------------------------------------------------------------------

% Begin 

%------------------------------------------------------------------

\begin{document}

\mytitle
\chapter{chapter 1}
\section{section 1.1}
\subsection{subection 1.1.1}
  \lipsum%remove

\chapter{chapter 2}
\section{section 2.1}
\subsection{subection 2.1.1}
  \lipsum%remove

%------------------------------------------------------------------

% end 

%------------------------------------------------------------------ 


\end{document}  

El problema

Este es el "código 1" (que se agregará a mis preámbulos en la sección "nuevo código" anterior):

\fancypagestyle{chapterstart}{% 1st page of the chapters, i.e. no new page for chapter
}
\makeatletter

\def\chapter{
\pagestyle{chapterstart}
\secdef\@chapter\@schapter}

\renewcommand\thesection{\@arabic\c@section} 

\makeatother

Este código me permite comenzar un nuevo capítulo en la misma página y también mantiene mi encabezado y pie de página en la misma página. Sin embargo, esto restablece los números de sección de cada capítulo. por ejemplo, "capítulo 2, sección 2.1" pasaría a ser "capítulo 2, sección 1.1".

Este es el "código 2" (se agregará arriba, como antes):

\usepackage{etoolbox}
\makeatletter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
\makeatother

Este código me permite comenzar un capítulo en la misma página y mantiene la numeración original para la sección, por ejemplo, "capítulo 2, sección 2.1" permanecería como "capítulo 2, sección 2.1". Sin embargo, mi encabezado y pie de página no se incluirán en la misma página.

La meta

¿Cómo combino el "código 1" y el "código 2" para permitirme: comenzar un nuevo capítulo en la misma página, mantener mi encabezado y pie de página en las páginas del nuevo capítulo y mantener el formato de la numeración de las secciones?

Respuesta1

El código 1 habría funcionado sin \renewcommand\thesection{\@arabic\c@section}. Esto omite el número del capítulo (el original es \thechapter.\@arabic\c@section).

Pero hay una desventaja: no establece \@afterindentfalse, lo que daría lugar a un primer párrafo con sangría después del título del capítulo para el texto normal.

La línea \pagestyle{chapterstart}no es necesaria. Los \chapterconjuntos originales \thispagestyle{plain}. Sin esto, el estilo de la página no cambia.

En el código 2 \chapterse cambia con \patchcmd, lo que tiene la ventaja de que se puede emitir una advertencia o un error si el comando cambió y ya no se puede parchear (último argumento, ejemplo en el código).

\documentclass[12pt, oneside]{book}

\usepackage{sectsty,fancyhdr}
\sectionfont{\LARGE\bfseries}
\usepackage{geometry}

\usepackage{lipsum}%remove 


% *******************************Margin Settings*******************************

\geometry{% margin settings, has to go first before \pagestyle{}
    paper=a4paper, 
    inner=2.5cm, % Inner margin
    outer=2.5cm, % Outer margin
    bindingoffset=0.0cm, % Binding offset
    top=2.5cm, % Top margin
    bottom=2.5cm, % Bottom margin
    headsep=3.5mm,% controles header  
    footskip=6.4mm,% controles footer
    %showframe,% show how the type block is set on the page
}

% ***************************Header/Footer Settings****************************

\sectionfont{\LARGE\bfseries}%this will keep the formattings of sections
\pagestyle{fancy}
\fancyhf{} % sets all head and foot elements empty.
\rhead{} % right side of upper footer 
\lhead{Project title} %left side 
\renewcommand{\headrulewidth}{2.0pt} % Width of the top line
\renewcommand{\footrulewidth}{1.0pt} % Bottom line 
\setlength{\headheight}{14.5pt}%used to remove the \fancyhf{} \headheight error
\rfoot{Page \thepage} % vice versa with the page number 
\lfoot{\leftmark} % Should show the name of section 

\makeatletter
\renewcommand{\sectionmark}[1]{%this avoids the \makecaptical of footers
  \markboth{\ifnum \c@secnumdepth>\z@ %this allowes symbols in foorters
      \thesection\hskip 1em\relax
    \fi #1}{}}
\makeatother


%****************************ADD NEW CODE HERE**********************



%***************************Title************************************
\newcommand{\mytitle}{
\begin{center}
{\Huge{\textbf{Project of...}}} 
\end{center}

\begin{center}
\textsc{\Large My name}\\[0.5cm] 
\end{center}

\begin{center}
{\large My ID number}\\[0.5cm] 
\end{center}
}

%------------------------------------------------------------------
% Code 2
\usepackage{etoolbox}
\makeatletter
% no new page for \chapter
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}
% don't change the pagestyle
\patchcmd{\chapter}{\thispagestyle{plain}}{}{}{%
    % example for a warning, 'Package' in text necessary to make TexStudio show it.
    \GenericWarning{(preamble)\@spaces\@spaces\@spaces\@spaces}{Package preamble Warning: patching \string\chapter\space did not work.}}
}
% allow floats on top of the page with a new chapter
\patchcmd{\chapter}{\global\@topnum\z@}{}{}{}
% if not commented out, first paragraph will be indented
%\patchcmd{\chapter}{\@afterindentfalse}{}{}{}
%\makeatother

%------------------------------------------------------------------

% Begin 

%------------------------------------------------------------------

\begin{document}

\mytitle
\chapter{chapter 1}
\section{section 1.1}
\subsection{subection 1.1.1}
  \lipsum%remove

\chapter{chapter 2}
\section{section 2.1}
\subsection{subection 2.1.1}
  \lipsum%remove

%------------------------------------------------------------------

% end 

%------------------------------------------------------------------ 


\end{document}  

información relacionada