表格内的超链接垂直对齐

表格内的超链接垂直对齐

当尝试使用以下命令创建表时tabulary

 \documentclass{article}

\usepackage{booktabs}
\usepackage{tabulary}
\usepackage{hyperref}

\begin{document}

  \begin{tabulary}{6in}{rCJ}
    \toprule
    \textbf{Thing} & \textbf{Another} & \textbf{Thing} \\
    \midrule
    DEF & \hyperlink{def:ABC_DEF}{\texttt{ABC\_DEF}} & Some letters going on over here. \\
    GHIJKL & \hyperlink{def:ABC_GHI}{\texttt{ABC\_GHI}} \hyperlink{def:ABC_JKL}{\texttt{ABC\_JKL}} & This box has enough text inside of it to do some word wrapping I should hope, as that's what happens in my table. \\
    \bottomrule
  \end{tabulary}

\end{document}

作为超链接的表格条目显示为与单元格底部对齐,这样它们就会与同一行中的其他文本偏移(即在表格DEF上方)。但是,当我删除 s 时,行中的文本全部对齐。ABC_DEFhyperlink

有什么方法可以在“C”列中使用超链接tabulary并保持垂直对齐?

答案1

但文本是对齐的;超链接的框向下延伸,但文本的垂直位置保持不变,如通过一些辅助线可以看出:

\documentclass{article}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{hyperref}

\usepackage{tikz}

\begin{document}

  \begin{tabulary}{6in}{rCJ}
    \toprule
    \textbf{Thing} & \textbf{Another} & \textbf{Thing} \\
    \midrule
    DEF & \hyperlink{def:ABC_DEF}{\texttt{ABC\_DEF}} & Some letters going on over here. \\
    GHIJKL & \hyperlink{def:ABC_GHI}{\texttt{ABC\_GHI}} \hyperlink{def:ABC_JKL}{\texttt{ABC\_JKL}} & This box has enough text inside of it to do some word wrapping I should hope, as that's what happens in my table. \\
    \bottomrule
  \end{tabulary}

\begin{tikzpicture}[remember picture,overlay]
\draw[blue] (0,31.5pt)  -- +(\textwidth,0);
\draw[blue] (0,19.3pt)  -- +(\textwidth,0);
\draw[blue] (0,8pt)  -- +(\textwidth,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

也许您可以使用某些选项来隐藏超链接框hyperref,例如\usepackage[colorlinks]{hyperref}

\documentclass{article}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage[colorlinks,linkcolor=cyan]{hyperref}

\begin{document}

  \begin{tabulary}{6in}{rCJ}
    \toprule
    \textbf{Thing} & \textbf{Another} & \textbf{Thing} \\
    \midrule
    DEF & \hyperlink{def:ABC_DEF}{\texttt{ABC\_DEF}} & Some letters going on over here. \\
    GHIJKL & \hyperlink{def:ABC_GHI}{\texttt{ABC\_GHI}} \hyperlink{def:ABC_JKL}{\texttt{ABC\_JKL}} & This box has enough text inside of it to do some word wrapping I should hope, as that's what happens in my table. \\
    \bottomrule
  \end{tabulary}

\end{document}

在此处输入图片描述

如果你想保留盒子,但让它们更紧密,你可以使用海科·奥伯迪克的建议他的回答\ref 用紧密的方框围绕引用

\documentclass{article}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{hyperref}


\begin{document}

\hypersetup{pdflinkmargin=0pt}
  \begin{tabulary}{6in}{rCJ}
    \toprule
    \textbf{Thing} & \textbf{Another} & \textbf{Thing} \\
    \midrule
    DEF & \mbox{\hyperlink{def:ABC_DEF}{\texttt{ABC\_DEF}}} & Some letters going on over here. \\
    GHIJKL & \hyperlink{def:ABC_GHI}{\texttt{ABC\_GHI}} \mbox{\hyperlink{def:ABC_JKL}{\texttt{ABC\_JKL}}} & This box has enough text inside of it to do some word wrapping I should hope, as that's what happens in my table. \\
    \bottomrule
  \end{tabulary}

\end{document}

在此处输入图片描述

相关内容