答案1
\documentclass{article}
\usepackage{stackengine}
\setstackEOL{\\}
\newcounter{tmpctr}
\newcommand\fancyRoman[1]{%
\setcounter{tmpctr}{#1}%
\setbox0=\hbox{\kern.2pt\textsf{\Roman{tmpctr}}}%
\setstackgap{S}{-.6pt}%
\Shortstack{\rule{\dimexpr\wd0+.1ex}{.7pt}\\\copy0\\
\rule{\dimexpr\wd0+.1ex}{.7pt}}%
}
\begin{document}
Fancy Romans:
1--5: \fancyRoman{1}
\fancyRoman{2}
\fancyRoman{3}
\fancyRoman{4}
\fancyRoman{5}
6--10: \fancyRoman{6}
\fancyRoman{7}
\fancyRoman{8}
\fancyRoman{9}
\fancyRoman{10}
11--12: \fancyRoman{11}
\fancyRoman{12}
\end{document}
答案2
我改用了一个叫做romanbar
包来写罗马数字,你还可以在其中看到用户@egreg 的宏,它与问题下方评论的链接相同,
这是我的小代码:
\documentclass[12pt,a4paper]{article}
\usepackage{newtxtext}%%%%%%%%%%%% <----optional (it gives a best view of the roman numbers) -
%%%% You can choose another font compilable with pdfLaTeX
\usepackage{romanbar}
\begin{document}
\Romanbar{1}, \Romanbar{2}, \Romanbar{5}, \Romanbar{10}, \Romanbar{43}
\end{document}
答案3
\documentclass[12pt,a4paper]{article}
\usepackage{newtxtext}
% <----optional (it gives a best view of the roman numbers) -
% You can choose another font compilable with pdfLaTeX
\usepackage{romanbar}
\begin{document}
\Romanbar{1}, \Romanbar{2}, \Romanbar{5}, \Romanbar{10}, \Romanbar{43}
\end{document}