这是“http://” 中的两个斜线之间的空格太大. Bianca Lobo 的回答(使用适当的字距调整定义命令)很好;但是,它在命令的\twobar
参数中不起作用\url
包裹同名。使用时如何减少两个斜线之间的间距\url
?(我对无衬线字体和罗马字体的解决方案感兴趣。)
\documentclass{article}
\usepackage{url}
\newcommand{\twobar}{/\kern-0.2em/}
\begin{document}
\sffamily
\urlstyle{sf}
http:\twobar www.tex.stackexchange.com
\url{http://www.tex.stackexchange.com}
\url{http:\twobar www.tex.stackexchange.com}
\bigskip
\rmfamily
\urlstyle{rm}
http:\twobar www.tex.stackexchange.com
\url{http://www.tex.stackexchange.com}
\url{http:\twobar www.tex.stackexchange.com}
\end{document}
答案1
该url
包提供了一种在 URL 字符串中进行搜索和替换的方法。请参阅自文档化的代码。我们对其进行了调整,因为它在正确的位置\Url@acthash
被调用。\url
\documentclass{article}
\pagestyle{empty}
\usepackage{url}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\makeatletter
% nice "//"
\newcommand{\twobar}{/\kern-0.2em/}
% store original \Url@acthash
\let\orig@Url@acthash\Url@acthash
% make new \Url@acthash that acts "//" as well
\let\new@Url@acthash\Url@acthash
\g@addto@macro{\new@Url@acthash}{\Url@Edit\Url@String{//}{\twobar}}
% make \urlstyle use the original \Url@acthash
\let\orig@urlstyle\urlstyle
\def\urlstyle{\let\Url@acthash\orig@Url@acthash\orig@urlstyle}
% make selected url styles use the new \Url@acthash
\g@addto@macro{\url@rmstyle}{\let\Url@acthash\new@Url@acthash}
\g@addto@macro{\url@sfstyle}{\let\Url@acthash\new@Url@acthash}
\makeatother
\begin{document}
\sffamily
\urlstyle{sf}
http:\twobar www.tex.stackexchange.com
\par
\url{http://www.tex.stackexchange.com}
\par
\url{http:\twobar www.tex.stackexchange.com}
\bigskip
\ttfamily
\urlstyle{tt}
http:\twobar www.tex.stackexchange.com
\par
\url{http://www.tex.stackexchange.com}
\par
\url{http:\twobar www.tex.stackexchange.com}
\bigskip
\rmfamily
\urlstyle{rm}
http:\twobar www.tex.stackexchange.com
\par
\url{http://www.tex.stackexchange.com}
\par
\url{http:\twobar www.tex.stackexchange.com}
\bigskip
\end{document}
答案2
为斜线定义特殊行为:
\documentclass{article}
\usepackage{url}
\makeatletter
\def\Url@twoslashes{\mathchar`\/\@ifnextchar/{\kern-.2em}{}}
\g@addto@macro\UrlSpecials{\do\/{\Url@twoslashes}}
\makeatother
\begin{document}
\urlstyle{sf}\url{http://tex.stackexchange.com/4427}
\bigskip
\urlstyle{rm}\url{http://tex.stackexchange.com}
\bigskip
\urlstyle{tt}\url{http://tex.stackexchange.com}
\end{document}
避免字距调整的更复杂的定义tt
是
\def\Url@twoslashes{%
\mathchar`\/% print a slash
\expandafter\ifx\UrlFont\ttfamily
\expandafter\@gobble % do nothing if style is tt
\else
\expandafter\@firstofone % check if a / follows and insert a kern
\fi
{\@ifnextchar/{\kern-.2em}{}}
}
\UrlFonts
如果对某些新风格做出愚蠢的定义,则并非完全万无一失。