原来的

原来的

我目前尝试通过以下方式设置页码:

\fancyhf{}%
\fancyfoot[RO]{\begin{picture}(0,0)\put(1.5cm,-0.9cm){\includegraphics[width = 1cm]{page-number}}}\put(1.5cm,-0.9cm){\makebox[0pt]{\pagenumberfont\Large\thepage}}\end{picture}}%
\fancyfoot[LE]{\begin{picture}(0,0)\put(-1.5cm,-0.9cm){\includegraphics[width = 1cm]{page-number}}}\put(-1.5cm,-0.9cm){\makebox[0pt]{\pagenumberfont\Large\thepage}}\end{picture}}%

但我收到了错误:

! You can't use `\raise' in vertical mode.
\put  ...itsset \@tempdimc {#2}\unitlength \raise 
                                                  \@tempdimc \hb@xt@ \z@ {\@...

l.41 ...makebox[0pt]{\pagenumberfont\Large\thepage}}
                                                  \end{picture}}%
? 

我该如何修复我的代码或使用另一种方式让背景位于页码的正后方,并且与页码以相同的方式居中?

最小示例:

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[paperwidth=6.125in,paperheight=9.25in,inner=2.0625cm,outer=3.2985cm,top=2.325cm,bottom=3.6846000000000005cm]{geometry}%
%
\usepackage{graphicx}%
\usepackage{fontspec}%
\usepackage{tocloft}%
\usepackage{changepage}%
\usepackage{ebgaramond}%
\newfontfamily{\pagenumberfont}{Pacifico}%
\setmainfont{EB Garamond}%

\usepackage[pdfusetitle,bookmarks=true,colorlinks=true,linkcolor=black,urlcolor=black,citecolor=black]{hyperref}%
\usepackage{fancyhdr}%
\usepackage{etoolbox}%
\pagestyle{fancy}%
\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\ifodd\value{page}\includegraphics[width =\paperwidth, height =\paperheight]{../right-\thechapter}\else\includegraphics[width =\paperwidth, height =\paperheight]{../raw_images/PoeticHypnosisI/left-\thechapter}\fi}}%%
%
\begin{document}%
\normalsize%
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}%
\fancyhf{}%
\fancyfoot[RO]{\begin{picture}(0,0)\put(1.5cm,-0.9cm){\includegraphics[width = 1cm]{page-number}}}\put(1.5cm,-0.9cm){\makebox[0pt]{\pagenumberfont\Large\thepage}}\end{picture}}%
\fancyfoot[LE]{\begin{picture}(0,0)\put(-1.5cm,-0.9cm){\includegraphics[width = 1cm]{page-number}}}\put(-1.5cm,-0.9cm){\makebox[0pt]{\pagenumberfont\Large\thepage}}\end{picture}}%
\renewcommand{\headrulewidth}{0.0pt}%

\newpage%
\begingroup%
\begin{adjustwidth}{0.75cm}{0.4cm}%
\AddToHookNext{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{../tableofcontents}}}%
\lineskiplimit=-\maxdimen%
\tableofcontents%
\end{adjustwidth}%
\thispagestyle{fancy}%
\endgroup%
\setmainfont{EB Garamond}%
\chapter*{Introduction}%
\addcontentsline{toc}{chapter}{Introduction}%
\vfill%
\paragraph{}%

%
Super Text
\paragraph{}%

%
Super Text

%
\end{document}

答案1

您的示例无法按原样使用。我已将您的图片替换为标准示例图片。您还加载了冲突的字体和字体包。由于我没有您用于页码的字体,因此我已注释掉这些fontspec内容并使用了fontenc/ inputenc/ lmodern/textcomp内容。如果您想使用fontspec该字体,请删除不兼容的包并取消注释相关行。

原来的

我知道实现所需效果的最简单方法是将内容放入框中,然后在页脚设置中使用它们。在这里,我使用了“棺材”,因为xcoffins它们易于连接和对齐。这样可以直接将页码放在图像顶部,无需手动使用picture和摆弄水平/垂直调整。

带有样本图像的输出

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[paperwidth=6.125in,paperheight=9.25in,inner=2.0625cm,outer=3.2985cm,top=2.325cm,bottom=3.6846000000000005cm]{geometry}%
%
\usepackage[]{graphicx}%
\usepackage{xcoffins}
% \usepackage{fontspec}% if you want to use this, remove fontenc, inputenc, lmodern, textcomp
\usepackage{tocloft}%
\usepackage{changepage}%
\usepackage{ebgaramond}%
% \newfontfamily{\pagenumberfont}{Pacifico}%
% \setmainfont{EB Garamond}%
\let\pagenumberfont\sffamily
\usepackage{fancyhdr}%
\usepackage{etoolbox}%
\usepackage[pdfusetitle,bookmarks=true,colorlinks=true,linkcolor=black,urlcolor=black,citecolor=black]{hyperref}% load last unless specific package requires later loading, consider bookmarks
\pagestyle{fancy}%
\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\ifodd\value{page}\includegraphics[width =\paperwidth, height =\paperheight]{example-image-a}\else\includegraphics[width =\paperwidth, height =\paperheight]{example-image-b}\fi}}

\NewCoffin \PagenumberCoffin
\NewCoffin \PagenumberbackCoffin

\NewDocumentCommand \MakePagenumberCoffin { O {r} }
{%
  \SetHorizontalCoffin \PagenumberCoffin {\pagenumberfont\Large\thepage}%
  \SetHorizontalCoffin \PagenumberbackCoffin {\includegraphics[width=1cm]{example-image}}%
  \JoinCoffins \PagenumberbackCoffin [hc,vc] \PagenumberCoffin [hc,vc]%
  \TypesetCoffin \PagenumberbackCoffin [B,#1]%
}

\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}%
\fancyhf{}%
\fancyfoot[RO]{\MakePagenumberCoffin}
\fancyfoot[LE]{\MakePagenumberCoffin[l]}%
\renewcommand{\headrulewidth}{0.0pt}%
\begin{document}
\begingroup
  \begin{adjustwidth}{0.75cm}{0.4cm}%
    \AddToHookNext{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{example-image-c}}}%
    \lineskiplimit=-\maxdimen
    \tableofcontents
  \end{adjustwidth}%
  \thispagestyle{fancy}%
\endgroup
% \setmainfont{EB Garamond}%
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}%
\vfill

\paragraph{This command is not the way to make paragraphs}%

Super Text
\paragraph{A subsubsubheading} rather than a paragraph.

This is a new paragraph.

Super Text is in another new paragraph.

\end{document}

编辑 1(非实验性)

如果您不想使用实验版本xcoffins,这里有一个非实验版本。

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[paperwidth=6.125in,paperheight=9.25in,inner=2.0625cm,outer=3.2985cm,top=2.325cm,bottom=3.6846000000000005cm]{geometry}%
%
\usepackage[]{graphicx}%
% \usepackage{fontspec}% if you want to use this, remove fontenc, inputenc, lmodern, textcomp
\usepackage{tocloft}%
\usepackage{changepage}%
\usepackage{ebgaramond}%
% \newfontfamily{\pagenumberfont}{Pacifico}%
% \setmainfont{EB Garamond}%
\let\pagenumberfont\sffamily
\usepackage{fancyhdr}%
\usepackage{etoolbox}%
\usepackage[pdfusetitle,bookmarks=true,colorlinks=true,linkcolor=black,urlcolor=black,citecolor=black]{hyperref}% load last unless specific package requires later loading, consider bookmarks
\pagestyle{fancy}%
\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\ifodd\value{page}\includegraphics[width =\paperwidth, height =\paperheight]{example-image-a}\else\includegraphics[width =\paperwidth, height =\paperheight]{example-image-b}\fi}}

\ExplSyntaxOn
\coffin_new:N \l_christian_pageno_coffin
\coffin_new:N \g_christian_pagenoback_coffin
\coffin_new:N \l_christian_pagenocombo_coffin

\AtBeginDocument
{
  \hcoffin_gset:Nn \g_christian_pagenoback_coffin { \includegraphics[width=1cm]{example-image} }
}

\NewDocumentCommand \MakePagenumberCoffin { O {r} }
{%
  \group_begin:
    \hcoffin_set:Nn \l_christian_pageno_coffin  {\pagenumberfont\Large\thepage}
    \coffin_set_eq:NN \l_christian_pagenocombo_coffin \g_christian_pagenoback_coffin
    \coffin_join:NnnNnnnn \l_christian_pagenocombo_coffin { hc } { vc } \l_christian_pageno_coffin { hc } { vc } { 0pt } { 0pt }
    \coffin_typeset:Nnnnn \l_christian_pagenocombo_coffin { B } { #1 } { 0pt } { 0pt }
  \group_end:
}
\ExplSyntaxOff
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}%
\fancyhf{}%
\fancyfoot[RO]{\MakePagenumberCoffin}
\fancyfoot[LE]{\MakePagenumberCoffin[l]}%
\renewcommand{\headrulewidth}{0.0pt}%
\begin{document}
\begingroup
  \begin{adjustwidth}{0.75cm}{0.4cm}%
    \AddToHookNext{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{example-image-c}}}%
    \lineskiplimit=-\maxdimen
    \tableofcontents
  \end{adjustwidth}%
  \thispagestyle{fancy}%
\endgroup
% \setmainfont{EB Garamond}%
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}%
\vfill

\paragraph{This command is not the way to make paragraphs}%

Super Text
\paragraph{A subsubsubheading} rather than a paragraph.

This is a new paragraph.

Super Text is in another new paragraph.

\end{document}

这样做的好处是只需将图像排版到背景棺材中一次。之后每次都可以重复使用结果。 中的高级命令xcoffins不允许您只将一个棺材复制到另一个棺材,但编程层中的命令功能更全面。

编辑 2 (带移位)

我们可以通过添加一个基本的键值接口来修改它,以移动页码。提供了三个键

  • side应该是lr(默认值r:)
  • xshift应该是一个维度(默认值1.5cm:)
  • yshift应该是一个维度(默认值-0.9cm:)

然后以下内容将左侧页码向左向下移动,右侧页码向右向下移动。

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[paperwidth=6.125in,paperheight=9.25in,inner=2.0625cm,outer=3.2985cm,top=2.325cm,bottom=3.6846000000000005cm]{geometry}%
%
\usepackage[]{graphicx}%
% \usepackage{fontspec}% if you want to use this, remove fontenc, inputenc, lmodern, textcomp
\usepackage{tocloft}%
\usepackage{changepage}%
\usepackage{ebgaramond}%
% \newfontfamily{\pagenumberfont}{Pacifico}%
% \setmainfont{EB Garamond}%
\let\pagenumberfont\sffamily
\usepackage{fancyhdr}%
\usepackage{etoolbox}%
\usepackage[pdfusetitle,bookmarks=true,colorlinks=true,linkcolor=black,urlcolor=black,citecolor=black]{hyperref}% load last unless specific package requires later loading, consider bookmarks
\pagestyle{fancy}%
\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\ifodd\value{page}\includegraphics[width =\paperwidth, height =\paperheight]{example-image-a}\else\includegraphics[width =\paperwidth, height =\paperheight]{example-image-b}\fi}}

\ExplSyntaxOn
\coffin_new:N \l_christian_pageno_coffin
\coffin_new:N \g_christian_pagenoback_coffin
\coffin_new:N \l_christian_pagenocombo_coffin

\AtBeginDocument
{
  \hcoffin_gset:Nn \g_christian_pagenoback_coffin { \includegraphics[width=1cm]{example-image} }
}

\keys_define:nn { christian / page~no }
{
  side .tl_set:N = \l_christian_side_tl,
  side .initial:n = r,
  xshift .dim_set:N = \l_christian_xshift_dim,
  xshift .initial:n = 1.5cm,
  yshift .dim_set:N = \l_christian_yshift_dim,
  yshift .initial:n = -0.9cm,
}
\cs_generate_variant:Nn \coffin_typeset:Nnnnn { NnVVV }
\NewDocumentCommand \MakePagenumberCoffin { O {side=r,xshift=1.5cm} }
{%
  \group_begin:
    \keys_set:nn { christian / page~no } { #1 }
    \hcoffin_set:Nn \l_christian_pageno_coffin  {\pagenumberfont\Large\thepage}
    \coffin_set_eq:NN \l_christian_pagenocombo_coffin \g_christian_pagenoback_coffin
    \coffin_join:NnnNnnnn \l_christian_pagenocombo_coffin { hc } { vc } \l_christian_pageno_coffin { hc } { vc } { 0pt } { 0pt }
    \coffin_typeset:NnVVV \l_christian_pagenocombo_coffin { B } \l_christian_side_tl \l_christian_xshift_dim \l_christian_yshift_dim
  \group_end:
}
\ExplSyntaxOff
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}%
\fancyhf{}%
\fancyfoot[RO]{\MakePagenumberCoffin}
\fancyfoot[LE]{\MakePagenumberCoffin[side=l,xshift=-1.5cm]}%
\renewcommand{\headrulewidth}{0.0pt}%
\begin{document}
\begingroup
  \begin{adjustwidth}{0.75cm}{0.4cm}%
    \AddToHookNext{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{example-image-c}}}%
    \lineskiplimit=-\maxdimen
    \tableofcontents
  \end{adjustwidth}%
  \thispagestyle{fancy}%
\endgroup
% \setmainfont{EB Garamond}%
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}%
\vfill

\paragraph{This command is not the way to make paragraphs}%

Super Text
\paragraph{A subsubsubheading} rather than a paragraph.

This is a new paragraph.

Super Text is in another new paragraph.

\end{document}

移位页码

编辑3

如果您只是想要页码偏移,那么所有关于移动东西的摆弄都是不必要的。相反,您可以简单地重新定义,\headwidthfancyhdr文档中所述。这很简单。所以您真正需要的只是如何在其背景上框出页码。

fancyhdr 文档中覆盖的标准偏移情况与棺材相结合,以“装箱”(和一点点)页码组合

请注意,这些行只是为了演示目的。实际使用时show frame请删除注释行。geometry

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage[show frame,paperwidth=6.125in,paperheight=9.25in,inner=2.0625cm,outer=3.2985cm,top=2.325cm,bottom=3.6846000000000005cm]{geometry}% remove "show frame" when happy with layout
%
\usepackage[]{graphicx}%
\usepackage{tocloft}%
\usepackage{ebgaramond}%
\usepackage{changepage}
\let\pagenumberfont\sffamily
\usepackage{fancyhdr}%
\usepackage{etoolbox}%
\usepackage[pdfusetitle,bookmarks=true,colorlinks=true,linkcolor=black,urlcolor=black,citecolor=black]{hyperref}% load last unless specific package requires later loading, consider bookmarks
\pagestyle{fancy}%
\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\ifodd\value{page}\includegraphics[width =\paperwidth, height =\paperheight]{example-image-a}\else\includegraphics[width =\paperwidth, height =\paperheight]{example-image-b}\fi}}

\ExplSyntaxOn
\coffin_new:N \l_christian_pageno_coffin
\coffin_new:N \g_christian_pagenoback_coffin
\coffin_new:N \l_christian_pagenocombo_coffin

\AtBeginDocument
{
  \hcoffin_gset:Nn \g_christian_pagenoback_coffin { \includegraphics[width=1cm]{example-image} }
}

\keys_define:nn { christian / page~no }
{
  side .tl_set:N = \l_christian_side_tl,
  side .initial:n = r,
  yshift .dim_set:N = \l_christian_yshift_dim,
  yshift .initial:n = -0.9cm,
}
\cs_generate_variant:Nn \coffin_typeset:Nnnnn { NnVnV }
\NewDocumentCommand \MakePagenumberCoffin { O {side=r,xshift=1.5cm} }
{% if textblock has constant width, we could do this more efficiently by setting some of this only once for each of the two even/odd pages, but we don't want to assume that
  \group_begin:
    \keys_set:nn { christian / page~no } { #1 }
    \hcoffin_set:Nn \l_christian_pageno_coffin  {\pagenumberfont\Large\thepage}
    \coffin_set_eq:NN \l_christian_pagenocombo_coffin \g_christian_pagenoback_coffin
    \coffin_join:NnnNnnnn \l_christian_pagenocombo_coffin { hc } { vc } \l_christian_pageno_coffin { hc } { vc } { 0pt } { 0pt }
    \coffin_typeset:NnVnV \l_christian_pagenocombo_coffin { B } \l_christian_side_tl { 0pt } \l_christian_yshift_dim
  \group_end:
}
\ExplSyntaxOff
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}%
\fancyhf{}%
\fancyfoot[RO]{\MakePagenumberCoffin[side=r]}
\fancyfoot[LE]{\MakePagenumberCoffin[side=l]}
\addtolength \headwidth {1.5cm}
\renewcommand{\headrulewidth}{0.0pt}%
\begin{document}
\begingroup
  \begin{adjustwidth}{0.75cm}{0.4cm}%
    \tableofcontents
  \end{adjustwidth}%
  \thispagestyle{fancy}%
\endgroup
\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}%
\vfill

\paragraph{This command is not the way to make paragraphs}%

Super Text
\paragraph{A subsubsubheading} rather than a paragraph.

This is a new paragraph.

Super Text is in another new paragraph.

\end{document}

相关内容