隔離頁面以關閉標題

隔離頁面以關閉標題

我在整個文件中的每個頁面上都有標題\usepackage{fancyhdr},我想在某些帶有大數字的頁面上關閉該標題。如果我\thispagestyle{empty}正確使用它會刪除標題,但僅在隨機頁面上。我以為我可以透過將效果放在\newpage我的圖形之前然後使用 來將效果應用到正確的頁面\thispagestyle{empty},但結果仍然相同。我是否必須.tex為圖形創建一個新的,或者是否有更簡單的方法來做到這一點?

在我的main.tex文件中,我有\begin{document},然後是\pagestyle{fancy}\fancyfoot{}\lhead{\thepage}\rhead{\nouppercase{\rightmark}},後面是各種.tex文件。查看具體.tex文檔,我有很多帶有圖形插入的文本,如下所示:

\begin{figure}
\centering
\hbox{\hspace{-15mm} \includegraphics[scale=0.9]{my-image}}
\caption{my caption}
\label{myfigure}
\end{figure}

我嘗試在圖像之前添加\newpage後跟,但它會將其應用到錯誤的頁面。\thispagestyle{empty}我也\clearpage按照評論中的建議嘗試過,但發生了同樣的事情。

答案1

這似乎有效(儘管我們不知道您的\documentclass或其他很多嘗試和錯誤解決方案):

在此輸入影像描述在此輸入影像描述

\documentclass{article}

\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lipsum} % For text

\begin{filecontents}[overwrite]{chapter1.tex}
    \clearpage
    \thispagestyle{empty}
    \begin{figure}[p]
    \centering
    \hbox{\hspace{-15mm} \includegraphics[scale=0.9]{example-image-a}}
    \caption{my caption}
    \label{myfigure}
    \end{figure}
\end{filecontents}

\fancyhead{}
\fancyfoot{}
\fancyhead[L]{\thepage}
\fancyhead[R]{\nouppercase{\rightmark}}
\renewcommand{\headrulewidth}{0pt}

\pagestyle{fancy}

\begin{document}

\section{Test}
\lipsum[1-8]

\include{chapter1}

\lipsum[1-8]

\end{document}

中的部分只是我創建的filecontents您的文件之一的示例。.tex


若要將頁碼放在頁面上,[p]請使用下列命令:

在此輸入影像描述

\documentclass{article}

\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lipsum} % For text

\begin{filecontents}[overwrite]{chapter1.tex}
    \clearpage
    \thispagestyle{floatp}
    \begin{figure}[p]
    \centering
    \hbox{\hspace{-15mm} \includegraphics[scale=0.9]{example-image-a}}
    \caption{my caption}
    \label{myfigure}
    \end{figure}
\end{filecontents}

\fancyhead{}
\fancyfoot{}
\fancyhead[L]{\thepage}
\fancyhead[R]{\nouppercase{\rightmark}}
\renewcommand{\headrulewidth}{0pt}

% ------------ Added
\fancypagestyle{floatp}{%redefining plain pagestyle
    \fancyfoot{}
    \fancyhead{}
    \fancyfoot[R]{\thepage}         % Page number in bottom right
}

\pagestyle{fancy}

\begin{document}

\section{Test}
\lipsum[1-8]

\include{chapter1}

\lipsum[1-8]

\end{document}

答案2

\floatpagestyle{empty}只用於[p]大型浮標又如何?

另請參閱包裝 手冊中的\rotfloatpagestyle和。\thisfloatpagestylefloatpag

另請注意,fancyhdr提供 \iffloatpage{浮動頁面的值}{對其他頁面的價值}

\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{floatpag}\floatpagestyle{empty}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\section{foo1}\subsection{foo}\lipsum[1]
\section{foo}\subsection{foo}\lipsum[1]
\section{foo}\subsection{foo}\lipsum[1-2]
\begin{figure}[h]\includegraphics[]{example-image-9x16}\caption{foo}\end{figure}
\section{foo}\subsection{foo}\lipsum[1]
\begin{figure}[p]\centering\includegraphics[]{example-image-9x16}\caption{foo}\end{figure}
\section{foo}\subsection{foo}\lipsum[1]
\section{foo}\subsection{foo}\lipsum[1]
\end{document}

答案3

\pagestyle{empty}您需要在包含圖形的頁面之前的頁面被運出之後發出指令。

  • shipout/after在最近的 LaTeX 版本中,您可以在 LaTeX 發布某個頁面後立即使用鉤子來執行程式碼。 (根據\changes- 條目ltshipout.dtx該掛鉤於 2021 年 1 月 8 日添加。

  • 您可以使用該套件茲參考用於儲存和檢索 LaTeX 放置相關圖形的頁面的所謂「絕對頁碼」的值。

  • 此外,您還可以定義一個宏\CodeAfterShipoutOfAbsolutePage,在其中指定絕對頁碼和一些程式碼,以便shipout/after僅在絕對頁碼具有指定值的頁面傳送後將指令附加到鉤子以執行程式碼。

  • 在下面的範例中,絕對頁碼可以透過 TeX 進行計算來指定,這可能涉及存取 zref 標籤。因此,在下面的範例中,\CodeAfterShipoutOfAbsolutePage不僅採用兩個參數,而是採用三個參數,其中一個表示以逗號分隔的 zlabel 列表,必須定義該列表才能計算出絕對頁碼的規格。如果未定義這些 zlabel 之一(在任何情況下都是第一次編譯中的情況),則程式碼也不會被執行。

    !!因此,至少需要兩次編譯才能使所有內容匹配。 !!

所以語法\CodeAfterShipoutOfAbsolutePage是:

\CodeAfterShipoutOfAbsolutePage
  {<comma-list of zref-labels that must exist for the code to be carried out>%
    % Here you specify both those zref-labels that are needed for the
    % <expression for computing the absolute page number of the page after 
    % whose shipping-out code shall be carried out> to work out and probably
    % also those zref-labels that are needed for the <code to carry out after
    % the page has been shipped out> to work out.
  }%
  {<expression for computing the absolute page number of the page after 
    whose shipping-out code shall be carried out>}%
  {<code to carry out after the page has been shipped out>%
    % Be aware that you cannot use this for adding visible material
    % or glue to a page. You can use this only for doing abstract actions
    % like calculations or directives like `\thispagestyle{...}`.
  }%

這是一個最小的工作範例。
在範例中shipout/after使用了鉤子。
根據\changes- 條目ltshipout.dtx
該鉤子是在2021 年 1 月 8 日添加的。
這是因為將程式碼分配給不存在的鉤子不會觸發警告或錯誤訊息。此範例適用於 TeX Live 2022。背頁如果在 Overleaf 的選單中選擇 TeX Live 2022。

\NeedsTeXFormat{LaTeX2e}[2021/01/08]
% (According to \changes-entry in ltshipout.dtx the hook
%  shipout/after  was added in January 8, 2021.)
\makeatletter
\RequirePackage[abspage]{zref}
\ExplSyntaxOn
%...............................................................................
% Save the  value of abspage-counter to a zref-label:
%...............................................................................
\cs_new_protected:Npn \saveabspage #1 {\zref@labelbyprops{#1}{abspage}}
%...............................................................................
% Obtain the saved abspage-counter-value from zref-label if possible, otherwise
% deliver -1:
%...............................................................................
\cs_new_protected:Npn \getabspage #1 {\zref@extractdefault{#1}{abspage}{-1}}
%...............................................................................
% Map over comma-list #1 denoting zref-labels and execute code #2 in case all of
% them are defined, otherwise execute code #3; this is for doing calculations 
% with zref-labels which can only be done in case all of them are defined:
%...............................................................................
\cs_new:Npn \CheckWhetherAllZlabelsDefined #1 
  {
    \exp:w
      \clist_map_function:nN {#1} \mystuff_checkzlabel:nwnn
      \exp_after:wN\exp_end:\use_i:nn
  }
\cs_new:Npn \mystuff_checkzlabel:nwnn #1#2 \exp_after:wN\exp_end:\use_i:nn #3#4
  {
    \int_compare:nNnTF {\getabspage{#1}}={-1}
      {#2 \exp_after:wN\exp_end:\use_i:nn {#4}}
      {#2 \exp_after:wN\exp_end:\use_i:nn {#3}}{#4}%
  }
%...............................................................................
% Map over comma-list denoting zref-labels and generate warning for each 
% undefined zref-label:
%...............................................................................
\cs_new_protected:Npn \WarnForUndefinedZlabels #1
  {
    \clist_map_function:nN {#1}\zref@refused
  }
%...............................................................................
% Provide code to execute on background-picture-environment of page whose
% absolute page number is to be specified:
%...............................................................................
\cs_new_protected:Npn \CodeAfterShipoutOfAbsolutePage#1#2#3{ 
  % #1 = comma-list of zref-labels that must exist for the code (#3) to be 
  %      carried out.
  % #2 = expression for computing the absolute page number of the page 
  %      after whose shipout the code #3 shall be carried out:
  % #3 = code to carry out after shipping out the specified page
  \AddToHook{shipout/after}{
    \WarnForUndefinedZlabels{#1}
    \int_compare:nNnT {\CheckWhetherAllZlabelsDefined{#1}{#2}{-1}}
                      =
                      {\value{abspage}}
                      {#3}
  }
}
\ExplSyntaxOff
\makeatother



\documentclass{article}
\usepackage{lipsum}
\pagestyle{headings}

\CodeAfterShipoutOfAbsolutePage{Some ABS label}%
                               {\getabspage{Some ABS label}-1}%
                               {\thispagestyle{empty}}%

\begin{document}
\section{Some headings}
\subsection{Some more headings}
\lipsum{1-2}
\begin{figure}
\noindent\rule{\textwidth}{.6\textheight}
\caption{Some figure}\saveabspage{Some ABS label}
\end{figure}
\lipsum{3-18}
\end{document}

在此輸入影像描述

(缺點是您不能使用它來修改第一頁,因為在該頁面之前不會有可以完成發貨操作的頁面。)

相關內容