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?

4
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

7
  • Nice! Ugly red frames I would say. Is it possible to do it closer?
    – Sigur
    Oct 16 '12 at 1:36
  • 1
    @Sigur what do you mean? Do you mean to have the boxes tighter? Oct 16 '12 at 1:40
  • Yes, like \fbox.
    – Sigur
    Oct 16 '12 at 1:41
  • 1
    @Sigur one can use \hypersetup{pdflinkmargin=0pt} (see tex.stackexchange.com/a/77595/3954) but if the surrounding boxes have descenders the hyperlink boxes will still have depth. Oct 16 '12 at 1:45
  • 1
    @Sigur please see the last example in my updated answer. Oct 16 '12 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.