Hyperref、tikz 节点和下划线错位

Hyperref、tikz 节点和下划线错位

对于Tikz节点,下划线会发生偏移。我使用lualatex。请参阅我的相关问题:pdflatex 与 lualatex 下划线之谜

在此处输入图片描述

\documentclass[french]{article}
\usepackage{xcolor,hyperref,tikz}

\hypersetup{%
    colorlinks=true,
    urlcolor=blue,
    urlbordercolor=blue}

\AtBeginDocument{\hypersetup{pdfborderstyle={/S/U/W .6pt}}}

\tikzset{RndBox/.style args={#1 and #2}{%
    thick,
    fill=#1,
    inner sep=0pt,
%   outer sep=0pt,
    draw=#2,
    text=#2,
    rounded corners=2pt,
    minimum width=.6cm,
    minimum height=1.25em,
    text depth = 0ex,
    font = \bfseries\sffamily
    },
    RndBox/.default={gray!25 and black}
}

\begin{document}

\href{%
    https://studio.code.org/s/course3/stage/2/puzzle/1}{%
    \smash{Labyrinthe}} un lien

\medskip

\tikz[anchor=base, baseline]
    \node[RndBox,minimum width=20pt] {C} ;
\href{%
    https://studio.code.org/s/course3/stage/2/puzzle/1}{%
    \smash{Labyrinthe}} un lien

\end{document}

答案1

在这种情况下,您可以精确地知道节点的宽度。这表明

\documentclass[french]{article}
\usepackage{xcolor,hyperref,tikz}
\usetikzlibrary{positioning}
\hypersetup{%
    colorlinks=true,
    urlcolor=blue,
    urlbordercolor=blue}

\AtBeginDocument{\hypersetup{pdfborderstyle={/S/U/W .6}}}

\tikzset{RndBox/.style args={#1 and #2}{%
    thick,
    fill=#1,
    inner sep=0pt,
%   outer sep=0pt,
    draw=#2,
    text=#2,
    rounded corners=2pt,
    minimum width=.6cm,
    minimum height=1.25em,
    text depth = 0ex,
    font = \bfseries\sffamily
    },
    RndBox/.default={gray!25 and black}
}

\begin{document}

\href{%
    https://studio.code.org/s/course3/stage/2/puzzle/1}{%
    \smash{Labyrinthe}} un lien

\medskip

\makebox[20pt]{\tikz[anchor=base, baseline,overlay]{
    \node[RndBox,minimum width=20pt] (C) {C} ;}}
\href{%
    https://studio.code.org/s/course3/stage/2/puzzle/1}{%
    \smash{Labyrinthe}} 
    un lien

\end{document}

在此处输入图片描述

在这里,我实施了 Ulrike 对您的其他问题的评论以及 percusse 的建议。

相关内容