您能告诉我将一行文字放在页面底部的另一种解决方案吗?

您能告诉我将一行文字放在页面底部的另一种解决方案吗?

我正在编写一个文档类,其中我想在文本区域的底部、脚注之后放置一行文本,以便其位置始终完全固定。 解决方案如下:

\documentclass{article}
\usepackage{lipsum,graphicx}
\title{A sample title}
\author{John Doe}

\makeatletter
\def\@maketitle{%
\newpage
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
{\large
\lineskip .5em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1em%
{\large \@date}%
\end{center}%
\begin{figure}[!b]
\copyright\ 2022 John Doe \hfill Department of Mathematics
\end{figure}
\par
\vskip 1.5em
}
\makeatother

\begin{document}
\maketitle
Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]
\end{document}

但出于某些原因,我不想使用浮动环境。您能建议我其他解决方案吗(最好不加载额外的包)?

答案1

有可能对页面上的文本进行绝对定位。例如,tikz 提供了执行此操作的方法。


如果正在使用最新的 LaTeX 版本并且可以使用 shipout-hooks,那么您可以将代码添加到 hook 中shipout/foreground

该钩子shipout/foreground指的是一个图片环境,其左上角 (0,0) 位于页面的左上角,单位长度为 1pt。
(要使页面上的事物发生,坐标的 y/second 分量需要为负数。在最近的 LaTeX 版本中,环境不需要picture关注规范化\dimexpr和长度寄存器,因为它是自动完成的。)\unitlength

\documentclass[twoside]{article}

\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%

\usepackage{lipsum}
\title{A sample title}
\author{John Doe}

\makeatletter
\newcommand\foo[1]{#1}
\def\@maketitle{%
\newpage
% If you want this on the titlepage only, use \AddToHookNext instead of \AddToHook
\AddToHook{shipout/foreground}{%
  \put(\dimexpr 1in+\ifodd\thepage\oddsidemargin\else\evensidemargin\fi\relax,
       \foo{\dimexpr-\paperheight+.5\dimexpr\paperheight-(1in+\topmargin+\headheight+\headsep+\textheight+\footskip)+\ht\strutbox\relax\relax})%
  {%
    \hbox to\textwidth{\copyright\ 2022 John Doe \hfill Department of Mathematics}%
  }%
}
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
{\large
\lineskip .5em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1em%
{\large \@date}%
\end{center}%
\par
\vskip 1.5em
}
\makeatother

\begin{document}
\maketitle
Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]

\newpage

Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]

\end{document}

在此处输入图片描述


如果使用的 LaTeX 版本不是最新版本,请考虑加载包埃索一皮克

下面的代码提供了一个示例,其中命令\AddToShipOutPicture其中包的命令埃索一皮克与图片环境相结合,其中命令\put可用于定位文本。

\documentclass[twoside]{article}
\usepackage{lipsum,eso-pic}
\title{A sample title}
\author{John Doe}

\makeatletter
\newcommand\ConvertToUnitlength[1]{%
  \strip@pt\dimexpr#1*65536/\number\dimexpr\unitlength\relax\relax
}%
\def\@maketitle{%
\newpage
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
{\large
\lineskip .5em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1em%
{\large \@date}%
\end{center}%
% If you want this on every page, use \AddToShipoutPicture.
% If you want this on the title-page only, use \AddToShipoutPicture*.
\AddToShipoutPicture{%
  \vbox to \paperheight{%
    \hsize=\paperwidth
    %----------------------------------------------------
    %       Within the \vbox do whatever you like:
    %       e.g., use a picture-environment:
    %----------------------------------------------------
    \setlength{\unitlength}{1cm}%
    \begin{picture}(\ConvertToUnitlength{\paperwidth},
                    \ConvertToUnitlength{\paperheight})(0,0)%
      % Inside this picture 0,0 is the bottom left corner.
      % Unit is cm.
      % If you wish to use length-parameter or \dimexppr, you can use \ConvertToUnitlength.
      % With recent LaTeX \ConvertToUnitlength is not really needed, but
      % you can use it for hiding ( and ) belonging to a \dimexpr
      % from the scanning for a )-delimiter of a \put-command.
      % You can also use eso-pic's \LenToUnit for this purpose.
      % If you need to learn about length-parameters of page-layout, see the documentation of the package "layout".
      \put(\ConvertToUnitlength{\dimexpr 1in+\ifodd\thepage\oddsidemargin\else\evensidemargin\fi\relax},
           \ConvertToUnitlength{.5\dimexpr\paperheight-(1in+\topmargin+\headheight+\headsep+\textheight+\footskip)+\ht\strutbox\relax})%
      {%
        \hbox to\textwidth{\copyright\ 2022 John Doe \hfill Department of Mathematics}%
      }%
    \end{picture}%
    %----------------------------------------------------
  }%
}%
\par
\vskip 1.5em
}
\makeatother

\begin{document}
\maketitle
Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]

\newpage

Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]

\end{document}

在此处输入图片描述

答案2

或者,如果您喜欢粗暴的 hack,并且如果文本只出现在标题页上,并且标题页无论如何都包含脚注,以便绘制将正文与脚注分开的规则,并且您通过 完成标题页\newpage,您可以\footnotetext在之前使用\newpage放置最后一个“脚注”,其中包含您的版权声明。如果使用 hyperref,则需要将内容包装到 -environment 中NoHyper。我不知道这与\raggedbottom/有何互动\flushbottom

\documentclass[twoside]{article}
\usepackage{lipsum,hyperref}
\title{A sample title}
\author{John Doe}

\makeatletter
\def\@maketitle{%
\newpage
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
{\large
\lineskip .5em%
\begin{tabular}[t]{c}%
\@author
\end{tabular}\par}%
\vskip 1em%
{\large \@date}%
\end{center}%
% If you want this on every page, use \AddToShipoutPicture.
% If you want this on the title-page only, use \AddToShipoutPicture*.
\par
\vskip 1.5em
}
\makeatother

\begin{document}
\maketitle
Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]

\begingroup
\makeatletter
\long\def\@makefntext#1{\noindent#1}%
\begin{NoHyper}%
\footnotetext{\par\vspace*{\dimexpr\footskip-2\baselineskip\relax}{\normalsize\copyright\ 2022 John Doe \hfill Department of Mathematics}}%
\end{NoHyper}%
\endgroup
\newpage

Text goes here\footnote{A footnote} and\footnote{Another footnote}
\lipsum[2]

\end{document}

在此处输入图片描述

相关内容