
현재 프로젝트에서 인쇄하고 배포할 수 있는 워크시트를 만들고 싶습니다. 이를 위해 각 워크시트의 페이지 번호를 재설정하고 싶지만 워크시트에 두 페이지 이상이 있는 경우(예: 뒷페이지가 있는 경우)에만 페이지 번호를 표시하고 싶습니다. 워크시트에 페이지가 하나만 있는 경우 페이지 번호를 숨겨서 페이지 2 등이 어디에 있는지 불필요하게 혼동하지 않도록 해야 합니다. 로 이 작업을 수행할 수 있나요 fancyhdr
?
여기는 MWE입니다. 각 워크시트는 자체 섹션으로 시작됩니다. 저는 LuaLaTeX를 사용합니다.
\documentclass[a4paper, twoside, 12pt]{extarticle}
\usepackage{graphicx}
\usepackage[left=2.5cm,right=2.5cm,top=3cm,bottom=4cm,headheight=0mm, footskip=10mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[RO,RE]{Bla}
\fancyhead[LO,LE]{Bla}
\fancyfoot{}
\fancyfoot[LE,RO]{}
\fancyfoot[LO,CE]{}
\fancyfoot[CO,CE]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\renewcommand{\thesection}{\arabic{section}.}
\makeatletter
\renewcommand*{\@seccntformat}[1]{\csname the#1\endcsname\hspace{0.25cm}}
\makeatother
\definecolor{mainblue}{rgb}{0.0, 0.28, 0.67}
\usepackage[math-style=ISO, bold-style=ISO]{unicode-math}
\setmathfont{Garamond-Math.otf}[StylisticSet={7,9}]
\setlength{\parindent}{0em}
\setlength{\parskip}{0.25\baselineskip}
\usepackage{titlesec}
\titleformat*{\section}{\LARGE\bfseries\sffamily\color{mainblue}\centering}
\usepackage{fontspec}
\setmainfont{EB Garamond}
\defaultfontfeatures{Scale=MatchUppercase}
\setsansfont{Quattrocento Sans}
\newcommand{\head}[1]{%
\clearpage
\noindent
\vspace*{0.3cm}
\section{#1}
\vspace*{0.3cm}
\setcounter{page}{1}
}
\begin{document}
\head{Only one page}
Please hide page number below.
\head{Two pages}
First page. Please don't hide page number below.
\clearpage
Second page
\end{document}
새 페이지 스타일을 정의하여 이 작업을 수동으로 수행할 수 있다는 것을 알고 있지만 이는 나에게 너무 지루할 것입니다. 나는 하나의 프로젝트로 병합하고 싶은 워크시트를 이미 많이 만들었고, 모두 한 페이지에 들어갈 수 있는지 확인하는 데 많은 시간이 걸릴 것입니다. 내가 무엇을 할 수 있을지 아는 사람이 있나요?
답변1
\label
발행 직후 페이지 번호를 저장하는 데 사용하며 \clearpage
다음 실행 시 페이지 수가 1인지 테스트에 성공하고 \thepage
건너뜁니다.
내가 headheight
그걸 고쳤어할 수 없다헤더를 원하면 0으로 설정하세요. 또한 fontenc
와 함께 로드하면 안 됩니다 fontspec
. 먼저 패키지를 로드한 후 설정을 하도록 프리앰블을 재구성했습니다.
주변 \titlespacing
보다는 사용하세요 .\vspace
\section
\documentclass[a4paper, twoside, 12pt]{article}
\usepackage{graphicx}
\usepackage[
left=2.5cm,
right=2.5cm,
top=3cm,
bottom=4cm,
headheight=14.5pt,% <-- as recommended by fancyhdr
footskip=10mm
]{geometry}
%\usepackage[T1]{fontenc}% NOT with fontspec
\usepackage[dvipsnames]{xcolor}
\usepackage{refcount}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{fontspec}
\usepackage[math-style=ISO, bold-style=ISO]{unicode-math}
%%% fancyhdr
\fancyhead{}
\fancyhead[RO,RE]{Bla}
\fancyhead[LO,LE]{Bla}
\fancyfoot{}
\fancyfoot[LE,RO]{}
\fancyfoot[LO,CE]{}
\fancyfoot[CO,CE]{\maybethepage}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
%%% colors
\definecolor{mainblue}{rgb}{0.0, 0.28, 0.67}
%%% fontspec and unicode-math
\setmathfont{Garamond-Math.otf}[StylisticSet={7,9}]
\setmainfont{EB Garamond}
\defaultfontfeatures{Scale=MatchUppercase}
\setsansfont{Quattrocento Sans}
%%% generic
\makeatletter
\renewcommand*{\@seccntformat}[1]{\csname the#1\endcsname\hspace{0.25cm}}
\makeatother
\renewcommand{\thesection}{\arabic{section}.}
\setlength{\parindent}{0em}
\setlength{\parskip}{0.25\baselineskip}
%%% titlesec
\titleformat*{\section}{\LARGE\bfseries\sffamily\color{mainblue}\centering}
%%% personal commands
\makeatletter
\newcommand{\head}[1]{%
\label{NPAGES\arabic{section}}%
\clearpage
\setcounter{page}{1}%
\section{#1}
}
\AtEndDocument{%
\label{NPAGES\arabic{section}}%
}
\newcommand{\maybethepage}{%
\ifnum\getpagerefnumber{NPAGES\arabic{section}}=1
\else
\thepage
\fi
}
\makeatother
\begin{document}
\head{Only one page}
Please hide page number below.
\head{Two pages}
First page. Please don't hide page number below.
\clearpage
Second page
\end{document}
답변2
새 페이지에서 설정/시작 되므로 \section
페이지가 배송될 때 설정되므로 바닥글 내의 페이지 번호를 조건으로 지정할 수 있습니다. 그래서 업데이트하겠습니다.\head
현재 섹션의 (마지막) 페이지 번호를 캡처하도록 업데이트하겠습니다.
\newcommand{\head}[1]{%
\label{last-page-for-\thesection}% Store last page of current section
\clearpage
\vspace*{0.3cm}
\section{#1}
\vspace*{0.3cm}
\setcounter{page}{1}%
}
결승전도 캡쳐\section
의 마지막 페이지 번호도 캡처합니다.
\AtEndDocument{\label{last-page-for-\thesection}}% Capture last page of final section
그런 다음 다음을 사용하여 페이지 번호 설정을 조건으로 합니다.refcount
:
\usepackage{refcount}
% Condition on placing footer page number; if \section has more than 1 page
\fancyfoot[CO,CE]{\ifnum\getpagerefnumber{last-page-for-\thesection}>1 \thepage\fi}
다음은 완전한 최소한의 예입니다.
\documentclass[twoside]{extarticle}
\usepackage[dvipsnames]{xcolor}
\usepackage{fancyhdr}
\fancyhf{}% Clear header/footer
\fancyhead[RO,RE]{Right header}
\fancyhead[LO,LE]{Left header}
% Condition on placing footer page number; if \section has more than 1 page
\fancyfoot[CO,CE]{\ifnum\getpagerefnumber{last-page-for-\thesection}>1 \thepage\fi}
\renewcommand{\headrulewidth}{0pt}% Remove page header rule
\pagestyle{fancy}
\makeatletter
\renewcommand*{\@seccntformat}[1]{\csname the#1\endcsname.\hspace{0.25cm}}
\makeatother
\definecolor{mainblue}{rgb}{0.0, 0.28, 0.67}
\usepackage{titlesec}
\titleformat*{\section}{\LARGE\bfseries\sffamily\color{mainblue}\centering}
\usepackage{refcount}
\AtEndDocument{\label{last-page-for-\thesection}}% Capture last page of final section
\newcommand{\head}[1]{%
\label{last-page-for-\thesection}% Store last page of current section
\clearpage
\vspace*{0.3cm}
\section{#1}
\vspace*{0.3cm}
\setcounter{page}{1}%
}
\begin{document}
\head{Only one page}
Please hide page number below.
\head{Two pages}
First page. Please don't hide page number below.
\clearpage
Second page
\end{document}