格式化论文关键词

格式化论文关键词

我需要以这种方式格式化多行关键字:

Keywords: keyword1  keyword2  keyword3
          keyword4

我使用给定的 LaTeX 类和关键字环境的对应定义是:

\newcommand\englishkeywords[1]{%
  \vspace{2ex}\noindent{\bf\zihao{-4} \ABCD@label@englishkeywords} \bf\zihao{-4}#1}

我尝试使用它\parbox来实现我想要的:

\newcommand\englishkeywords[1]{%
  \vspace{2ex}\noindent{\bf\zihao{-4} \ABCD@label@englishkeywords} \parbox[t][][t]{0.8\linewidth}{\raggedright\bf\zihao{-4}#1}}

代码运行得几乎完美,但我不知道如何设置 的width(此处为 0.8\linewidth)参数\parbox。如果我将其设置为更大的值,则会导致欠满或过满。我该如何解决这个问题,或者有没有更好的格式化方法?

更新:

抱歉没有描述清楚,我想改进这个课程,希望能够以更通用的方式做到这一点(即它也可以处理只有一行关键字的情况)

梅威瑟:

% things related to custom class have been removed
\documentclass[a4paper]{article}

\def\englishkeywordslabel{Keywords:~}
\newcommand\englishkeywords[1]{%
  \vspace{2ex}\noindent{\bf \englishkeywordslabel} \parbox[t][][t]{\linewidth}{\raggedright\bf#1}}
  %\vspace{2ex}\noindent{\bf englishkeywords} \bf#1}

\begin{document}
I'm a reference line I'm a reference line I'm a reference line I'm a reference line I'm a reference line 

\englishkeywords{keyword1\quad keyword2\quad keyword3\\ keyword4}
\end{document}

答案1

使用列表;您在处理 parbox 下方的间距时不会遇到任何问题。

\documentclass[a4paper]{article}

\newcommand\englishkeywordslabel{Keywords:}
\newcommand\englishkeywords[1]{%
  \begin{list}{}{%
    \setlength{\topsep}{2ex}%
    \settowidth{\leftmargin}{\bfseries\englishkeywordslabel~}%
    \setlength{\labelsep}{0pt}%
    \setlength{\labelwidth}{\leftmargin}%
    \setlength{\itemindent}{0pt}%
  }
  \raggedright\bfseries\item[\bfseries\englishkeywordslabel~]#1
  \end{list}
}
\begin{document}

I'm a reference line I'm a reference line I'm a reference line
I'm a reference line I'm a reference line

\englishkeywords{keyword1\quad keyword2\quad keyword3\\ keyword4}

I'm a reference line I'm a reference line I'm a reference line
I'm a reference line I'm a reference line

\end{document}

在此处输入图片描述

答案2

也许这对你有用。我不太确定你对一行关键字列表的担忧是什么,如果我理解错了,请告诉我。

无论如何,您可以改进格式。有两个明显的问题:(1)您使用的是过时的(对于 LaTeX)命令,例如\bf;(2)您可以“模块化”您的设置,以便可以在文档级别轻松更改它(假设关键字相关命令设置在或.cls.sty

\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}% for the sake of the example
\usepackage{etoolbox,xcolor}

\newcounter{countargs}%   count items in the list
\newcounter{iterateargs}% iterate over items in list

\newcommand{\mykeywords}[1]{%
  \bigskip
  \begingroup
  \centering
  \begin{minipage}{0.8\linewidth}
  \kwlabel\space
  \parbox[t]{0.8\linewidth}{%
      \setcounter{countargs}{0}%
      \renewcommand*{\do}[1]{\stepcounter{countargs}}%
      \docsvlist{#1}%
      \setcounter{iterateargs}{0}%
      \renewcommand*{\do}[1]{%
        \stepcounter{iterateargs}%
        \raggedright
        \printkeyword{##1}%
        \ifnum\value{iterateargs}<\value{countargs}%
        \keywordlistsep\quad   % <-- how to separate list items
        \else\fi
      }%
    \docsvlist{#1}%
  }%
\end{minipage}
\endgroup
\bigskip
}

% These are things that could be easily redefined in the `.tex` files if the above commands are in a `.cls` or `.sty` file...
% Keyword label:
\newcommand{\kwlabel}{{\kwlabelfmt
    Keywords:%
  }}
% Keyword label format:
\newcommand{\kwlabelfmt}{\bfseries\sffamily}
% format how the keywords appear
\newcommand{\printkeyword}[1]{\sffamily #1}
% Separator for list items
\newcommand{\keywordlistsep}{;}
% Note: depending on how much control you want to give to the user, other commands could be factored out and of \mykeywords....


\begin{document}
I'm a reference line I'm a reference line I'm a reference line I'm a reference line I'm a reference line


\mykeywords{keyword1, keyword2, keyword3, }

\renewcommand{\printkeyword}[1]{\textcolor{red}{#1}}

\mykeywords{keyword1, keyword2, keyword3, {keyword4, with commascommas in it, so it needs to be braced}, keyword 5}

\mykeywords{ Sorry for not describing it clearly{,} I want to improve
  the class and I hope to do this in a more versatile way (i.e. it can
  also deal with the case that there's only one line keywords}

\end{document}

相关内容