같은 페이지에서 장을 시작하고 머리글과 바닥글을 유지하는 방법(이미 사용 가능한 코드가 있음)

같은 페이지에서 장을 시작하고 머리글과 바닥글을 유지하는 방법(이미 사용 가능한 코드가 있음)

설정

현재 내 프로젝트의 첫 번째 페이지와 일반 레이아웃에 대한 코드는 다음과 같습니다.

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

문제

이것은 "코드 1"입니다(위의 "새 코드" 섹션의 서문에 추가됨).

\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

이 코드를 사용하면 같은 페이지에서 새 장을 시작할 수 있으며 머리글과 바닥글도 같은 페이지에 유지됩니다. 그러나 이렇게 하면 각 장의 섹션 번호가 재설정됩니다. 예를 들어 "2장, 섹션 2.1"은 "2장, 섹션 1.1"이 됩니다.

이것은 "코드 2"입니다(이전과 같이 위에 추가됨).

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

이 코드를 사용하면 같은 페이지에서 장을 시작할 수 있고 섹션을 나눌 때 원래 번호를 유지할 수 있습니다. 예를 들어 "2장, 섹션 2.1"은 "2장, 섹션 2.1"로 유지됩니다. 하지만 내 머리글과 바닥글은 같은 페이지에 포함되지 않습니다.

목표

"코드 1"과 "코드 2"를 결합하여 동일한 페이지에서 새 장을 시작하고, 새 장 페이지에 머리글과 바닥글을 유지하고, 섹션 번호 지정 형식을 유지하려면 어떻게 해야 합니까?

답변1

코드 1은 \renewcommand\thesection{\@arabic\c@section}. 장 번호가 생략되었습니다(원본은 \thechapter.\@arabic\c@section).

그러나 단점이 있습니다. 설정되지 않아 \@afterindentfalse일반 텍스트의 경우 장 제목 뒤에 첫 번째 단락이 들여쓰기됩니다.

\pagestyle{chapterstart}은 필요하지 않습니다. 원본 \chapter세트 \thispagestyle{plain}. 이것이 없으면 페이지 스타일이 변경되지 않습니다.

코드 2에서는 \chapter로 변경됩니다 \patchcmd. 이는 명령이 변경되어 더 이상 패치할 수 없는 경우 경고나 오류가 표시될 수 있다는 이점이 있습니다(마지막 인수, 코드의 예).

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

관련 정보