对于我的所有文档,我创建了一个 template.tex 文件,该文件被导入到我的所有文件中。但它说我遇到了这些问题:
/home/rperrod/rp/PERSO/LaTeX/Test/template/t.tex:20: Undefined control sequence. [ \setlength{\footheight}{10mm}]
/home/rperrod/rp/PERSO/LaTeX/Test/template/t.tex:20: LaTeX Error: Missing \begin{document}. [ \setlength{\footheight}{10mm}]
/home/rperrod/rp/PERSO/LaTeX/Test/template/t.tex:25: Undefined control sequence. [ \allowdisplaybreaks]
这是我的测试文件:
\documentclass[a4paper, 12pt]{article}
\usepackage[english, french]{babel}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{varwidth}
%----------- My template file ---------
\geometry{
a4paper,
left=16mm,
top=16mm,
bottom=16mm,
right=16mm
}
\pagestyle{fancy}
\fancyhf{}
\setlength{\headheight}{10mm}
\lhead{\textsc{Some Text}}
\rhead{\textsc{SOME} Text}
\setlength{\footheight}{10mm}
\rfoot{\thepage}
\date{}
\author{}
\allowdisplaybreaks
%-----------------------------------
\title{I'm a giraffe}
\begin{document}
\maketitle\thispagestyle{fancy}
Lorem ipsum
\section{Colorado}
\newpage
\newpage
\section{Says}
\newpage
\section{Giraaaaaaaaaaaaaaaffe}
\end{document}
问题出在哪里?我刚从朋友那里复制了这个,对他来说,它有效。我忘记了某个包吗?
答案1
最好在几何定义中包含headheight
和footskip
(不包含),而不是单独包含。footheight
\setlength
\documentclass[a4paper, 12pt]{文章}
\usepackage[english, french]{babel}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{varwidth}
\usepackage{amsmath}
%----------- My template file ---------
\geometry{
a4paper,
left=16mm,
top=16mm,
bottom=16mm,
right=16mm,
headheight=10mm,
footskip=10mm,
}
\pagestyle{fancy}
\fancyhf{}
\lhead{\textsc{Some Text}}
\rhead{\textsc{SOME} Text}
\rfoot{\thepage}
\date{}
\author{}
\allowdisplaybreaks
%-----------------------------------
\title{I'm a giraffe}
\begin{document}
\maketitle\thispagestyle{fancy}
Lorem ipsum
\section{Colorado}
\newpage
\newpage
\section{Says}
\newpage
\section{Giraaaaaaaaaaaaaaaffe}
\end{document}
答案2
您显示的错误消息的格式具有误导性,因为它掩盖了哪个命令未定义。
第一个错误是
! Undefined control sequence.
<argument> \footheight
l.23 \setlength{\footheight}{10mm}
?
如果你注释掉第 23 行并重新运行,那么你会得到
! Undefined control sequence.
l.28 \allowdisplaybreaks
amsmath
这是尚未加载的命令,因此添加
\usepackage{amsmath}
您还可获得
Package french.ldf Warning: OT1 encoding should not be used for French.
(french.ldf) Add \usepackage[T1]{fontenc} to the preamble
(french.ldf) of your document; reported on input line 35.
综合起来,没有警告或错误:
\documentclass[a4paper, 12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[english, french]{babel}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{varwidth}
\usepackage{amsmath}
%----------- My template file ---------
\geometry{
a4paper,
left=16mm,
top=16mm,
bottom=16mm,
right=16mm
}
\pagestyle{fancy}
\fancyhf{}
\setlength{\headheight}{10mm}
\lhead{\textsc{Some Text}}
\rhead{\textsc{SOME} Text}
% \setlength{\footheight}{10mm}
\rfoot{\thepage}
\date{}
\author{}
\allowdisplaybreaks
%-----------------------------------
\title{I'm a giraffe}
\begin{document}
\maketitle\thispagestyle{fancy}
Lorem ipsum
\section{Colorado}
\newpage
\newpage
\section{Says}
\newpage
\section{Giraaaaaaaaaaaaaaaffe}
\end{document}