
我正在嘗試在灰色框中列印 URL 和其他路徑。但是,我不能這樣做。當我使用\colorbox
with時\path
,換行符就停止工作了。看起來好像\colorbox
停\path
在了斷線處;\color
沒有。
有辦法糾正嗎?
我嘗試通讀,url.sty
但我對 LaTeX 的有限理解無法解讀它。我嘗試過一遍\path
和的定義\colorbox
。雖然不太明白。
\path:
macro:->\leavevmode \begingroup \urlstyle {tt}\Url
\colorbox:
macro:#1{->\protect \color@box {#1}{
\color@box {#1}{:
undefined
這是兩個相關(可能)但不同的問題
這是我的 MWE
\documentclass{article}
\usepackage{letltxmacro}
\usepackage[obeyspaces]{xcolor}
\usepackage[obeyspaces]{url}
\usepackage{etoolbox}
\LetLtxMacro{\oldpath}{\path}
\renewcommand{\path}[1]{{\colorbox{gray!8}{\oldpath{#1}}}}
\newrobustcmd\pathcb[1]{\colorbox{gray!8}{\path{#1}}}
\begin{document}
\colorbox{gray!7}{\parbox{\dimexpr\linewidth-2\fboxsep}{\strut \path{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verbhttps://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}\strut}}
\pathcb{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verbhttps://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
\path{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verbhttps://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
\end{document}
我試過沃納對易碎彩盒的回答但線還是不會斷。我寧願避免使用 TiKz,因為我對它一無所知。
如果我可以提供更多詳細信息,請告訴我。
答案1
命令如\url
和\path
不吸收他們的論點,但要延遲這樣做,以便在兩者之間做出一些設定。
新增顏色作為字體屬性:
\documentclass{article}
\usepackage{xcolor}
\usepackage[obeyspaces]{url}
\usepackage{etoolbox}
\appto{\UrlFont}{\color{gray!70}}
\begin{document}
Some text for triggering a line break
\url{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
\url{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
and some text after the links
\end{document}