目录:第一页和后续页面采用不同的页面样式

目录:第一页和后续页面采用不同的页面样式

这是我的第一个问题。我通常只阅读答案和评论。它以前有效 =)。

所以,问题是如何对目录的第一页和后续页使用不同的样式。

我用框架编写了不同的样式(framebig用于第一页和framesmall后续页面)。框架是使用tikzbackground包绘制的。我尝试使用\thispagestyle{framebig}命令\tableofcontents,但没有用(我不知道为什么)。

\documentclass[a4paper, 12pt, oneside, hidelinks]{book}
\usepackage[width=17cm, left=3cm, top=1cm, bottom=2.5cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}

\usepackage[scale=1,angle=0,opacity=1,color=black!100]{background}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{positioning,calc}
\usepackage{lastpage}
\usepackage{lmodern}
\usepackage{titlesec}


%%%%%%%%%%%%%%%%%%%%
% My page styles with frame
%%%%%%%%%%%%%%%%%%%%

\newpagestyle{framesmall}{
\newgeometry{width=17cm, left=3cm, top=1cm, bottom=2.5cm}
\backgroundsetup{%
contents={\SMALLFRAME}
 }
}

\newpagestyle{framebig}{
\newgeometry{width=17cm, left=3cm, top=1cm, bottom=5cm}
\backgroundsetup{%
contents={\BIGFRAME}
 }
}

%    SMALLFRAME command
\newcommand{\SMALLFRAME}{
  \begin{tikzpicture}[remember picture,overlay]
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 18.4cm,
    minimum height = 28.5cm] (frame) at ($(current page.south east)+(-0.6cm,0.6cm)$) {};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1cm,
    minimum height = .8cm] (page) at ($(current page.south east)+(-0.6cm,0.6cm)$) {\thepage};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1cm,
    minimum height = .7cm] (pagename) at ($(page.north east)+(0cm,-0.04cm)$) {\small Page};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 11cm,
    minimum height = 1.5cm] (smallframe) at ($(page.south west)+(0.04cm,0cm)$) {pagestyle\{framesmall\}};
  \end{tikzpicture}%
}

%    BIGFRAME command
\newcommand{\BIGFRAME}{
\begin{tikzpicture}[remember picture,overlay]
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 18.4cm,
    minimum height = 28.5cm] (frame) at ($(current page.south east)+(-0.6cm,0.6cm)$) {};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 2cm,
    minimum height = .5cm] (pages) at ($(frame.south east)+(0cm,-0.03cm)$) {\pageref{LastPage}};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 2cm,
    minimum height = .5cm] (pagesname) at ($(pages.north east)+(0cm,-0.03cm)$) {Pages};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1.5cm,
    minimum height = .5cm] (page) at ($(pages.south west)+(0.03cm,-0.0cm)$) {\thepage}; %
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1.5cm,
    minimum height = .5cm] (pagename) at ($(pagesname.south west)+(0.03cm,-0.0cm)$) {Page};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 18.4cm,
    minimum height = 5.5cm] (smallframe) at ($(frame.south east)+(0.0cm,-0.03cm)$) {pagestyle\{framebig\}};
  \end{tikzpicture}%
}

% END of style's block
%%%%%%%%%%%%%%%%%%%%%%


\begin{document}

\pagestyle{framebig}
\tableofcontents

\part{part}
\chapter{chapter}

\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\part{part}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}
\chapter{chapter}
\section{section}
\section{section}



\end{document}

有没有办法使用给定的库来解决这个问题,或者是否需要额外的库?

我希望看到如下图所示的目录。

在此处输入图片描述

我很高兴收到我的问题的答复和评论。

PS 如何删除标准设计自带的页码(用红色圆圈标记)

答案1

您混合使用background包设置和titleps页面样式设置。它们都可以单独实现布局,但方式不同。您不应该将它们混合在一起。恕我直言,这titleps更可能是您应该使用的工具。因为您也可以使用它来设置页眉内容。此外,您在问题中询问如何删除页码,所以这是titleps包有用的地方。在下面的例子中,我将使用它titleps来实现您的目标,并且页眉目前设置为空。

对于大框架页面中的页边距更改和页面样式更改,以及将后续页面恢复为默认值。您需要使用包afterpage并重新定义\part\chapter命令。将\afterpage{\newgeometry{width=17cm, left=3cm, top=1cm, bottom=6cm}\restoregeometry}定义放在这两个命令的开头。这将使章节(也影响目录,因为它是章节的星号版本)和部分(我假设您希望部分页面也具有大框架布局)页面具有新的几何形状,并将后续页面恢复为默认值。默认情况下,\thispagestyle{plain}这两个命令定义中将有一个。因此,您需要将它们更改为,\thispagestyle{framebig}以便同时更改章节和部分页面的页面样式。

对于新的页面样式定义,你应该看看官方的文档此包的 含义\newpagestyle是为此页面样式设置新的页眉和页脚,您定义它的方式只是执行一些命令并忽略页脚和页眉内容。这不是您使用此命令应该做的事情。您可以设置的页眉和页脚内容共有 12 个:

\sethead[⟨even-left⟩][⟨even-center⟩][⟨even-right⟩] {⟨odd-left⟩}{⟨odd-center⟩}{⟨odd-right⟩}

\setfoot[⟨even-left⟩][⟨even-center⟩][⟨even-right⟩] {⟨odd-left⟩}{⟨odd-center⟩}{⟨odd-right⟩}

您可以使用这些位置中的任何一个来包含您的tikz代码,因为您使用remember pictureandoverlay选项并根据页面节点将节点置于绝对位置。我所做的只是将 ⟨odd-left⟩ 和 ⟨even-left⟩ 脚内容设置为代码tikz\SMALLFRAME\SMALLFRAME),并将其他内容保留为空(似乎您不想要任何标题)。

我删除了所有不必要的包。并tikz稍微调整一下代码,以完成没有calc库的绘图。通过使用shift={(-0.6cm,0.6cm)选项,您可以将节点放在相对于页面节点的位置。还有outer sep=0pt选项,让您在定位节点时无需考虑节点的线宽

最终代码如下:

\documentclass[a4paper, 12pt, oneside, hidelinks]{book}
\usepackage[width=17cm, left=3cm, top=1cm, bottom=2.5cm]{geometry}
%\usepackage[utf8]{inputenc}% Don't need any more
\usepackage[T2A]{fontenc}
\usepackage{tikz}
\usepackage{lastpage}
\usepackage{afterpage}
\usepackage{lmodern}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum} % for dummy text
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%
% My page styles with frame
%%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewcommand\part{%
  \afterpage{\newgeometry{width=17cm, left=3cm, top=1cm, bottom=6cm}\restoregeometry}
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \thispagestyle{framebig}%
  \if@twocolumn
    \onecolumn
    \@tempswatrue
  \else
    \@tempswafalse
  \fi
  \null\vfil
  \secdef\@part\@spart}
\renewcommand\chapter{%
\afterpage{\newgeometry{width=17cm, left=3cm, top=1cm, bottom=6cm}\restoregeometry}%
\if@openright\cleardoublepage\else\clearpage\fi%
    \thispagestyle{framebig}%
    \global\@topnum\z@
    \@afterindentfalse
    \secdef\@chapter\@schapter}
\makeatother

\newpagestyle{framesmall}{
\sethead[][][]{}{}{}
\setfoot[\SMALLFRAME][][]
{\SMALLFRAME}{}{}
}

\newpagestyle{framebig}{
\sethead[][][]{}{}{}
\setfoot[\BIGFRAME][][]
{\BIGFRAME}{}{}
}

%    SMALLFRAME command
\newcommand{\SMALLFRAME}{
  \begin{tikzpicture}[remember picture,overlay]
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 18.4cm,
    minimum height = 28.5cm,
    outer sep=0pt,
    shift={(-0.6cm,0.6cm)}
    ] (frame) at (current page.south east) {};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1.2cm,
    minimum height = .8cm,
    outer sep=0pt,
    shift={(-0.6cm,0.6cm)}
    ] (page) at (current page.south east) {\thepage};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1.2cm,
    minimum height = .7cm,outer sep=0pt] (pagename) at (page.north east) {\small Page};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 11cm,
    minimum height = 1.5cm,outer sep=0pt] (smallframe) at (page.south west) {pagestyle\{framesmall\}};
  \end{tikzpicture}%
}

%    BIGFRAME command
\newcommand{\BIGFRAME}{
\begin{tikzpicture}[remember picture,overlay]
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 18.4cm,
    minimum height = 28.5cm,
    outer sep=0pt,
    shift={(-0.6cm,0.6cm)}
    ] (frame) at (current page.south east) {};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 2cm,
    minimum height = .5cm,
    outer sep=0pt
    ] (pages) at (frame.south east) {\pageref{LastPage}};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 2cm,
    minimum height = .5cm,
    outer sep=0pt
    ] (pagesname) at (pages.north east) {Pages};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1.5cm,
    minimum height = .5cm,
    outer sep=0pt
    ] (page) at (pages.south west) {\thepage}; %
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 1.5cm,
    minimum height = .5cm,
    outer sep=0pt
    ] (pagename) at (pagesname.south west) {Page};
  \node[rectangle,
    draw = black,
    line width = 1pt,
    anchor=south east,
    minimum width = 18.4cm,
    minimum height = 5.5cm,
    outer sep=0pt
    ] (smallframe) at (frame.south east) {pagestyle\{framebig\}};
  \end{tikzpicture}%
}

% END of style's block
%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initial the common pagestyle %
% for regular page             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{framesmall}
\begin{document}
\tableofcontents
\part{part}
\lipsum[1-10]
\chapter{chapter}
\lipsum[1-10]
\section{section}
\section{section}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% create some dummy toc entries %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{tempcn}
\loop
\ifnum\value{tempcn}<21
\stepcounter{tempcn}
\addcontentsline{toc}{chapter}{Testing}\phantomsection
\addcontentsline{toc}{section}{Testing}
\addcontentsline{toc}{section}{Testing}
\repeat
\end{document}

输出:

在此处输入图片描述

相关内容