2

The title is self-explanatory. I want to introduce line breaks in TikZ nodes when the text is an hyperref, an e-mail address in this case.

I know I can introduce line breaks in nodes using the align option and \\, but when the text hyperref, this gives an error.

I have tried the text width option, but that produces underfull warnings in many cases I have, and I cannot solve it...

This is my MWE:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{calc,positioning}

\usepackage{hyperref}

\hypersetup{pdfborder = {0 0 0}}


\begin{document}

\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0, fill=yellow}]
\node[anchor=east, align=right] (A) at (0,0) {I can split normal text\\
    into two lines};

\node[below=1cm of A.south east, anchor=north east] (B) {\href{mailto:complete\_name@longaddress.com}{complete\_name@longaddress.com}};%I WANT TO SPLIT THIS TOO, AFTER THE @

\node[below=1cm of B.south east, anchor=north east] (C) {\href{mailto:name@longaddress.com}{name@longaddress.com}};%AND THIS IN THE SAME WAY

%\node[below=1cm of C.south east, anchor=south east, align=right] (D) {\href{mailto:complete\_name@longaddress.com}{complete\_name\\
%@longaddress.com}}; %IF I USE align=right AND \\ AS ABOVE, I GET ERROR

\node[below=1cm of C.south east, anchor=north east, text width=2.8cm, align=right] (D) {\href{mailto:complete\_name@longaddress.com}{complete\_name\\
        @longaddress.com}}; %WITH text width WORKS OK FOR THIS CASE, BUT FOR OTHERS I GET UNDERFULL

\node[below=1cm of D.south east, anchor=north east, text width=2.8cm, align=right] (E) {\href{mailto:name@longaddress.com}{name\\
        @longaddress.com}};%UNDERFULL, IS THERE A WAY I CAN SPLIT THIS TEXT WITHOUT WARNINGS?


\end{tikzpicture}


\end{document}

It produces the desired visual output, but with an UNDERFULL warning in the last node that I want to get rid of. Any advice?

fig1

Werner
  • 603,163
DaniCee
  • 2,217

1 Answers1

4

Set the displayed text inside a tabular, as suggested in Manual/automatic line breaks and text alignment in TikZ nodes:

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\usepackage{hyperref}
\hypersetup{pdfborder = {0 0 0}}

\begin{document}

\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0, fill=yellow}]
  \node[anchor=east, align=right] (A) at (0,0) {I can split normal text \\
    into two lines};

  \node[below=1cm of A.south east, anchor=north east] (B) 
    {\href{mailto:complete\_name@longaddress.com}{%
      \begin{tabular}{@{}l@{}}
        complete\_name@ \\
        longaddress.com
      \end{tabular}}};

\end{tikzpicture}

\end{document}

You can modify the column specification to obtain a different alignment.

Werner
  • 603,163