自定义编号样式使用符号数而不是数字

自定义编号样式使用符号数而不是数字

有没有可能通过符号的数量来计数?例如,如果我想打印一个字母的 4 个版本,我分配了 \arabic{#1} 数字,它显示:

1 2 3 4

我想要的是显示如下内容:

* ** *** **** 或者;用不同的符号代替每个数字。例如:

 * for 1
# for 2 

等等。

我正在准备不同版本的考试,我想用符号而不是数字来显示版本号。提前致谢。

更新: 尽管我得到了专家的良好回应,但我仍然无法做到我真正需要的。我想我无法很好地阐述我的问题,这就是为什么我决定提供一个最小的代码。这是我的代码:

\documentclass[twoside]{article}
\usepackage[english]{babel}
\usepackage{comment}
% set fonts
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{microtype}
\usepackage{etoolbox}
\newcommand{\comm}[1]{}
\ifdef{\myoutput}{}{\def\myoutput{exam}}
\ifdef{\myversion}{}{\def\myversion{2}}

% mcexams options.
\usepackage[output=\myoutput
           ,numberofversions=5
           ,version=\myversion
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=true
           ]{mcexam}

\usepackage[margin=0.95in]{geometry}
% Packages used for special things
\usepackage{framed,booktabs} 


% Set headers and footers
\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lhead{Name:\hrulefill{}\quad Student ID:\hrulefill{}}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}


\begin{document}
% Exam preamble stuff - this will be printed on every version
\begin{center}
  \bfseries\Huge exam title \\
  \LARGE 

\end{center}

% Show which version is being printed (Concept, Answers, etc.)
\begin{center}\bfseries\Huge\MakeUppercase{\mctheversion}\end{center}

% This only shows on the "Exam" form that students see. So put instructions, etc. here.
\mcifoutput{exam}{
\large\bigskip

\noindent Name: \hrulefill{}\hrulefill{}\hrulefill{}\quad{}Student ID\#: \hrulefill\hrulefill{} \\[.75\baselineskip]



On your scantron, use either a pencil or pen:

} % end if exam



\end{document}

如果有人能给我提供解决此特定问题的确切解决方案,我将不胜感激。我尝试定义 newcounter 或更改 \mctheversion 值,但版本中仍然显示数字而不是符号。请看下图: 在此处输入图片描述

答案1

无需任何包,仅使用标准 LaTeX 代码和“原始” \loop

\documentclass{article}

\newcounter{mycntr}

\makeatletter
\newcommand{\lettersymbols}[1]{%
  \begingroup
  \setcounter{mycntr}{0}
  \loop\unless\ifnum\value{mycntr}=#1
  \mysymbol%
  \addtocounter{mycntr}{1}%
  \repeat
  \endgroup
}
\makeatother

\newcommand{\mysymbol}{\textasteriskcentered}

\begin{document}
\setcounter{section}{5}

\renewcommand{\thesection}{\lettersymbols{\number\value{section}}}

\thesection

\end{document}

来自 OP 的代码

\mctheversion宏负责版本的输出,因此只需使用\lettersymbols或进行相应更改\repeatedsymbols即可。请注意,这\MakeUppercase可能会失败。

\documentclass[twoside]{article}
\usepackage[english]{babel}
\usepackage{comment}
% set fonts
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{microtype}
\usepackage{etoolbox}
\newcommand{\comm}[1]{}
\ifdef{\myoutput}{}{\def\myoutput{exam}}
\ifdef{\myversion}{}{\def\myversion{2}}


\newcommand{\mysymbol}{\textasteriskcentered}


\newcount\mycntr

\newcommand{\repeatedsymbols}[1]{%
  \begingroup
  \mycntr=0
  \loop\unless\ifnum\mycntr=#1%
  \mysymbol%
  \advance\mycntr by 1
  \repeat
  \endgroup
}



\newcommand{\lettersymbols}[1]{%
  \ifcase#1
  \or
  \textasteriskcentered
  \or
  \textdollar
  \or
  \textdagger
  \or
  \textsection
  \or
  \textsterling
  \fi
}


% mcexams options.
\usepackage[output=\myoutput
           ,numberofversions=5
           ,version=\myversion,
           ,seed=1
           ,randomizequestions=true
           ,randomizeanswers=true
           ,writeRfile=true
           ]{mcexam}

\usepackage[margin=0.95in]{geometry}
% Packages used for special things
\usepackage{framed,booktabs} 


% Set headers and footers
\usepackage{fancyhdr,lastpage}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{1pt}
\lhead{Name:\hrulefill{}\quad Student ID:\hrulefill{}}
\lfoot{\mctheversion}
\rfoot{Page \thepage\ of \pageref{LastPage}}


\AtBeginDocument{%
  \renewcommand{\mctheversion}{\lettersymbols{\value{mcversion}}}
%  \renewcommand{\mctheversion}{\repeatedsymbols{\value{mcversion}}}
}


\begin{document}

% Exam preamble stuff - this will be printed on every version
\begin{center}
  \bfseries\Huge exam title \\
  \LARGE 

\end{center}

% Show which version is being printed (Concept, Answers, etc.)
\begin{center}\bfseries\Huge\mctheversion\end{center}

% This only shows on the "Exam" form that students see. So put instructions, etc. here.
\mcifoutput{exam}{
\large\bigskip

\noindent Name: \hrulefill{}\hrulefill{}\hrulefill{}\quad{}Student ID\#: \hrulefill\hrulefill{} \\[.75\baselineskip]



On your scantron, use either a pencil or pen:

} % end if exam



\end{document}

答案2

您可以使用以下方式轻松完成xparse

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\numsym}{m}
 {
  \int_compare:nTF { \use:c { c@#1 } > \tl_count:N \c_majid_numsym_tl }
   {
    \use:c { @ctrerr }
   }
   {
    \tl_item:Nn \c_majid_numsym_tl { \use:c { c@#1 } }
   }
 }

\tl_const:Nn \c_majid_numsym_tl
 {% add to the list using the same format {<command>}
  {*}{\#}{@}{!}{?}
 }
\ExplSyntaxOff

\newcounter{test}
\renewcommand{\thetest}{\numsym{test}}

\begin{document}

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\end{document}

在此处输入图片描述

重复一个符号就更容易了:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewExpandableDocumentCommand{\repsym}{mm}
 {
  \prg_replicate:nn { \use:c { c@#2 } } { #1 }
 }
\ExplSyntaxOff

\newcounter{test}
\renewcommand{\thetest}{\repsym{*}{test}}

\begin{document}

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\stepcounter{test}\arabic{test}: \thetest

\end{document}

在此处输入图片描述

答案3

我不知道这是否已经存在,但构建这种东西很容易。当然,如果你想要更高的值,你需要让符号列表更长。

\documentclass{article}
\usepackage{pgffor}
\newcommand{\nbullets}[1]{%
\foreach \X in {1,...,#1}
{\textbullet}}
\def\lstsyms{{"","*","\#","@","!","?"}}
\newcommand{\numsymbol}[1]{%
\pgfmathparse{\lstsyms[#1]}%
\pgfmathresult
}

\begin{document}
3:\nbullets{3}, 7:\nbullets{7}

\renewcommand{\labelenumi}{\nbullets{\value{enumi}}}
\begin{enumerate}
 \item first
 \item second
 \item third
 \item last 
\end{enumerate}

1:\numsymbol{1}, 2:\numsymbol{2}, 3:\numsymbol{3}
\end{document}

在此处输入图片描述

相关内容