2

Im struggling with the options in tikz to get straight lines instead of curved lines, when im linking A to B (see picture below).

Here is my mwe:

\documentclass{article}
\usepackage{pgf,tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\mathtikzmark}[2]{\tikz[baseline={(#1.base)},remember picture] \node[inner sep=0pt] (#1) {#2};}
\usepackage{xparse}
\DeclareDocumentCommand{\link}{ O{shorten >=4pt,shorten <=4pt} O{} O{above} m m}{
    \begin{tikzpicture}[remember picture, overlay, >=stealth, shift={(0,0)}]
        \draw[#1,->] (#4) to node[#3] {#2} (#5) ;
    \end{tikzpicture}%
}
%-----------------------------------------------------------------------------------------------

\begin{document}

\hspace*{40mm}f(x) = x + \mathtikzmark{B}{3}

\fcolorbox{red}{white}{\mathtikzmark{A}{Attention: blabla}}

\link[shorten >=1.mm,shorten <=1.mm,out=0,in=270,black]{A}{B} \end{document}

I get this:

enter image description here

What im trying to get is this:

enter image description here

Anyone knows how to setup the options?

1 Answers1

3

Normally, to draw such a line, one would use (a) -| (b) (see https://tex.stackexchange.com/a/401429/), but that wouldn't work when you're using to in a macro like that.

However, you could modify how to draws the line, by adding

to path={(\tikztostart) -|  (\tikztotarget)}

to the options of \link. I.e.

\link[shorten >=1.mm,shorten <=1.mm,black, to path={(\tikztostart) -|  (\tikztotarget)}]{A}{B}

enter image description here

Torbjørn T.
  • 206,688