
嘗試編寫一個命令來產生一行第一個填滿的圓圈n
。所需的功能是\IBmark{l}{m}
其中l
是線的長度,m
是實心圓的數量。
用於LaTeX
背頁
\newcommand{\IBmark}[2]{\pgfmathparse{#1-#2}\textbf{\multido{}{#2}{\CIRCLE}\multido{}{\pgfmathresult}{\Circle}}}
我最好的嘗試是使用該包使其正常工作tikz
,但是它返回了這個
⚫⚫⚫.0OO
為了l = 5
,而m = 3
不是想要的
⚫⚫⚫OO
嘗試使用該pgf print
指令允許的捨入會傳回更糟糕的結果。我似乎找不到消除錯誤的方法。
答案1
您需要新增int(...)
到計算中\pgfmathparse
。
此外,在此實作中, 的使用\textbf
是不相關的,因此被刪除。
\documentclass{article}
\usepackage{txfonts}
\usepackage{pstricks-add}
\def\CIRCLE{$\medbullet$}
\def\Circle{$\medcirc$}
\newcommand{\IBmark}[2]{\pgfmathparse{int(#1-#2)}%
\multido{}{#2}{\CIRCLE}\multido{}{\pgfmathresult}{\Circle}}
\begin{document}
\IBmark{5}{3}
\end{document}
答案2
歡迎!從我拍攝的照片來看,您可能想要這樣的東西:
\documentclass{article}
\usepackage{tikz}
\newcommand{\IBmark}[2]{\begin{tikzpicture}[baseline={(X.base)},
cfill/.code={\unless\ifnum\X>#2
\tikzset{fill}
\fi}]
\path (1,-0.25ex) node (X) {\vphantom{X}}foreach \X in {1,...,#1}
{(\X*1.2em,0) node[circle,draw,minimum size=1em,cfill] {}};
\end{tikzpicture}}
\begin{document}
Hello \IBmark{5}{3}.
\end{document}
您可以調整幻像節點的垂直位置以獲得所需的任何對齊方式。原則上不需要TikZ 可以做到這一點,但用 Ti 完成這件事肯定很容易kZ。
答案3
如果我們使用 OpTeX 那麼我們可以這樣做:
\def\ibmark#1#2{\fornum 1..#1\do{\ifnum##1>#2$\circ$\else$\bullet$\fi}}
\ibmark{5}{3}
\bye