将信息放在第一页底部时出现问题

将信息放在第一页底部时出现问题

我正在开发模板,我想拥有类似这样的内容:

我想做的事情的例子

我正在处理双列文档,并试图将其复制\fancyfoot[L]{}(仅限于第一页),但边距不足以容纳信息,而且我无法实现自动调整的功能。

我将留下一个文档类和 main.tex 的示例

文档类示例代码

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{example}[2024/03/28 Rho LaTeX class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}}
\ProcessOptions\relax
\LoadClass[twocolumn]{extarticle}
\AtEndOfClass{\RequirePackage{microtype}}

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

\usepackage[utf8]{inputenc}
\usepackage{lipsum} 
\usepackage{stix2}
\usepackage{fancyhdr}
\usepackage{xifthen}
\usepackage{etoolbox}
\usepackage{algorithm}
\usepackage{adjustbox}
\usepackage{iflang}
\usepackage{ragged2e}
\usepackage{url}

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

\usepackage[left=1.25cm, right=1.25cm, top=2cm, bottom=2cm, headsep=0.75cm]{geometry}

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

\newcommand\correspondingauthor[2][]{
  \gdef\@corres{\textsuperscript{#1}\fontsize{6.5}{9}\selectfont#2}
}
\newcommand{\footerfont}{\normalfont\fontsize{7}{9}\selectfont}
\newcommand{\institution}[1]{\def\@institution{#1}}
\newcommand{\etal}[1]{\def\@etal{#1}}
\newcommand{\course}[1]{\def\@course{#1}}
\newcommand{\doi}[1]{\def\@doi{#1}}
\newcommand{\footitle}[1]{\def\@footitle{#1}}
\newcommand{\footinfo}[1]{\def\@footinfo{#1}}

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

\pagestyle{fancy}

\fancypagestyle{firststyle}{
    \fancyhead[R]{}
    \fancyhead[L]{}
    \fancyfoot[L]{}
    \fancyfoot[R]{
        \vspace{-5pt}
        \begin{minipage}{\textwidth}
            \rule{3cm}{0.5pt}
            \footnotesize
            \vskip1.5pt
            \@corres\par
            \@doi\par
            \@footinfo\par
        \end{minipage}
    }
        \vskip-25pt
}

% Header
\fancyhead[C]{}
\fancyhead[RE]{\sffamily\footnotesize{\itshape\@title}\hspace{10pt}{\bfseries\thepage}}
\fancyhead[LO]{\sffamily\footnotesize{\bfseries\thepage}\hspace{10pt}{\itshape\@title}}
\fancyhead[LE]{}
\fancyhead[RO]{}

% Footer
\lfoot{}%
\cfoot{}%
\rfoot{}%

\fancyfoot[RO]{\sffamily\footnotesize\@institution\hspace{10pt}{\bfseries\@date}\hspace{10pt}\@footitle}
\fancyfoot[LO]{\sffamily\footnotesize\@etal}
\fancyfoot[RE]{\sffamily\footnotesize\@etal}
\fancyfoot[LE]{\sffamily\footnotesize\@course}

\renewcommand{\headrulewidth}{0pt} % No header rule
\renewcommand{\footrulewidth}{0pt} % No footer rule

main.tex 的示例

\documentclass[9pt,a4paper,twoside]{example}

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

\title{Example}
\author{Author 1}
\date{April 2024}

%---------------------------------------------
% Using the commands
%---------------------------------------------

\correspondingauthor[$\ast$]{Corresponding author at: This is an example of how you can customize this part of the article. Please, provide the corresponding author information and publisher here. \textit{E-mail address:} [email protected].}

\footinfo{Available Online \\ Available date. XXXX-XX/ \copyright\ All rights reserved.}

\doi{\url{https://www.doi.org/exampledoi/XXXXXXXXXX}}

\institution{Example}

\etal{Author last name et al.}

\footitle{Example}

\course{Example}

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

\begin{document}

\maketitle
\thispagestyle{firststyle}

\lipsum[2-10]
\\

\textbf{On the first page the footer is different from the rest of the pages. I would like to implement something that always shows below but automatically adjusts to the lines that are placed in case I have more information.}\\

\textbf{As I placed it now, you can see that the bottom margin is smaller than the top one and I would like them to be the same.}

\newpage

\textbf{Here the footer change. But if you tried to make the footer larger to fit the information for the first page, it no longer looks good because it looks unnaturally large on the other pages.}

\lipsum[2-10]

\end{document}

这就是我得到的结果。如您所见,底部比顶部小,并且由于我编写代码的方式,我必须手动调整它。

我的意思是我还没有想出一个可以把信息放在第一页的底部并且自行调整到所需高度的解决方案。

在此处输入图片描述

有人能给我一个解决方案吗,让信息块始终放在第一页的底部,或者如何获取第一张图片的结果。非常感谢 :)

答案1

您需要更改\textheight第一页的。要自动调整,如果页脚的高度可能会改变,请使用框

\newbox\firstfootbox
\sbox{\firstfootbox}{%
  \parbox[t]{\textwidth}{%
    \rule{3cm}{0.5pt}
    \footnotesize
    \vskip1.5pt
    \@corres\par
    \@doi\par
    \@footinfo\par
  }%
}

页脚的额外高度与框深度相对应(使用[t]\parbox顶线与基线对齐)。从\textheight

\addtolength{\textheight}{-\dp\firstfootbox}

并在页脚中调用框内容

\fancyfoot[L]{\usebox{\firstfootbox}}

最后,你需要恢复下一页的几何形状。你可以用钩子来做

\AddToHookNext{shipout/after}{
  \restoregeometry
  \global\textheight=\textheight
}

由于长度分配是本地的,因此\global\textheight=\textheight是需要的(它是唯一被改变的长度\restoregeometry)。

我建议创建一个包含所有几何设置的命令

\NewDocumentCommand{\firstpagegeometry}{}{%
  \sbox{\firstfootbox}{%
    \parbox[t]{\textwidth}{%
      \rule{3cm}{0.5pt}
      \footnotesize
      \vskip1.5pt
      \@corres\par
      \@doi\par
      \@footinfo\par
    }%
  }
  \addtolength{\textheight}{-\dp\firstfootbox}
  \AddToHookNext{shipout/after}{
    \restoregeometry
    \global\textheight=\textheight
  }
}

并在之前调用它\maketitle

完整示例:

\begin{filecontents*}{example.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{example}[2024/03/28 Rho LaTeX class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{extarticle}}
\ProcessOptions\relax
\LoadClass[twocolumn]{extarticle}
\AtEndOfClass{\RequirePackage{microtype}}

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

\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{stix2}
\usepackage{fancyhdr}
\usepackage{xifthen}
\usepackage{etoolbox}
\usepackage{algorithm}
\usepackage{adjustbox}
\usepackage{iflang}
\usepackage{ragged2e}
\usepackage{url}

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

\usepackage[left=1.25cm, right=1.25cm, top=2cm, bottom=2cm, headsep=0.75cm]{geometry}

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

\newcommand\correspondingauthor[2][]{
  \gdef\@corres{\textsuperscript{#1}\fontsize{6.5}{9}\selectfont#2}
}
\newcommand{\footerfont}{\normalfont\fontsize{7}{9}\selectfont}
\newcommand{\institution}[1]{\def\@institution{#1}}
\newcommand{\etal}[1]{\def\@etal{#1}}
\newcommand{\course}[1]{\def\@course{#1}}
\newcommand{\doi}[1]{\def\@doi{#1}}
\newcommand{\footitle}[1]{\def\@footitle{#1}}
\newcommand{\footinfo}[1]{\def\@footinfo{#1}}

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

\pagestyle{fancy}

\newbox\firstfootbox

\NewDocumentCommand{\firstpagegeometry}{}{%
  \sbox{\firstfootbox}{%
    \parbox[t]{\textwidth}{%
      \rule{3cm}{0.5pt}
      \footnotesize
      \vskip1.5pt
      \@corres\par
      \@doi\par
      \@footinfo\par
    }%
  }
  \addtolength{\textheight}{-\dp\firstfootbox}
  \AddToHookNext{shipout/after}{
    \restoregeometry
    \global\textheight=\textheight
  }
}

\fancypagestyle{firststyle}{
  \fancyhead[R]{}
  \fancyhead[L]{}
  \fancyfoot[R]{}
  \fancyfoot[L]{\usebox{\firstfootbox}}
}

  % Header
\fancyhead[C]{}
\fancyhead[RE]{\sffamily\footnotesize{\itshape\@title}\hspace{10pt}{\bfseries\thepage}}
\fancyhead[LO]{\sffamily\footnotesize{\bfseries\thepage}\hspace{10pt}{\itshape\@title}}
\fancyhead[LE]{}
\fancyhead[RO]{}

% Footer
\lfoot{}%
\cfoot{}%
\rfoot{}%

\fancyfoot[RO]{\sffamily\footnotesize\@institution\hspace{10pt}{\bfseries\@date}\hspace{10pt}\@footitle}
\fancyfoot[LO]{\sffamily\footnotesize\@etal}
\fancyfoot[RE]{\sffamily\footnotesize\@etal}
\fancyfoot[LE]{\sffamily\footnotesize\@course}

\renewcommand{\headrulewidth}{0pt} % No header rule
\renewcommand{\footrulewidth}{0pt} % No footer rule
\end{filecontents*}

\documentclass[9pt,a4paper,twoside]{example}

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

\title{Example}
\author{Author 1}
\date{April 2024}

% ---------------------------------------------
% Using the commands
% ---------------------------------------------

\correspondingauthor[$\ast$]{Corresponding author at: This is an example of how
  you can customize this part of the article. Please, provide the corresponding
  author information and publisher here. \textit{E-mail address:}
  [email protected].}

\footinfo{Available Online \\ Available date. XXXX-XX/ \copyright\ All
  rights reserved.}

\doi{\url{https://www.doi.org/exampledoi/XXXXXXXXXX}}

\institution{Example}

\etal{Author last name et al.}

\footitle{Example}

\course{Example}

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

\begin{document}

\firstpagegeometry

\maketitle
\thispagestyle{firststyle}

\lipsum[2-10]
\\

\textbf{On the first page the footer is different from the rest of the pages.
  I would like to implement something that always shows below but automatically
  adjusts to the lines that are placed in case I have more information.}\\

\textbf{As I placed it now, you can see that the bottom margin is smaller than
  the top one and I would like them to be the same.}

\newpage

\textbf{Here the footer change. But if you tried to make the footer larger to
  fit the information for the first page, it no longer looks good because it
  looks unnaturally large on the other pages.}

\lipsum[2-10]

\end{document}

第 1 页

第2页

相关内容