编辑

编辑

我想养成一些良好的 LaTeX 编码习惯。我知道我属于新手,我很想听听建议。

我们有一个由一些 MS Word 用户创建的旧文档标题,我用手指绘制了 LaTeX 来大致匹配它。下面讨论的示例代码生成的标题是:

在此处输入图片描述

图像中有 NEEDarg10、NEEDarg11、NEEDarg12,这些都是占位符,我希望可以将作者 2 的信息放入其中。

我首先将文档和作者信息“放在”一个 3 列表格中,现在我想了解如何抽象该结构,以便文档内的使用更加清晰。我想将结构隐藏在序言或样式文件中。

我需要将很多信息放入这个标题中。我遇到了 newcommand 只允许 9 个参数的问题。这导致我在 author1 信息之后的努力付诸东流。

%1 logo left
%2 logo right
%3 Title
%4 Guide number
%5 URL
%6 keywords
%7 Author1 name
%8 Author1 Affiliation
%9 Author1 email
% Wish I could have flexible method to insert more authors
%10 Author2 name
%11 Authot2 Affiliation
%12 Author2 email

即使它允许超过 9 个参数,用户界面也很丑陋。我有点不切实际地想象,我们将在文档中以正确的顺序获取这些参数:

\crmdahdr{logoleft.png}%1
         {logoright.png}%2
         {A Very Long Title: With a Possibly Long Subtitle}%3
         {45}%4
         {https://crmda.ku.edu/guides}%5
         {\LaTeX, Programming}%6
         {Firstname1 Lastname1}%7
         {CRMDA}%8
         {email1.edu}

一般问题:重新设计这个的最佳方法是什么?我在 Google 上搜索了很多次,不知道该相信谁,哪种模板样式好。在我看来,最常见的方法是让用户声明许多全局变量,这些值不需要显式传递给函数。这样好吗?

您能告诉我如何为作者姓名、所属机构和电子邮件创建一个结构,并将这些结构作为参数传递,以便在新命令中使用吗?

我不想将其构建为一个全新的文档类,我希望可以自由地将其作为 tex 或 sty 文件放入各种文档中。这个使用 KOMA,我不记得为什么了。

\documentclass[11pt,letterpaper,english]{scrartcl}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{color}
\usepackage{babel}
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=true,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=true]
 {hyperref}

\makeatletter

\@ifundefined{date}{}{\date{}}

\usepackage[includehead,includefoot]{geometry}
\geometry{
lmargin=1in,
rmargin=1in,
tmargin=0.75in,
bmargin=1.0in,
headheight=0pt,
headsep=0pt,
marginparwidth=0pt,
footskip=1.5\baselineskip,
}

\usepackage{multicol}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[yyyymmdd,hhmmss]{datetime}

\usepackage{babel}
\usepackage{array}
\providecommand{\tabularnewline}{\\}

%1 logo left
%2 logo right
%3 Title
%4 Guide number
%5 URL
%6 keywords
%7 Author1 name
%8 Author1 Affiliation
%9 Author1 email
%Wish I could have
%10 Author2 name
%11 Authot2 Affiliation
%12 Author2 email

\newcommand{\crmdahdr}[9]{
  \begin{tabular}{|>{\centering}p{1.25in}>{\raggedright}p{3.5in}>{\raggedleft}p{1.75in}|}
  \hline 
  \begin{minipage}[c]{1.25in}%
  \begin{center}
  \textsc{\includegraphics[width=1.25in]{#1}}
  \par\end{center}%
  \end{minipage} & %
  \begin{minipage}[c][1\totalheight][b]{3.5in}%
  \bigskip
  \begin{center}
  \begin{minipage}[t][1\totalheight][b]{1\columnwidth}%
  \begin{center}
  \textbf{\large{}#3}\\
  \rule[0.5ex]{1\linewidth}{1pt}
  \par\end{center}%
  \end{minipage}
  \par\end{center}{\Huge \par}
  \begin{minipage}[t]{1\columnwidth}%
  \begin{center}
  \textbf{#7}, #8 <#9>\\
  \textbf{NEEDarg10}, NEEDarg11 <NEEDarg12>
  \par\end{center}%
  \end{minipage}

  \smallskip{}

  \begin{flushleft}
  \textbf{Guide No}: #4.\\
  \textbf{Keywords}: #6\\
  See \url{#5} for updates.
  \par\end{flushleft}
  \smallskip%
  \end{minipage} & %
  \begin{minipage}[c]{1.75in}%
  \smallskip{}

  \begin{center}
  \includegraphics[width=1.75in]{#2}
  \par\end{center}{\Huge \par}%
  \end{minipage}

  \begin{minipage}[c]{1.75in}%
  \smallskip{}
  \begin{center}
  \today
  \par\end{center}%
  \end{minipage}\tabularnewline
  \hline 
  \end{tabular}
}%%end

\makeatother

\begin{document}

\crmdahdr{logoleft.png}%1
         {logoright.png}%2
         {A Very Long Title: With a Possibly Long Subtitle}%3
         {45}%4
         {https://crmda.ku.edu/guides}%5
         {\LaTeX, Programming}%6
         {Firstname1 Lastname1}%7
         {CRMDA}%8
         {email1.edu}

Some words here
\end{document}

我知道您需要左上角和右上角的图像“logoleft.png”和“logoright.png”。如果您不介意的话,我会附上空白的白色图像文件:徽标左徽标右

我有一个小问题。我从一个更大的项目中取出此代码来制作 MRE,并删除了许多包和其他结构。我注意到,当我删除 hyperref 包时,文档不再编译且无错误。

第 121 行:未定义控制序列。{email1.edu}

为什么删除 hyperef 会导致这种情况?

答案1

这会整理前言,消除坏框并设置键值接口。键可以提前单独设置,也可以在调用命令时通过可选参数设置。

如果这样做,您应该为所有键设置默认值和/或配置有意义的错误消息。

如果您不使用expl3语法,请注意您的代码会引入大量虚假空格,其中一些可能会反过来伤害您,而其余的则会困扰您的梦想并在您的坟墓上跳舞。

键值接口允许使用任意数量的键(当然,取决于 TeX 对这些键的限制),通常更易于使用,并且可使代码更简洁、更易读且更易于维护。也就是说,它们非常流行。

\documentclass[11pt,letterpaper,american]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{babel}% surely once is sufficient
\usepackage{parskip}% seems a shame to do this with a KOMA class, but if you must
\usepackage[includehead,includefoot]{geometry}% this stomps all over KOMA's efforts - if you want to use KOMA, use KOMA; otherwise, if you want geometry and stuff, use a standard class [unless you are forced to do otherwise - there are some complex cases, mostly involve US theses, but there you just have to take the view that your document is going to look like crap because the school requires crap for you to graduate]
\usepackage{multicol}
\usepackage{listings}
\usepackage[demo]{graphicx}
\usepackage{xcolor}% loads color
\usepackage[yyyymmdd,hhmmss]{datetime}
\usepackage{array,tabularx}
\usepackage{xparse}
\usepackage[unicode=true,pdfusetitle, bookmarks=true,bookmarksnumbered=false,bookmarksopen=false, breaklinks=true,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=true] {hyperref}
% \tabularnewline, \date are defined in core LaTeX
\geometry{% as I say - this is a crappy way to treat a KOMA class
  lmargin=1in,
  rmargin=1in,
  tmargin=0.75in,
  bmargin=1.0in,
  headheight=0pt,
  headsep=0pt,
  marginparwidth=0pt,
  footskip=1.5\baselineskip,
}

\ExplSyntaxOn
\NewDocumentCommand \crmdasetup { +m }
{
  \keys_set:nn { crmda } { #1 }
}
\keys_define:nn { crmda }
{
    first ~ author .code:n = {
      \keys_set:nn { crmda / first ~ author } { #1 }
    },
    second ~ author .code:n = {
      \keys_set:nn { crmda / second ~ author } { #1 }
    },
    first ~ author / first ~ name .tl_set:N = \l_crmda_first_first_name_tl,
    first ~ author / last ~ name .tl_set:N = \l_crmda_first_last_name_tl,
    first ~ author / affiliation .tl_set:N = \l_crmda_first_affil_tl,
    first ~ author / email .tl_set:N = \l_crmda_first_email_tl,
    second ~ author / first ~ name .tl_set:N = \l_crmda_second_first_name_tl,
    second ~ author / last ~ name .tl_set:N = \l_crmda_second_last_name_tl,
    second ~ author / affiliation .tl_set:N = \l_crmda_second_affil_tl,
    second ~ author / email .tl_set:N = \l_crmda_second_email_tl,
    left ~ logo .tl_set:N = \l_crmda_left_logo_tl,
    right ~ logo .tl_set:N = \l_crmda_right_logo_tl,
    number .int_set:N = \l_crmda_number_int,
    title .tl_set:N = \l_crmda_title_tl,
    keywords .tl_set:N = \l_crmda_keywords_tl,
    url .tl_set:N = \l_crmda_url_tl,
    first ~ author .initial:n = { first ~ name = Santa, last ~ name = Claus, affiliation = Toys ~ Research ~ Institute, email = [email protected]},
    second ~ author .initial:n = { first ~ name = Tooth, last ~ name = Fairy, affiliation = Institute ~ of ~ Dentistry, email = [email protected]},
    url .initial:n = {https://keys.invensions.bym},
    number .initial:n = 42,
    title .initial:n = {Guide ~ to ~ Guides},
    keywords .initial:n = {guide},
}
\NewDocumentCommand \crmdahdr { +o }
{
  \IfValueT { #1 } 
  {
    \keys_set:nn { crmda } { #1 }
  }
  \crmda_hdr:
}
\cs_new_protected:Nn \crmda_hdr:
{
  \noindent
  \begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}p{1.25in}>{\centering\arraybackslash}X>{\raggedleft\arraybackslash}p{1.25in}|}
    \hline 
    \begin{minipage}[c]{\linewidth}
      \begin{center}
        \includegraphics[width=\linewidth]{\l_crmda_left_logo_tl} % no point in have small caps for an image
        \par
      \end{center}%
    \end{minipage} & 
    \begin{minipage}[c][1\totalheight][b]{3.5in}%
      \bigskip
      \begin{center}
        \begin{minipage}[t][1\totalheight][b]{1\columnwidth}%
          \begin{center}
            \textbf{ \large \l_crmda_title_tl }\\
            \rule[0.5ex]{1\linewidth}{1pt}
            \par\end{center}%
        \end{minipage}
        \par
      \end{center}{\Huge \par} % ??!!??
      \begin{minipage}[t]{1\columnwidth}
        \begin{center}
          \textbf{\l_crmda_first_first_name_tl {} ~ \l_crmda_first_last_name_tl}, ~\l_crmda_first_affil_tl {} ~ <\l_crmda_first_email_tl >\\
          \textbf{\l_crmda_second_first_name_tl {} ~ \l_crmda_second_last_name_tl}, ~\l_crmda_second_affil_tl {} ~ <\l_crmda_second_email_tl >
          \par
        \end{center}
      \end{minipage}      
      \smallskip
      \par     
      \begin{flushleft}
        \textbf{Guide No}: ~ \int_to_arabic:n { \l_crmda_number_int  } .\\
        \textbf{Keywords}: ~ \l_crmda_keywords_tl \\
        See ~ \url{\l_crmda_url_tl} ~ for ~ updates.
        \par
      \end{flushleft}
      \smallskip
    \end{minipage} & 
    \begin{minipage}[c]{\linewidth}
      \smallskip
      \par
      \begin{center}
        \includegraphics[width=\linewidth]{\l_crmda_right_logo_tl}
        \par
      \end{center}
      {\Huge \par}
    \end{minipage}
    \par
    \begin{minipage}[c]{\linewidth}
      \smallskip
      \begin{center}
        \today
        \par
      \end{center}
    \end{minipage}
    \tabularnewline
    \hline 
  \end{tabularx}
}
\ExplSyntaxOff

\begin{document}

\crmdahdr[% use this optional argument or set keys with \crmdasetup{<keys>} beforehand
  first author={last name=Lastname1 , first name=Firstname1, affiliation=CRMDA, email=email1.edu},
  second author={last name=Lastname2 , first name=Firstname2, affiliation=CRMDB, email=email2.edu},
  url={https://crmda.ku.edu/guides},
  keywords={\LaTeX, Programming},
  title={A Very Long Title: With a Possibly Long Subtitle},
  left logo={logoleft},
  right logo={logoright},
  number=45,
]

Some words here
\end{document}

标题

编辑

这是使第二作者可选的一种方法。我不确定我是否会从头开始这样做,但这是一种快速调整现有代码的方法。

\documentclass[11pt,letterpaper,american]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{babel}% surely once is sufficient
\usepackage{parskip}% seems a shame to do this with a KOMA class, but if you must
\usepackage[includehead,includefoot]{geometry}% this stomps all over KOMA's efforts - if you want to use KOMA, use KOMA; otherwise, if you want geometry and stuff, use a standard class [unless you are forced to do otherwise - there are some complex cases, mostly involve US theses, but there you just have to take the view that your document is going to look like crap because the school requires crap for you to graduate]
\usepackage{multicol}
\usepackage{listings}
\usepackage[demo]{graphicx}
\usepackage{xcolor}% loads color
\usepackage[yyyymmdd,hhmmss]{datetime}
\usepackage{array,tabularx}
\usepackage{xparse}
\usepackage[unicode=true,pdfusetitle, bookmarks=true,bookmarksnumbered=false,bookmarksopen=false, breaklinks=true,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=true] {hyperref}
% \tabularnewline, \date are defined in core LaTeX
\geometry{% as I say - this is a crappy way to treat a KOMA class
  lmargin=1in,
  rmargin=1in,
  tmargin=0.75in,
  bmargin=1.0in,
  headheight=0pt,
  headsep=0pt,
  marginparwidth=0pt,
  footskip=1.5\baselineskip,
}

\ExplSyntaxOn
\NewDocumentCommand \crmdasetup { +m }
{
  \bool_set_false:N \l_crmda_two_authors_bool
  \keys_set:nn { crmda } { #1 }
}
\keys_define:nn { crmda }
{
    first ~ author .code:n = {
      \keys_set:nn { crmda / first ~ author } { #1 }
    },
    second ~ author .code:n = {
      \keys_set:nn { crmda } { two ~ authors }
      \keys_set:nn { crmda / second ~ author } { #1 }
    },
    two ~ authors .bool_set:N = \l_crmda_two_authors_bool,
    two ~ authors .default:n = true,
    two ~ authors .initial:n = false,
    first ~ author / first ~ name .tl_set:N = \l_crmda_first_first_name_tl,
    first ~ author / last ~ name .tl_set:N = \l_crmda_first_last_name_tl,
    first ~ author / affiliation .tl_set:N = \l_crmda_first_affil_tl,
    first ~ author / email .tl_set:N = \l_crmda_first_email_tl,
    second ~ author / first ~ name .tl_set:N = \l_crmda_second_first_name_tl,
    second ~ author / last ~ name .tl_set:N = \l_crmda_second_last_name_tl,
    second ~ author / affiliation .tl_set:N = \l_crmda_second_affil_tl,
    second ~ author / email .tl_set:N = \l_crmda_second_email_tl,
    left ~ logo .tl_set:N = \l_crmda_left_logo_tl,
    right ~ logo .tl_set:N = \l_crmda_right_logo_tl,
    number .int_set:N = \l_crmda_number_int,
    title .tl_set:N = \l_crmda_title_tl,
    keywords .tl_set:N = \l_crmda_keywords_tl,
    url .tl_set:N = \l_crmda_url_tl,
    first ~ author .initial:n = { first ~ name = Santa, last ~ name = Claus, affiliation = Toys ~ Research ~ Institute, email = [email protected]},
    second ~ author .initial:n = { first ~ name = Tooth, last ~ name = Fairy, affiliation = Institute ~ of ~ Dentistry, email = [email protected]},
    url .initial:n = {https://keys.invensions.bym},
    number .initial:n = 42,
    title .initial:n = {Guide ~ to ~ Guides},
    keywords .initial:n = {guide},
}
\NewDocumentCommand \crmdahdr { +o }
{
  \group_begin:
    \IfValueT { #1 } 
    {
      \bool_set_false:N \l_crmda_two_authors_bool
      \keys_set:nn { crmda } { #1 }
    }
    \crmda_hdr:
  \group_end:
}
\cs_new_protected:Nn \crmda_hdr:
{
  \noindent
  \begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}p{1.25in}>{\centering\arraybackslash}X>{\raggedleft\arraybackslash}p{1.25in}|}
    \hline 
    \begin{minipage}[c]{\linewidth}
      \begin{center}
        \includegraphics[width=\linewidth]{\l_crmda_left_logo_tl} % no point in have small caps for an image
        \par
      \end{center}%
    \end{minipage} & 
    \begin{minipage}[c][1\totalheight][b]{3.5in}%
      \bigskip
      \begin{center}
        \begin{minipage}[t][1\totalheight][b]{1\columnwidth}%
          \begin{center}
            \textbf{ \large \l_crmda_title_tl }\\
            \rule[0.5ex]{1\linewidth}{1pt}
            \par\end{center}%
        \end{minipage}
        \par
      \end{center}{\Huge \par} % ??!!??
      \begin{minipage}[t]{1\columnwidth}
        \begin{center}
          \textbf{\l_crmda_first_first_name_tl {} ~ \l_crmda_first_last_name_tl}, ~\l_crmda_first_affil_tl {} ~ <\l_crmda_first_email_tl >
          \bool_if:NT \l_crmda_two_authors_bool
          {
            \\
            \textbf{\l_crmda_second_first_name_tl {} ~ \l_crmda_second_last_name_tl}, ~\l_crmda_second_affil_tl {} ~ <\l_crmda_second_email_tl >
          }
          \par
        \end{center}
      \end{minipage}      
      \smallskip
      \par     
      \begin{flushleft}
        \textbf{Guide No}: ~ \int_to_arabic:n { \l_crmda_number_int  } .\\
        \textbf{Keywords}: ~ \l_crmda_keywords_tl \\
        See ~ \url{\l_crmda_url_tl} ~ for ~ updates.
        \par
      \end{flushleft}
      \smallskip
    \end{minipage} & 
    \begin{minipage}[c]{\linewidth}
      \smallskip
      \par
      \begin{center}
        \includegraphics[width=\linewidth]{\l_crmda_right_logo_tl}
        \par
      \end{center}
      {\Huge \par}
    \end{minipage}
    \par
    \begin{minipage}[c]{\linewidth}
      \smallskip
      \begin{center}
        \today
        \par
      \end{center}
    \end{minipage}
    \tabularnewline
    \hline 
  \end{tabularx}
}
\ExplSyntaxOff

\begin{document}

\crmdahdr

\crmdahdr[% use this optional argument or set keys with \crmdasetup{<keys>} beforehand
  first author={last name=Lastname1 , first name=Firstname1, affiliation=CRMDA, email=email1.edu},
  second author={last name=Lastname2 , first name=Firstname2, affiliation=CRMDB, email=email2.edu},
  url={https://crmda.ku.edu/guides},
  keywords={\LaTeX, Programming},
  title={A Very Long Title: With a Possibly Long Subtitle},
  left logo={logoleft},
  right logo={logoright},
  number=45,
]

\crmdasetup{%
  first author={last name=Author , first name=Only, affiliation=CRMDC, email=lone.edu},
  url={https://crmda.ku.edu/guides},
  keywords={single-authoring, just one},
  title={Another Very Long Title: With a Possibly Long Subtitle},
  left logo={logoleft},
  right logo={logoright},
  number=48,
}
\crmdahdr

Some words here
\end{document}

请注意,如果您使用\crmdasetup,则选项将全局设置,而如果您将它们传递给可选参数\crmdahdr,则它们仅在组内本地设置。

三个标题

答案2

我修改了 @cfr 的代码,并找到了一个适用于一、二或三名作者的情况的解决方案。它与 @cfr 提出的解决方案相同,只是我不在键名中使用空格。也许我太老了,看不清左侧的“姓氏”。这对我来说看起来很危险。所以我把它写成“姓氏”,和其他的类似。

结果如下:

在此处输入图片描述

代码如下。如您所见,这种方法不容易添加新作者。它需要复制/粘贴定义其他作者的节。我尝试使用我在 xparse 文档中找到的一些代码来获得更通用的方法。我认为我可以通过像这样的可选参数检查来轻松解决问题

 \IfNoValueF{\l_guide_second_firstname_tl}{
      \textbf{\l_guide_second_firstname_tl {} ~
      l_guide_second_lastname_tl}, ~\l_guide_second_affil_tl {} ~ 
      <\l_guide_second_email_tl >\\}

但它从来没有奏效。我不知道如何将 -NoValue- 设置为其他作者的默认值。也许你知道怎么做。

我将尝试制作另一个 MRE 测试案例,以探索更灵活的项目添加。在这种情况下,我不会考虑作者,而是考虑班级名册,该名册必须随着学生的增加或删除而轻松增加和缩小。这对我来说可能是一次教育经历。

但这有效,我受到鼓舞继续尝试。再次感谢@cfr 的帮助。

\documentclass[11pt,letterpaper,american]{article}
% PJ 20170914: This is my answer to guide with 3 authors
% See https://tex.stackexchange.com/questions/391114/writing-newcommands-user-interface-advice-request?noredirect=1#comment971803_391114
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{babel}% surely once is sufficient
\usepackage{parskip}% seems a shame to do this with a KOMA class, but if you must
\usepackage[includehead,includefoot]{geometry}%
\usepackage{multicol}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{xcolor}% loads color
\usepackage[yyyymmdd,hhmmss]{datetime}
\usepackage{array,tabularx}
\usepackage{xparse}
\usepackage{ifthen}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false, bookmarksopen=false,
breaklinks=true, pdfborder={0 0 0},
pdfborderstyle={},backref=false,
colorlinks=true] {hyperref}

\geometry{
  lmargin=1in,
  rmargin=1in,
  tmargin=0.75in,
  bmargin=1.0in,
  headheight=0pt,
  headsep=0pt,
  marginparwidth=0pt,
  footskip=1.5\baselineskip,
}

\ExplSyntaxOn
\NewDocumentCommand \guidesetup { +m }
{
  \bool_set_false:N \l_guide_twoauthors_bool
  \bool_set_false:N \l_guide_threeauthors_bool
  \keys_set:nn { guide } { #1 }
}
\keys_define:nn { guide }
{
    firstauthor .code:n = {
      \keys_set:nn { guide / firstauthor } { #1 }
    },
    secondauthor .code:n = {
      \keys_set:nn { guide } { twoauthors }
      \keys_set:nn { guide / secondauthor } { #1 }
    },
    thirdauthor .code:n = {
      \keys_set:nn { guide } { threeauthors }
      \keys_set:nn { guide / thirdauthor } { #1 }
    },
    twoauthors .bool_set:N = \l_guide_twoauthors_bool,
    twoauthors .default:n = true,
    twoauthors .initial:n = false,
    threeauthors .bool_set:N = \l_guide_threeauthors_bool,
    threeauthors .default:n = true,
    threeauthors .initial:n = false,
    firstauthor / firstname .tl_set:N = \l_guide_first_firstname_tl,
    firstauthor / lastname .tl_set:N = \l_guide_first_lastname_tl,
    firstauthor / affiliation .tl_set:N = \l_guide_first_affil_tl,
    firstauthor / email .tl_set:N = \l_guide_first_email_tl,
    secondauthor / firstname .tl_set:N = \l_guide_second_firstname_tl,
    secondauthor / lastname .tl_set:N = \l_guide_second_lastname_tl,
    secondauthor / affiliation .tl_set:N = \l_guide_second_affil_tl,
    secondauthor / email .tl_set:N = \l_guide_second_email_tl,
    thirdauthor / firstname .tl_set:N = \l_guide_third_firstname_tl,
    thirdauthor / lastname .tl_set:N = \l_guide_third_lastname_tl,
    thirdauthor / affiliation .tl_set:N = \l_guide_third_affil_tl,
    thirdauthor / email .tl_set:N = \l_guide_third_email_tl,
    leftlogo .tl_set:N = \l_guide_leftlogo_tl,
    rightlogo .tl_set:N = \l_guide_rightlogo_tl,
    number .int_set:N = \l_guide_number_int,
    title .tl_set:N = \l_guide_title_tl,
    keywords .tl_set:N = \l_guide_keywords_tl,
    url .tl_set:N = \l_guide_url_tl,
    firstauthor .initial:n = { firstname = a, lastname = b,
      affiliation = c, email = d},
    secondauthor .initial:n = { firstname = g, lastname = h,
      affiliation = i, email = j},
    thirdauthor .initial:n = { firstname = g, lastname = h,
      affiliation = i, email = j},
    url .initial:n = {https://ku.edu},
    number .initial:n = 42,
    title .initial:n = {Guide ~ to ~ Guides},
    keywords .initial:n = {guide},
}
\NewDocumentCommand \guidehdr { +o }
{
  \group_begin:
    \IfValueT { #1 } 
    {
      \bool_set_false:N \l_guide_twoauthors_bool 
      \keys_set:nn { guide } { #1 }
    }
    \guide_hdr:
    \group_end:
}
\cs_new_protected:Nn \guide_hdr:
{
  \noindent
  \begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}p{1.25in}>{\centering\arraybackslash}X>{\raggedleft\arraybackslash}p{1.25in}|}
    \hline 
    \begin{minipage}[c]{\linewidth}
      \begin{center}
        \includegraphics[width=\linewidth]{jayhawk.pdf}
        \par
      \end{center}%
    \end{minipage} & 
    \begin{minipage}[c][1\totalheight][b]{3.5in}%
      \bigskip
      \begin{center}
        \begin{minipage}[t][1\totalheight][b]{1\columnwidth}%
          \begin{center}
            \textbf{ \large \l_guide_title_tl }\\
            \rule[0.5ex]{1\linewidth}{1pt}
            \par\end{center}%
        \end{minipage}
        \par
      \end{center}
      \begin{minipage}[t]{1\columnwidth}
        \begin{center}
          \textbf{\l_guide_first_firstname_tl {} ~ \l_guide_first_lastname_tl}, ~\l_guide_first_affil_tl {} ~ <\l_guide_first_email_tl >
          \bool_if:NT \l_guide_twoauthors_bool
          {
            \\
            \textbf{\l_guide_second_firstname_tl {} ~ \l_guide_second_lastname_tl}, ~\l_guide_second_affil_tl {} ~ <\l_guide_second_email_tl >
          }
          \bool_if:NT \l_guide_threeauthors_bool
          {
            \\
            \textbf{\l_guide_third_firstname_tl {} ~ \l_guide_third_lastname_tl}, ~\l_guide_third_affil_tl {} ~ <\l_guide_third_email_tl >
          }
          \par
        \end{center}
      \end{minipage}      
      \smallskip
      \par     
      \begin{flushleft}
        {\small{}\textbf{Guide ~ No}: ~ \int_to_arabic:n { \l_guide_number_int  }}\\
        \textbf{Keywords}: ~ \l_guide_keywords_tl \\
        See ~ \url{\l_guide_url_tl} ~ for ~ updates.
        \par
      \end{flushleft}
      \smallskip
    \end{minipage} & 
    \begin{minipage}[c]{\linewidth}
      \smallskip
      \par
      \begin{center}
        \includegraphics[width=\linewidth]{\l_guide_rightlogo_tl}
        \par
      \end{center}
      {\Huge \par}
    \end{minipage}
    \par
    \begin{minipage}[c]{\linewidth}
      \smallskip
      \begin{center}
        \today
        \par
      \end{center}
    \end{minipage}
    \tabularnewline
    \hline 
  \end{tabularx}
}
\ExplSyntaxOff

\begin{document}

%% Try just one author:

\guidesetup{%
  firstauthor={last name=Author , first name=Only, affiliation=CRMDC, email=lone.edu},
  url={https://crmda.ku.edu/guides},
  keywords={single-authoring, just one},
  title={Another Very Long Title: With a Possibly Long Subtitle},
  leftlogo={jayhawk.pdf},
  rightlogo={CRMDAlogo-vert.pdf},
  number=48,
}
\guidehdr

% Try two authors
\guidesetup{
  firstauthor={lastname=Jonas-Smith, firstname=Arthur P.,
    affiliation=CRMDA, [email protected]},
  secondauthor={lastname=Montague, firstname=Wellington P., affiliation=i, email=g}, 
  url={https://crmda.ku.edu/guides},
  keywords={\LaTeX, Programming},
  title={A Very Long Title: With a Possibly Long Subtitle},
  leftlogo={jayhawk.pdf},
  rightlogo={CRMDAlogo-vert.pdf},
  number=45,
  }
\guidehdr




\guidesetup{%
  firstauthor={last name=Author , first name=First, affiliation=CRMDC,
    email=lone.edu},
  secondauthor={lastname=Author, firstname=Second, affiliation=CRMDD, email=g},
  thirdauthor={lastname=Author, firstname=Third, affiliation=i, email=g}, 
  url={https://crmda.ku.edu/guides},
  keywords={single-authoring, just one},
  title={Another Very Long Title: With a Possibly Long Subtitle},
  leftlogo={jayhawk.pdf},
  rightlogo={CRMDAlogo-vert.pdf},
  number=48,
}
\guidehdr




Some words here
\end{document}

相关内容