我想要显示代表如下地图的 UTF-8 字符:
\documentclass[11pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage[spanish]{babel}
\begin{document}\shorthandoff{>}\shorthandoff{<}
\begin{verbatim}
# # # # # ↓ # # # # # # # # # # #
# → → ↓ #
# # ↓ # #
# # → ↓ # #
# # # # # # ↓ # # # # #
# ↓ ← # #
# ↓ # #
# ↓ # # # # # #
# → → → → → → → ↓ #
# # # # # → ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # # # # # → → #
# # # # #
# # # #
# # # #
# # # # # # # # # # # # # # # # #
\end{verbatim}
\end{document}
我怎样才能使箭头占据与数字符号相同的空间?
答案1
在上述文件中发生的情况是,将其→
定义为\rightarrow
,而其又被定义为特定的(非等宽)字符。
相反,使用 XeTeX 或 LuaTeX,您可以使用任何您喜欢的 Unicode 字符,只要您使用的字体可以覆盖这些字符即可。在这种情况下,在我的系统上寻找一种可以覆盖所有提到的字符的等宽字体 ( # ↓ → ← ■ ╚ ╝
),我找到了许多选项(单击图像以正确查看):
\documentclass{article}
\usepackage{fontspec}
\begin{document}
\begin{verbatim}
whatever `verbatim` uses by default
######
■╚↓→←╝
\end{verbatim}
\setmonofont{Andale Mono}
\begin{verbatim}
Andale Mono
######
■╚↓→←╝
\end{verbatim}
\setmonofont{Courier New}
\begin{verbatim}
Courier New
######
■╚↓→←╝
\end{verbatim}
\setmonofont{Consolas}
\begin{verbatim}
Consolas
######
■╚↓→←╝
\end{verbatim}
\setmonofont{Lucida Console}
\begin{verbatim}
Lucida Console
######
■╚↓→←╝
\end{verbatim}
\setmonofont{Menlo}
\begin{verbatim}
Menlo
######
■╚↓→←╝
\end{verbatim}
\setmonofont{Times New Roman}
\begin{verbatim}
Times New Roman (not a monospace font!)
######
■╚↓→←╝
\end{verbatim}
\end{document}
我倾向于使用合适的等宽字体,而不是图像。
答案2
使用textcomp
就足够了。
避免
utf8x
那些已经好几年没有维护的,而那些utf8
维护得很好并且已经扩展到覆盖几个字符块的。T1
书写西班牙语时使用输出编码。该选项比停用和速记
es-noquoting
更好。<
>
现在是代码。
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc} % needed for Spanish
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-noquoting]{babel}
\usepackage{textcomp}
\begin{document}
\begin{verbatim}
# # # # # ↓ # # # # # # # # # # #
# → → ↓ #
# # ↓ # #
# # → ↓ # #
# # # # # # ↓ # # # # #
# ↓ ← # #
# ↓ # #
# ↓ # # # # # #
# → → → → → → → ↓ #
# # # # # → ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # # # # # → → #
# # # # #
# # # #
# # # #
# # # # # # # # # # # # # # # # #
\end{verbatim}
\end{document}
您可以使用pmboxdraw
其他符号,只要您使用正确的符号即可。简短示例:
\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc} % needed for Spanish
\usepackage[utf8]{inputenx}
\usepackage[spanish,es-noquoting]{babel}
\usepackage{textcomp}
\usepackage{pmboxdraw}
\pmboxdrawsetup{
Block/box={\texttt{0}},
}
\begin{document}
\begin{verbatim}
█ █ █ █ █ ↓ █ █ █ █ █ █ █ █ █ █ █
█ └ → ┐ █
\end{verbatim}
\end{document}
答案3
在 pdflatex 中工作。在组中,我\verbarrows
在 之前调用verbatim
,重新定义\leftarrow
和\rightarrow
以适应 的空间X
。当在 verbatim 环境中遇到时,箭头将适合 的大小\ttfamily X
。
\documentclass[11pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage[spanish]{babel}
\let\svrightarrow\rightarrow
\let\svleftarrow\rightarrow
\def\verbarrows{%
\def\rightarrow{\setbox0=\hbox{X}\makebox[\wd0]{$\svrightarrow$}}%
\def\leftarrow{\setbox0=\hbox{X}\makebox[\wd0]{$\svleftarrow$}}%
}
\begin{document}\shorthandoff{>}\shorthandoff{<}
\bgroup\verbarrows%
\begin{verbatim}
# # # # # ↓ # # # # # # # # # # #
# → → ↓ #
# # ↓ # #
# # → ↓ # #
# # # # # # ↓ # # # # #
# ↓ ← # #
# ↓ # #
# ↓ # # # # # #
# → → → → → → → ↓ #
# # # # # → ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # # # # # → → #
# # # # #
# # # #
# # # #
# # # # # # # # # # # # # # # # #
\end{verbatim}
\egroup
\end{document}
切换到verbatimbox
包可以简化调用并使其更加通用:
\documentclass[11pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage[spanish]{babel}
\let\svrightarrow\rightarrow
\let\svleftarrow\rightarrow
\def\verbarrows{%
\def\rightarrow{\setbox0=\hbox{X}\makebox[\wd0]{$\svrightarrow$}}%
\def\leftarrow{\setbox0=\hbox{X}\makebox[\wd0]{$\svleftarrow$}}%
}
\usepackage{verbatimbox}
\begin{document}\shorthandoff{>}\shorthandoff{<}
\begin{verbnobox}[\verbarrows]
# # # # # ↓ # # # # # # # # # # #
# → → ↓ #
# # ↓ # #
# # → ↓ # #
# # # # # # ↓ # # # # #
# ↓ ← # #
# ↓ # #
# ↓ # # # # # #
# → → → → → → → ↓ #
# # # # # → ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # # # # # → → #
# # # # #
# # # #
# # # #
# # # # # # # # # # # # # # # # #
\end{verbnobox}
\begin{verbnobox}[\tiny\verbarrows]
# # # # # ↓ # # # # # # # # # # #
# → → ↓ #
# # ↓ # #
# # → ↓ # #
# # # # # # ↓ # # # # #
# ↓ ← # #
# ↓ # #
# ↓ # # # # # #
# → → → → → → → ↓ #
# # # # # → ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # ↓ #
# # # # # # # → → #
# # # # #
# # # #
# # # #
# # # # # # # # # # # # # # # # #
\end{verbnobox}
\end{document}
答案4
正如@Ulrike 所说,使用 lualatex 或 xelatex 可以解决此特定情况下的问题。但是,如果您想使用除箭头之外的 unicode 字符,您可能会遇到麻烦。我确实遇到了麻烦,放弃了,并使用了图像。