TransWikia.com

Label placement on a tikzcd "to path" arrow

TeX - LaTeX Asked on August 11, 2021

I am using to path in order to have a better control of an arrow in a tikzcd diagram. However, I am having trouble to placement the label.

With this code

documentclass{article}
usepackage{tikz-cd}

begin{document}
begin{tikzcd}[labels=description, column sep=3cm]
  Aarrow["a+b",sloped,rounded corners,
  to path={
    -| ([yshift=-1.5cm,xshift=-.7cm]tikztostart.west)
    -| ([xshift=.7cm]tikztotarget.east)tikztonodes
    -- (tikztotarget)} ]{r}
  & B  C &  D
end{tikzcd}
end{document}

I get this
enter image description here

Moving the tikztonode instruction to the first segment:

documentclass{article}
usepackage{tikz-cd}

begin{document}
begin{tikzcd}[labels=description, column sep=3cm]
  Aarrow["a+b",sloped,rounded corners,
  to path={
    -| ([yshift=-1.5cm,xshift=-.7cm]tikztostart.west)tikztonodes
    -| ([xshift=.7cm]tikztotarget.east)
    -- (tikztotarget)} ]{r}
  & B  C &  D
end{tikzcd}
end{document}

I get this

enter image description here

Finally, in the last segment:

documentclass{article}
usepackage{tikz-cd}

begin{document}
begin{tikzcd}[labels=description, column sep=3cm]
  Aarrow["a+b",sloped,rounded corners,
  to path={
    -| ([yshift=-1.5cm,xshift=-.7cm]tikztostart.west)
    -| ([xshift=.7cm]tikztotarget.east)
    -- (tikztotarget)tikztonodes} ]{r}
  & B  C &  D
end{tikzcd}
end{document}

I get this

enter image description here

How do I make it appear in the long horizontal segment at the bottom?

One Answer

New answer: without changing the construction of the path.

By default, nodes have the option pos initialized implicitly. It is enough here to initialize to [pos=0.25].

documentclass{article}
usepackage{tikz-cd}

begin{document}
begin{tikzcd}[labels=description, column sep=3cm]
  Aarrow["a+b",rounded corners,
  to path={[pos=0.25]
    -| ([yshift=-1.5cm,xshift=-.7cm]tikztostart.west)
    -| ([xshift=.7cm]tikztotarget.east)tikztonodes
    -- (tikztotarget)} ]{r}
  & B  C &  D
end{tikzcd}
end{document}

Old answer: by modifying the construction of the path.

screenshot

documentclass[border=5mm]{standalone}
usepackage{tikz-cd}

begin{document}
begin{tikzcd}[labels=description, column sep=3cm]
  Aarrow["a+b",rounded corners,
  to path={
    -| ([yshift=-1.5cm,xshift=-.7cm]tikztostart.west)
    -- ([yshift=-1.5cm,xshift=.7cm]tikztotarget.east)tikztonodes
    |- (tikztotarget)} ]{r}
  & B  C &  D
end{tikzcd}
end{document}

Correct answer by AndréC on August 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP