헤더의 섹션 이름

헤더의 섹션 이름

논문 보고서를 작성 중인데 페이지 헤더에 섹션 이름을 유지하고 싶습니다. 지금은 페이지 번호가 바닥글 중앙에 있는데 그대로 유지하고 싶습니다. 섹션 이름을 유지하기 위해 fancyhdr을 사용해 보았지만 문제는 \frontmatter에 있는 내용의 헤더와 그림 목록도 표시한다는 것입니다. 어떤 제안이라도 도움이 될 것입니다.

%\documentclass[12pt,a4paper]{article}
\documentclass[12pt,a4paper]{article}   
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

%function definition for starting intro from first section.
\def\frontmatter{%
    \pagenumbering{roman}
    \setcounter{page}{1}
    \renewcommand{\thesection}{\Roman{section}}
}%

\def\mainmatter{%
    \pagenumbering{arabic}
    \setcounter{page}{1}
    \setcounter{section}{0}
    \renewcommand{\thesection}{\arabic{section}}
}%
\usepackage{fontspec}
%\setmainfont{Times New Roman}

\usepackage{makecell}
\usepackage{graphicx}

예상되는 내용은 다음과 같습니다. 여기에 이미지 설명을 입력하세요

답변1

자신만의 페이지 스타일을 사용 fancyhdr및 정의하고 및 \pagestyle{...}정의 끝에 사용할 수 있습니다 .\mainmatter\frontmatter
페이지 스타일 설정

% Page Layout
\setlength{\headheight}{15pt} % otherwise fancyhdr gives warning
\fancyhf{}

\fancypagestyle{frontmatter}{
    \fancyhf{} % clearing headers and footers
    \fancyfoot[C]{\thepage} % page number centered in the footer
    \renewcommand{\headrulewidth}{0pt} % Create an invisible header ruler line
}

\fancypagestyle{mainmatter}{
    \fancyhf{}
    \fancyhead[C]{\leftmark} % \leftmark gives current section with its number you may want to use \nouppercase
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0.3pt} % Create an header ruler line
}

답변2

귀하의 요구 사항에 따라 이는 패키지 없이 달성될 수 있습니다 fancyhdr. 다음은 예제 코드입니다.

\documentclass[12pt,a4paper]{article}   
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pagestyle `headings` setting %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\ps@headings{%
    \def\@oddfoot{\hfil\thepage\hfil}
    \def\@oddhead{\hfil\slshape\rightmark\hfil}%
    \def\@evenhead{\hfil\slshape\rightmark\hfil}%
    \let\@mkboth\markboth
    \def\sectionmark##1{%
      \markright {%
        \ifnum \c@secnumdepth >\m@ne
          \thesection\quad
        \fi
        ##1}}}
\makeatother

%%%%%%%%%%%%%%%%%%
% other packages %
%%%%%%%%%%%%%%%%%%
\usepackage{fontspec}
%\setmainfont{Times New Roman}
\usepackage{makecell}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{mwe}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%
% title page %
%%%%%%%%%%%%%%
\thispagestyle{empty}
\null\vfil
\begin{center}
\textbf{My Title}
\vskip 3em
\textbf{My Name}
\end{center}
\vfil\null
\clearpage

%%%%%%%%%%%%%%%
% frontmatter %
%%%%%%%%%%%%%%%
\pagenumbering{roman}
\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables
\clearpage

%%%%%%%%%%%%%%
% mainmatter %
%%%%%%%%%%%%%%
\pagenumbering{arabic}
\pagestyle{headings}
\section{Introduction}
\lipsum[1]
\clearpage

\section{Analysis}
\lipsum[2]
\begin{figure}[ht]
    \centering
    \includegraphics{example-image-a}
    \caption{figure 1}
    \label{fig:my_label}
\end{figure}
\clearpage

\section{Results}
\begin{table}[ht]
    \centering
    \begin{tabular}{c|c}
         1&2  \\
         3&4 
    \end{tabular}
    \caption{table 1}
    \label{tab:my_label}
\end{table}
\lipsum[3]

\end{document}

관련 정보