我正在尝试创建一个页面样式,其中 \guideNameA 是必需的,如果使用 \guideNameB,那么我想相应地修改页面样式。此外,我需要通过检查我在序言中是否使用了 \stuNameB 来修改文档内容。以下是页面样式
\ProvidesPackage{Title}[2020/01/11 v.01 an example package]
\RequirePackage{graphicx}
\RequirePackage{tikz}
\newcommand*{\guideNameA}[1]{\gdef\@guideNameA{#1}}
\newcommand*{\@guideNameA}{\texttt{\string\guideNameA} currently not set. Please fix this.}
\newcommand*{\guideNameB}[1]{\gdef\@guideNameA{#1}}
\newcommand*{\@guideNameB}{}
\newcommand*{\stuNameA}[1]{\gdef\@stuNameA{#1}}
\newcommand*{\@stuNameA}{\texttt{\string\stuNameA} currently not set. Please fix this.}
\newcommand*{\stuUSNA}[1]{\gdef\@stuUSNA{#1}}
\newcommand*{\@stuUSNA}{\texttt{\string\stuUSNA} currently not set. Please fix this.}
\newcommand*{\stuNameB}[1]{\gdef\@stuNameB{#1}}
\newcommand*{\@stuNameB}{}
\newcommand*{\stuUSNB}[1]{\gdef\@stuUSNB{#1}}
\newcommand*{\@stuUSNB}{}
\newcommand*{\stuNameC}[1]{\gdef\@stuNameC{#1}}
\newcommand*{\@stuNameC}{}
\newcommand*{\stuUSNC}[1]{\gdef\@stuUSNC{#1}}
\newcommand*{\@stuUSNC}{}
\renewcommand*{\maketitle}{%
\begin{titlepage}
\begin{tikzpicture}[remember picture, overlay]
\draw[line width = 4pt] ($(current page.north west) + (0.75in,-0.75in)$) rectangle ($(current page.south east) + (-0.75in,0.75in)$);
\end{tikzpicture}
\begin{center}
\vspace{1cm}
{\Large\bfseries\@title\unskip\strut\par}
\vspace{0.25cm}
{\Large\bfseries\ PROJECT REPORT\unskip\strut\par}
\vspace{0.25cm}
{\Large\bfseries Submitted by,\unskip\strut\par}
\end{center}
{\noindent\large\bfseries\@stuNameA\unskip\strut}\hfill{\large\bfseries\@stuUSNA\unskip\strut\par}
\vspace{0.25cm}
{\noindent\large\bfseries\@stuNameB\unskip\strut}\hfill{\large\bfseries\@stuUSNB\unskip\strut\par}
\vspace{0.25cm}
{\noindent\large\bfseries\@stuNameC\unskip\strut}\hfill{\large\bfseries\@stuUSNC\unskip\strut\par}
\begin{center}
{\Large\bfseries Under the guidance of \unskip\strut\par}
\end{center}
%%%%%%Check if \guideNameB is used%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%If true %%%%%%%%%%%%%
{\noindent\large\bfseries\@guideNameA\unskip\strut}\hfill{\large\bfseries\@guideNameB\unskip\strut\par}
%%%%%%%%%%%%%Else %%%%%%%%%%%%%%%%%
\begin{center}
{\large\bfseries\@guideNameA\unskip\strut\par}
\end{center}
\end{titlepage}
}
\endinput
并且该文件是
\documentclass{book}
%Packages
\usepackage{Title}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[a4paper, margin=1in]{geometry}
%%%%%%%%%%%%%%% Commands used from "Title" %%%%%%%%%%
\stuNameA{P Narashimaraja}
\stuUSNA{1RV07EC007}
\stuNameB{Nithin M}
\stuUSNB{1RV14EC001}
\guideNameA{Narashimaraja}
\guideNameB{Ramavenkateshwaran}
\begin{document}
\maketitle
%%%%%%%%%%%%%%%%%%%If \stuNameB{} command is used, then %%%%%%%%%%%%%%
Certified that the major project work titled \textbf{\textit{TITLE}} is carried out by \textbf{STUDENT NAME A} **and \textbf{STUDENT NAME B}** who **are** bonafide students of College of Engineering
%%%%%%%%%%%%%%%%%%%%%Else %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Certified that the major project work titled \textbf{\textit{TITLE}} is carried out by \textbf{STUDENT NAME A} who **is** bonafide students of College of Engineering
\end{document}
答案1
您可以使用 TeX 的\newif
宏来定义布尔值。在 之后\newif\iffoo
,可以使用\footrue
或设置布尔值\foofalse
,并使用 进行测试\iffoo ... \else ... \fi
。请注意,设置布尔值时要遵守 TeX 的分组规则:除非前面有\global
,否则这种设置仅限于最内层的组。将其应用到您的代码中,我做了以下操作(这包括您在问题中没有提到但似乎需要的补充,正如我从评论中理解的那样):
% Title.sty
...
\newif\ifGuideNameBUsed % initial state: false
\newif\ifStuNameBUsed % ditto
...
\newcommand*{\guideNameB}[1]{\gdef\@guideNameB{#1}\global\GuideNameBUsedtrue}
...
\newcommand*{\stuNameB}[1]{\gdef\@stuNameB{#1}\global\StuNameBUsedtrue}
...
\renewcommand*{\maketitle}{%
\begin{titlepage}
...
\ifGuideNameBUsed
...
\else
...
\fi
\vfill
\CollegeCertification
\end{titlepage}%
}
\newcommand*{\CollegeCertification}{%
...
\ifStuNameBUsed
...
\else
...
\fi
}
学生文件:
\documentclass{book}
\usepackage{Title}
...
\title{The Foo Project}
\stuNameA{P.~Duckafoo}
...
\guideNameA{Prof.~Prof.~Canard}
...
\begin{document}
\maketitle
Student text goes here.
\end{document}
我修复了你的这一行Title.sty
:
\newcommand*{\guideNameB}[1]{\gdef\@guideNameA{#1}}
它定义或覆盖\@guideNameA
而不是。我还修复了示例文档末尾的\@guideNameB
“学生”(单个学生情况下的额外内容)。此外,可以从包代码中要求其库和包;没有必要用这个来污染学生文档的序言,因为该行会自动执行所需的操作(在我看来,一个更好的包名称,更具体地说是使用此包的学院结构,将是一个好主意……)。以下是完整的代码:s
tikz
calc
graphicx
Title
\usepackage{Title}
Title.sty
:
\ProvidesPackage{Title}[2020/01/24 v0.1 An example package]
\RequirePackage{graphicx}
\RequirePackage{tikz}
\usetikzlibrary{calc}
\newif\ifGuideNameBUsed % initial state: false
\newif\ifStuNameBUsed % ditto
\newcommand*{\guideNameA}[1]{\gdef\@guideNameA{#1}}
\newcommand*{\@guideNameA}{\texttt{\string\guideNameA} currently not set. Please fix this.}
\newcommand*{\guideNameB}[1]{\gdef\@guideNameB{#1}\global\GuideNameBUsedtrue}
\newcommand*{\@guideNameB}{}
\newcommand*{\stuNameA}[1]{\gdef\@stuNameA{#1}}
\newcommand*{\@stuNameA}{\texttt{\string\stuNameA} currently not set. Please fix this.}
\newcommand*{\stuUSNA}[1]{\gdef\@stuUSNA{#1}}
\newcommand*{\@stuUSNA}{\texttt{\string\stuUSNA} currently not set. Please fix this.}
\newcommand*{\stuNameB}[1]{\gdef\@stuNameB{#1}\global\StuNameBUsedtrue}
\newcommand*{\@stuNameB}{}
\newcommand*{\stuUSNB}[1]{\gdef\@stuUSNB{#1}}
\newcommand*{\@stuUSNB}{}
\newcommand*{\stuNameC}[1]{\gdef\@stuNameC{#1}}
\newcommand*{\@stuNameC}{}
\newcommand*{\stuUSNC}[1]{\gdef\@stuUSNC{#1}}
\newcommand*{\@stuUSNC}{}
\renewcommand*{\maketitle}{%
\begin{titlepage}
\begin{tikzpicture}[remember picture, overlay]
\draw[line width = 4pt]
($(current page.north west) + (0.75in,-0.75in)$) rectangle
($(current page.south east) + (-0.75in,0.75in)$);
\end{tikzpicture}
\begin{center}
\vspace{1cm}
{\Large\bfseries\@title\unskip\strut\par}
\vspace{0.25cm}
{\Large\bfseries\ PROJECT REPORT\unskip\strut\par}
\vspace{0.25cm}
{\Large\bfseries Submitted by,\unskip\strut\par}
\end{center}
{\noindent\large\bfseries\@stuNameA\unskip\strut}\hfill{\large\bfseries\@stuUSNA\unskip\strut\par}
\vspace{0.25cm}
{\noindent\large\bfseries\@stuNameB\unskip\strut}\hfill{\large\bfseries\@stuUSNB\unskip\strut\par}
\vspace{0.25cm}
{\noindent\large\bfseries\@stuNameC\unskip\strut}\hfill{\large\bfseries\@stuUSNC\unskip\strut\par}
\begin{center}
{\Large\bfseries Under the guidance of \unskip\strut\par}
\end{center}
\ifGuideNameBUsed
{\noindent\large\bfseries\@guideNameA\unskip\strut}%
\hfill
{\large\bfseries\@guideNameB\unskip\strut\par}%
\else
\begin{center}
{\large\bfseries\@guideNameA\unskip\strut\par}%
\end{center}%
\fi
\vfill
\CollegeCertification
\end{titlepage}%
}
\newcommand*{\CollegeCertification}{%
\noindent
\ifStuNameBUsed
Certified that the major project work titled \textbf{\textit{\@title}} is
carried out by \textbf{\@stuNameA} and \textbf{\@stuNameB} who are
\emph{bonafide} students of College of Engineering.
\else
Certified that the major project work titled \textbf{\textit{\@title}} is
carried out by \textbf{\@stuNameA} who is a \emph{bonafide} student of
College of Engineering.
\fi
}
\endinput
学生文件样本:
\documentclass{book}
\usepackage{Title}
\usepackage[a4paper, margin=1in]{geometry}
\title{The Foo Project}
\stuNameA{P.~Duckafoo}
\stuUSNA{1RV07EC007}
\stuNameB{Q.~Quack}
\stuUSNB{1RV14EC001}
\guideNameA{Prof.~Prof.~Canard}
\guideNameB{Prof.~Dr.~Poulet~Jr.}
\begin{document}
\maketitle
\end{document}
我不得不说,我不太喜欢这种很厚的框架和\large\bfseries
标题页上的类型...无论如何,这里有四种可能情况的截图:
- 一名导师,一名学生:
- 一名导师,两名学生:
- 两名导师,一名学生:
- 两名导师,两名学生:
回答你上次的请求
回答此评论。在 的末尾Title.sty
, 之前\endinput
,添加:
\newcommand*{\printStuNameA}{\leavevmode\@stuNameA}
\newcommand*{\printStuNameB}{\leavevmode\@stuNameB}
然后,您可以在学生文档中使用\CollegeCertification
宏或类似这样的内容:
\ifStuNameBUsed
Two students: \printStuNameA\ and \printStuNameB.
\else
Only one student: \printStuNameA.
\fi
\CollegeCertification
如果您不想要我在标题页中包含的最后一项内容,只需删除包含之前的行\end{titlepage}
即可Title.sty
。