我该如何实现随着页数变化的自定义页脚?

发布于 2022-07-24 16:09:10

0E5CDEB23AAF14CE0BB0A8B4444505DA.jpg
就像这张图一样,我想实现一个随着page变化的页脚,也就是每一个page的页脚都有不同的文本,这个文本并不需要随机,而是可以自行一个一个定义
另外,这个页脚最好是一个parbox,以使得我能够随意在其中更改版式

查看更多

关注者
1
被浏览
927
3 个回答
芒果不盲
芒果不盲 2022-07-24
学好TiKZ和tcolorbox!

提供一种思路

使用 magicwatermark 宏包, 并通过外部文件来添加页脚信息.

%pagefoot.txt
{faraday.jpg}{爱情既是友谊的代名词,又是我们为共同的事业而奋斗的可靠保证,爱情是人生的良伴,你和心爱的女子同床共眠是因为共同的理想把两颗心紧紧系在一起。\par \hfill ------ 法拉第}
{newton.jpg}{苹果砸了我的头,我成了物理学家。\par \hfill ------ 牛顿}
%main.tex
\documentclass{ctexart}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\graphicspath{{figure/}}
\usepackage{fontawesome5}
\usepackage{magicwatermark}
\usepackage{zhlipsum}

\ExplSyntaxOn
\clist_clear_new:N \l_pagefoot_image_clist 
\clist_clear_new:N \l_pagefoot_text_clist

\cs_new:Npn \pagefoot_add_content:nn #1#2 {
  \clist_gput_right:Nn \l_pagefoot_image_clist { #1 }
  \clist_gput_right:Nn \l_pagefoot_text_clist { #2 }
}
\ior_open:Nn \g_tmpa_ior { pagefoot.txt }
\ior_map_inline:Nn \g_tmpa_ior 
{
  \pagefoot_add_content:nn #1
}
\ior_close:N \g_tmpa_ior

\PageSetup*{
  \begin{tikzpicture}[remember~picture,overlay]
    \fill[red!25] ([xshift=1cm]current~page.south~west) rectangle ([yshift=3cm]current~page.south~east);
    \fill[red!50] ([xshift=1cm,yshift=1cm]current~page.south~west) --++(0,2) -- ++(2,0)--cycle;
    \fill[red!50] ([xshift=-2cm]current~page.south~east) -- ++(2,0) -- ++(0,2)--cycle;
    \node[anchor=west] at ([shift={(1.2,1.5)}]current~page.south~west){\includegraphics[width=1.8cm,height=2.4cm]{\clist_item:Nn \l_pagefoot_image_clist{ \thepage }}};
    \node[font=\bfseries,] at ([shift={(-0.5,0.5)}]current~page.south~east){\thepage};
    \node[anchor=north~west] at ([shift={(3.5,2.8)}]current~page.south~west)
    {
      \begin{minipage}{\dimeval{\paperwidth-4.5cm}}
        \textcolor{red!50}{\faBook}\hskip .5em\tikz[baseline]{\node[anchor=base,rounded~corners,fill=red!50,inner~sep=.3mm]{物理学史};}\hskip 1em  \clist_item:Nn \l_pagefoot_text_clist { \thepage }
      \end{minipage}
    };
  \end{tikzpicture}
}
\ExplSyntaxOff
\Watermark
\pagestyle{empty}
\begin{document}
\zhlipsum[1]
\newpage
\zhlipsum[2]
\end{document}

效果如下:
第一页
1.png
第二页
2.png

附件:
pagefoot.zip

啸行
啸行 2022-07-24
这家伙很懒,什么也没写!
烟云幻梦
烟云幻梦 2022-11-07
数学系咸鱼一枚!

这里是另一种实现

\documentclass[12pt,oneside]{book}
\usepackage[dvipsnames,svgnames,x11names,table]{xcolor}
\definecolor{nuanbai}{HTML}{F5F5F5}
\pagecolor{nuanbai!20}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\usepackage[left=1.5cm,right=1.5cm,top=2cm,bottom=3.3cm,head=18.85004pt]{geometry}
\usepackage[fontset=ubuntu]{ctex}
\usepackage[automark]{scrlayer-scrpage}%页面设置宏包,隶属于koma-script文档类
\usepackage{tikz}
\usetikzlibrary{calc,shadows}
\usepackage[most]{tcolorbox}
\usepackage{fontawesome5}

\makeatletter
\newcommand*\footimage[1]{\def\@footimage{#1}}
\newcommand*\foottext[1]{\def\@foottext{#1}}
\ihead{}
\ohead{}
\chead{}
%%页脚
\ifoot{}
\cfoot{}
\ofoot{\footstyle}
\newlength\tipslen
\setlength\tipslen{13mm}
\setlength\footheight{50pt}
\newcommand{\footstyle}{%
  \begin{tikzpicture}[remember picture,overlay]
    \fill[red!25] 
    ([xshift=1cm]current page.south west) rectangle ([yshift=3cm]current page.south east);
    \fill[red!50] ([xshift=1cm,yshift=1cm]current page.south west) --++(0,2) -- ++(2,0)--cycle;
    \fill[red!50] ([xshift=-2cm]current page.south east) -- ++(2,0) -- ++(0,2)--cycle;
    \node[anchor=west] at ([shift={(1.2,1.5)}]current page.south west){\includegraphics[width=1.8cm,height=2.4cm]{\@footimage}};
    \node[font=\bfseries,text=white,rectangle,rounded corners,fill=red!50] at ([shift={(-0.5,0.5)}]current page.south east){\thepage};
    \node[anchor=north west] at ([shift={(3.5,2.8)}]current page.south west)
    {
      \begin{minipage}{\dimeval{\paperwidth-4.5cm}}
        \textcolor{red!50}{\faBook}\hspace{1em}\tikz[baseline]{\node[anchor=base,rounded corners=2.5pt,text=black,fill=red!50,inner sep=.3mm]{物理学史};}\hspace{1em}\@foottext
      \end{minipage}
    };
  \end{tikzpicture}
}
\makeatother

\begin{document}
\footimage{figures/newton.jpg}
\foottext{爱情既是友谊的代名词,又是我们为共同的事业而奋斗的可靠保证,爱情是人生的良伴,你和心爱的女子同床共眠是因为共同的理想把两颗心紧紧系在一起。\hfill ------ 法拉第}
\section{算法整理}
\newpage
\end{document}






撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览