
회색 상자 안에 URL과 기타 경로를 인쇄하려고 합니다. 그러나 나는 그렇게 할 수 없습니다. \colorbox
와 함께 사용하는 순간 \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에 대한 지식이 전혀 없기 때문에 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}