單獨為超連結著色

單獨為超連結著色

如何單獨設定超連結的顏色?目前它周圍有一個紅色框。

\href{www.google.com}{Test}

我怎麼才能選擇它的顏色?喜歡

\href{www.google.com}{Test}{boxcolor=blue}

我還有許多其他框要放置不同的顏色,因此我寧願重複輸入一個簡短的白痴友好方法,然後重新定義函數定義。

答案1

您可以使用{\color{<color>}\url{<url>}}\href{<url>}{\color{<color>}<text>}。宏只能簡單一點:

\documentclass{article}
\usepackage{xcolor}
\usepackage[hidelinks]{hyperref}
\newcommand\colorlink[3]{\href{#2}{\color{#1}#3}}
\newcommand\colorurl[2]{{\color{#1}\url{#2}}}
\linespread{1.3}

\begin{document}

\obeylines

\href{http://www.example.com}{www.example.com} 
\colorlink{purple}{http://www.example.com}{www.example.com}  
\colorlink{violet}{http://www.example.com}{www.example.com}{blue}   
\colorlink{blue}{http://www.example.com}{www.example.com}{cyan}  

\bigskip

\url{http://www.example.com}
\colorurl{purple}{http://www.example.com}
\colorurl{violet}{http://www.example.com}
\colorurl{blue}{http://www.example.com}

\end{document}

在奇怪的情況下,您想要連結框而不是彩色文本,請刪除與該框不相容的任何包選項(例如 colorlinkshidelinks),然後使用類似以下內容的選項:

\hypersetup{urlbordercolor=orange} 
\url{http://www.example.com}
\hypersetup{urlbordercolor=cyan}   % return to default color

相關內容