\huge 和 \newcommand 变量不能一起工作

\huge 和 \newcommand 变量不能一起工作

我想在某处定义一个项目名称并在我的整个文档中使用它 - 但是当我尝试在文档标题中使用我的项目名称时遇到了问题,该标题应该很大,所以我尝试了这种方式:

\newcommand{\projectName}{MyProject}

...

\begin{titlepage}
\begin{center}

\HRule \\[1.2cm] % horizontal line
{\huge \bfseries \projectName{}}\\[0.5cm] % title
\HRule \\[1.5cm] % Horizontal line

\end{center}
\end{titlepage}

但是当我尝试设置文件时得到的结果如下:

./TitlePage.tex:lineNumberWhereProjectNameIsUsed: Undefined control sequence.

有人知道吗我做错了什么或者我该如何解决这个问题

感谢所有帮助者的建议!

编辑:以下是完整的主 .tex 文件内容(其中包括上面的 TitlePage.tex):

\documentclass[11pt, a4paper, oneside]{Thesis} % Paper size, default font size and one-sided paper

\graphicspath{{./Pictures/}} % Specifies the directory where pictures are stored

\usepackage[square, numbers, comma, sort&compress]{natbib} % Use the natbib reference package - read up on this to edit the reference style; if you want text (e.g. Smith et al., 2012) for the in-text references (instead of numbers), remove 'numbers' 
\hypersetup{urlcolor=blue, colorlinks=true} % Colors hyperlinks in blue - change to black if annoying
\usepackage[ngerman]{babel}     % Sprachen
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{varioref}
\hyphenation{}
% adding glossary functionality
\usepackage{hyperref}
\usepackage[toc]{glossaries}
\makeglossaries
\input{./GlossaryEntries} 
% only showing chapters and sections in table of contents
\setcounter{tocdepth}{1}


\begin{document}
\selectlanguage{ngerman}    % set language to german

\frontmatter % Use roman page numbering style (i, ii, iii, iv...) for the pre-content pages

\setstretch{1.3} % Line spacing of 1.3

% Define the page headers using the FancyHdr package and set up for one-sided printing
\fancyhead{} % Clears all page headers and footers
\rhead{\thepage} % Sets the right side header to show the page number
\lhead{} % Clears the left side page header

\pagestyle{fancy} % Finally, use the "fancy" page style to implement the FancyHdr headers

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % New command to make the lines in the title page

%----------------------------------------------------------------------------------------
%   TITLE PAGE
%----------------------------------------------------------------------------------------

\include{TitlePage}

\end{document}  

答案1

看起来你正在使用这个论文模板。您想要的一个最小工作示例是:

\documentclass[11pt,a4paper,oneside]{Thesis}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

\begin{document}

\newcommand{\projectName}{MyProject}

\begin{titlepage}
\begin{center}

\HRule \\[1.2cm]
{\huge \bfseries \projectName{}}\\[0.5cm]
\HRule \\[1.5cm]

\end{center}
\end{titlepage}

\end{document}

生成一个包含以下内容的页面

Sample output

将其放在您的代码示例中并仅注释掉该行,则\input{./GlossaryEntries}下面的文件可以毫无问题地进行编译并产生类似的结果。

\documentclass[11pt, a4paper, oneside]{Thesis} % Paper size, default font size and one-sided paper

\graphicspath{{./Pictures/}} % Specifies the directory where pictures are stored

\usepackage[square, numbers, comma, sort&compress]{natbib} % Use the natbib reference package - read up on this to edit the reference style; if you want text (e.g. Smith et al., 2012) for the in-text references (instead of numbers), remove 'numbers' 
\hypersetup{urlcolor=blue, colorlinks=true} % Colors hyperlinks in blue - change to black if annoying
\usepackage[ngerman]{babel}     % Sprachen
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{varioref}
\hyphenation{}
% adding glossary functionality
\usepackage{hyperref}
\usepackage[toc]{glossaries}
\makeglossaries
%\input{./GlossaryEntries} 
% only showing chapters and sections in table of contents
\setcounter{tocdepth}{1}


\begin{document}
\selectlanguage{ngerman}    % set language to german

\frontmatter % Use roman page numbering style (i, ii, iii, iv...) for the pre-content pages

\setstretch{1.3} % Line spacing of 1.3

% Define the page headers using the FancyHdr package and set up for one-sided printing
\fancyhead{} % Clears all page headers and footers
\rhead{\thepage} % Sets the right side header to show the page number
\lhead{} % Clears the left side page header

\pagestyle{fancy} % Finally, use the "fancy" page style to implement the FancyHdr headers

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % New command to make the lines in the title page

%----------------------------------------------------------------------------------------
%   TITLE PAGE
%----------------------------------------------------------------------------------------

\newcommand{\projectName}{MyProject}

\begin{titlepage}
\begin{center}

\HRule \\[1.2cm] % horizontal line
{\huge \bfseries \projectName{}}\\[0.5cm] % title
\HRule \\[1.5cm] % Horizontal line

\end{center}
\end{titlepage}

\end{document}

相关内容