我在页面的右上角有文本(我的名字)和页码。但是,当我转到目录时,它会与文本一起显示页码。因此,如图所示,它显示“姓名 - 1”,但我希望目录中该部分的页码仅为“1”。我该如何实现?谢谢。
\documentclass[a4paper, 12pt]{article}
%Paragraph jumps and indentation
\setlength{\parindent}{1.25cm}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
%Border
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
%Double spacing
\usepackage{setspace}
\doublespacing
%Packages
\usepackage{fancyhdr}
\pagestyle{fancy}
\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset{0cm}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[R]{\thepage}
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyhead[R]{\thepage}%
}
\renewcommand{\thepage}{\text{Name}~~--~\arabic{page}}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{tabularx}
\usepackage[normalem]{ulem}
\newcommand{\di}{i}
\useunder{\uline}{\ul}{}
\usepackage{arabtex}
\usepackage{utf8}
\setcode{utf8}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{titlesec}
%Images
%Equation numbering
\counterwithin{equation}{section}
\usepackage{hyperref}
\urlstyle{same}
\pgfplotsset{compat=1.17}
\begin{document}
\thispagestyle{empty}
\setcounter{page}{0}
\thispagestyle{empty}
\tableofcontents
\clearpage
\section{x}
\clearpage
\section{y}
\end{document}
答案1
我的理解是,我认为你想要这样的东西:(我在建议的代码中稍微改变了正确的标题。我认为你的 MWE 中的破折号看起来太像减号了,当然,页码通常不是负数。)
\documentclass[a4paper, 12pt]{article}
%Paragraph jumps and indentation
\setlength{\parindent}{1.25cm}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
%Border
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
%Double spacing
\usepackage{setspace}
\doublespacing
%Packages
\usepackage{fancyhdr}
\pagestyle{fancy}
\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset{0cm}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
%\fancyhead[R]{\text{Name}~~--~\arabic{page}}
\fancyhead[R]{%
Name%
~\textendash{}~%
\thepage%
}
\fancypagestyle{plain}{%
\fancyhf{}%
%\fancyhead[R]{\thepage}%
}
%\renewcommand{\thepage}{\text{Name}~~--~\arabic{page}}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{tabularx}
\usepackage[normalem]{ulem}
\newcommand{\di}{i}
\useunder{\uline}{\ul}{}
\usepackage{arabtex}
\usepackage{utf8}
\setcode{utf8}
\usepackage{indentfirst}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{titlesec}
%Images
%Equation numbering
\counterwithin{equation}{section}
\usepackage{hyperref}
\urlstyle{same}
\pgfplotsset{compat=1.17}
\begin{document}
\thispagestyle{empty}
\setcounter{page}{0}
\thispagestyle{empty}
\tableofcontents
\clearpage
\section{x}
\clearpage
\section{y}
\end{document}