使用 PSTricks 绘制计数标记

使用 PSTricks 绘制计数标记

灵感来自 Paulo Cereda 的问题在这里,我想使用 PSTricks(或者 TikZ,如果没有人可以帮助使用 PSTricks)来绘制计数标记。

我不知道如何开始,所以我自己都无法尝试。:((我知道这并不好!)

我想要的是像这样的命令\tallymarks

\tallymarks{1}
\tallymarks{2}
...
\tallymarks{10}

并获得如下输出:

通缉

没有表格,也没有阿拉伯数字,只有计数标记本身。

更新 1

受到 Herbert 的想法的启发,这里尝试使用 PSTricks。

\documentclass{article}

\usepackage{pstricks-add}

\newcommand*{\tallymarksOne}{
  \pslineByHand(0,0)(0,1)
}
\newcommand*{\tallymarksTwo}{
  \pslineByHand(0,0)(0,1)
  \pslineByHand(0.25,0)(0.25,1)
}
\newcommand*{\tallymarksThree}{
  \pslineByHand(0,0)(0,1)
  \pslineByHand(0.25,0)(0.25,1)
  \pslineByHand(0.5,0)(0.5,1)
}
\newcommand*{\tallymarksFour}{
  \pslineByHand(0,0)(0,1)
  \pslineByHand(0.25,0)(0.25,1)
  \pslineByHand(0.5,0)(0.5,1)
  \pslineByHand(0.75,0)(0.75,1)
}
\newcommand*{\tallymarksFive}{
  \pslineByHand(0,0)(0,1)
  \pslineByHand(0.25,0)(0.25,1)
  \pslineByHand(0.5,0)(0.5,1)
  \pslineByHand(0.75,0)(0.75,1)
  \pslineByHand(-0.75,0)(1,1)
}

\newcounter{TallyTemp}
\def\tallymark#1{%
  \setcounter{TallyTemp}{#1}%
  \ifnum#1>5
    {\Tally E}\addtocounter{TallyTemp}{-5}%
  \else{\Tally%   
    \ifcase#1\or
    \tallymarksOne\addtocounter{TallyTemp}{-1}\or
    \tallymarksTwo\addtocounter{TallyTemp}{-2}\or
    \tallymarksThree\addtocounter{TallyTemp}{-3}\or
    \tallymarksFour\addtocounter{TallyTemp}{-4}\or
    \tallymarksFive\addtocounter{TallyTemp}{-5}%
    \fi}%
  \fi%
  \ifnum\theTallyTemp>0 \expandafter\tallymark\expandafter{\theTallyTemp}\fi
}

\begin{document}

\tallymark{0}
\tallymark{1}
\tallymark{2}
\tallymark{3}
\tallymark{4}
\tallymark{5}
\tallymark{14}

\end{document}

编译时,我收到一个错误:

! Undefined control sequence.
\tallymark ...ounter {TallyTemp}{-5}\else {\Tally 
                                                  \ifcase #1\or \tallymarksO...
l.50 \tallymark{0}

更新 2

Garbage Coloector 在 PSTricks 手册中向我提示了以下内容,但代码无法编译:

\documentclass{article}

\usepackage{pstricks-add}

\def\PstLineFuzzy[#1](#2,#3)(#4,#5)(#6,#7)(#8,#9){%
\pscurve[#1](! #2 rand 101 mod 1000 div sub
#3 rand 101 mod 1000 div sub)
(! #4 rand 101 mod 1000 div sub
#5 rand 101 mod 1000 div sub)
(! #6 rand 101 mod 1000 div sub
#7 rand 101 mod 1000 div sub)
(! #8 rand 101 mod 1000 div sub
#9 rand 101 mod 1000 div sub)}

\def\PstSticks#1{%
\multido{\iStick=0+1,\nXA=0.1+0.1,\nXB=-0.5+0.1,
\nXC=-0.35+0.10,\nXD=-0.15+0.10}{#1}{%
\pst@cnta=\iStick
\pst@cnth=\iStick
\divide\pst@cnth by 5
\multiply\pst@cnth by 5
\ifnum\iStick>0\relax
\ifnum\pst@cnta=\pst@cnth
\PstLineFuzzy[linecolor=red]%
(\nXB,0.2)(\nXC,0.4)(\nXD,0.6)(\nXA,0.8)
\hbox to 0.2\psxunit{}
\fi
\fi
\PstLineFuzzy[](\nXA,0.1)(\nXA,0.4)(\nXA,0.7)(\nXA,1)}}

\begin{document}

\psset{xunit=0.8,yunit=0.3}%
\begin{tabular}{|l|r|p{5.5cm}|}
\hline
Linux
& 27 & \PstSticks{27} \\ \hline
Mac OS X
& 14 & \PstSticks{14} \\ \hline
Windows XP & 43 & \PstSticks{43} \\ \hline
\end{tabular}

\end{document}

错误是

! Undefined control sequence.
<inserted text> \pst 
                     @cnta=\iStick \pst @cnth=\iStick \divide \pst @cnth by ...
l.38 & 27 & \PstSticks{27}
                           \\ \hline

答案1

使用xelatexlualatex。TallyMark 字体可从http://www.fonts2u.com/tally-mark.font

\documentclass{article}
\usepackage{fontspec}
\newfontface\Tally{TallyMark}
\newcounter{TallyTemp}
\def\tallymark#1{%
  \setcounter{TallyTemp}{#1}%
  \ifnum#1>5
    {\Tally E}\addtocounter{TallyTemp}{-5}%
  \else{\Tally%   
    \ifcase#1\or
    A\addtocounter{TallyTemp}{-1}\or
    B\addtocounter{TallyTemp}{-2}\or
    C\addtocounter{TallyTemp}{-3}\or
    D\addtocounter{TallyTemp}{-4}\or
    E\addtocounter{TallyTemp}{-5}%
    \fi}%
  \fi%
  \ifnum\theTallyTemp>0 \expandafter\tallymark\expandafter{\theTallyTemp}\fi
}

\begin{document}

\tallymark{0}
\tallymark{1}
\tallymark{2}
\tallymark{3}
\tallymark{4}
\tallymark{5}
\tallymark{14}

\end{document}

在此处输入图片描述

如果您想使用 PSTricks,则定义命令\ONE、、\TWO...并绘制线条。非常简单:

\documentclass{article}    
\usepackage{pstricks-add}    
\newcommand*\tallymarksOne{\pslineByHand(0,0)(0,1)}
\newcommand*\tallymarksTwo{\tallymarksOne\pslineByHand(2pt,0)(2pt,1)}
\newcommand*\tallymarksThree{\tallymarksTwo\pslineByHand(4pt,0)(4pt,1)}
\newcommand*\tallymarksFour{\tallymarksThree\pslineByHand(6pt,0)(6pt,1)}
\newcommand*\tallymarksFive{\tallymarksFour\pslineByHand(-17pt,0)(8pt,1)}

\newcounter{TallyTemp}
\def\tallymark#1{%
  \setcounter{TallyTemp}{#1}%
  \ifnum#1>5
    \tallymarksFive\kern14pt \addtocounter{TallyTemp}{-5}%
  \else%   
    \ifcase#1\or
    \tallymarksOne\kern3pt \addtocounter{TallyTemp}{-1}\or
    \tallymarksTwo\kern6pt \addtocounter{TallyTemp}{-2}\or
    \tallymarksThree\kern9pt \addtocounter{TallyTemp}{-3}\or
    \tallymarksFour\kern12pt \addtocounter{TallyTemp}{-4}\or
    \tallymarksFive\kern14pt \addtocounter{TallyTemp}{-5}%
    \fi%
  \fi%
  \ifnum\theTallyTemp>0 \expandafter\tallymark\expandafter{\theTallyTemp}\fi
  \vspace{1cm}
}

\begin{document}

\tallymark{0}\par
\tallymark{1}\par
\tallymark{2}\par
\tallymark{3}\par
\tallymark{4}\par
\tallymark{5}\par
\tallymark{14}

\end{document}

在此处输入图片描述

答案2

你不需要任何特殊字体,任何 PSTricks,只需要\pdfliteral

\newcount\tmpnum
\def\tallymarks#1{\leavevmode \lower1bp\vbox to9bp{}%
   \tmpnum=#1
   \loop \ifnum\tmpnum<5 \kern1bp \tallynum\tmpnum \else \tallyV \fi
         \advance\tmpnum by-5
         \ifnum\tmpnum>0 \repeat
}
\def\tallynum#1{\bgroup\tmpnum=#1\relax
   \loop \ifnum\tmpnum>0
         \kern1bp \tallyI \kern1bp
         \advance\tmpnum by-1
         \repeat
   \egroup
}
\def\tallyI{\pdfliteral{q .5 w 0 -1 m 0 8 l S Q}}
\def\tallyV{\kern1bp\pdfliteral{q .5 w -1 0 m 9 7 l S Q}\tallynum4\kern1bp }

test1: \tallymarks{3}

test2: \tallymarks{17}

\bye

相符

答案3

这是一个expl3方法:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn

\int_new:N \snehal_tally_full_int
\int_new:N \snehal_tally_partial_int
\box_new:N \snehal_tally_slash_box

\cs_generate_variant:Nn \int_step_inline:nnnn { nnVn }

\cs_new_protected:Npn \snehal_tally_mark:n #1
 {
  \int_set:Nn \snehal_tally_full_int { \int_div_truncate:nn { #1 } { 5 } }
  \int_set:Nn \snehal_tally_partial_int { \int_mod:nn { #1 } { 5 } }

  \int_step_inline:nnVn { 1 } { 1 } \snehal_tally_full_int
   {
    \hbox_set:Nn \snehal_tally_slash_box { $\big|$ }
    \box_rotate:Nn \snehal_tally_slash_box { -70 }
    \ensuremath
     {
      \ooalign
       {
        $||||$ \tex_cr:D
        \hidewidth \tex_raise:D .7ex \box_use:N \snehal_tally_slash_box \hidewidth
       }
     }~
   }
  \ensuremath
   {
    \int_step_inline:nnVn { 1 } { 1 } \snehal_tally_partial_int { | }
   }
 }

\NewDocumentCommand \tallymark { m }
 {
  \snehal_tally_mark:n { #1 }
 }

\ExplSyntaxOff
\begin{document}

\tallymark{1001}

\end{document}

在此处输入图片描述

答案4

我发现最简单的方法是使用\usepackage[misc]{ifsym},然后相应地使用命令\StrokeFive、、等 \StrokeFour\StrokeOne在此处输入图片描述

相关内容