6

When trying to create a table using tabulary as:

 \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}

the table entries that are hyperlinks show up as being aligned with the bottom of the cell such that they're offset from the other text in the same row (i.e. DEF is above ABC_DEF in the table). When I remove the hyperlinks, however, the text in the rows are all aligned.

Is there any way I can use hyperlinks in a 'C' column of tabulary and maintain vertical alignment?

David Carlisle
  • 757,742

1 Answers1

5

But the text is aligned; the boxes from the hyperlinks extend downwards, but the vertical position of the text remains unaltered, as can be seen with some auxiliary lines:

\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}

enter image description here

Perhaps you could suppress the hyperlink boxes using some of the hyperref options, as in, for example, \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}

enter image description here

If you want to keep the boxes, but making them tighter, you can use Heiko Oberdiek's suggestions in his answer to \ref with tight box surrounding the reference:

\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}

enter image description here

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128