5

I would like to draw a double-lined arc with an arrow at its end. It works perfectly well with a single line. Things are going south when I want to use a double lined arc.

Here is my MWE:

\documentclass[]{article}

\usepackage[a4paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes}
\usetikzlibrary{bending}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}

\usepackage{adjustbox}
\usepackage{graphicx}

\makeatletter

\def\anchor@sep{0.05}
\newsavebox{\my@scalebox}

\newcommand\glyph{%
  \begin{lrbox}{\my@scalebox}
    \begin{adjustbox}{raise=-0.5ex}
      \begin{tikzpicture}[draw]
        \begin{scope}
          \draw [border box] (0,0) -- (0,1) -- (1,1) -- (1,0) --  cycle;
          \node [anchors] (DL) at ({0.5/3 + \anchor@sep},{0.5/3 + \anchor@sep}) {};
          \node [anchors] (DM) at ({1.5/3},{0.5/3 + \anchor@sep}) {};
          \node [anchors] (DR) at ({2.5/3 - \anchor@sep},{0.5/3 + \anchor@sep}) {};
          %
          \node [anchors] (ML) at ({0.5/3 + \anchor@sep},{1.5/3}) {};
          \node [anchors] (MM) at ({1.5/3},{1.5/3}) {};
          \node [anchors] (MR) at ({2.5/3 - \anchor@sep},{1.5/3}) {};
          \node [anchors] (UL) at ({0.5/3 + \anchor@sep},{2.5/3 - \anchor@sep}) {};
          \node [anchors] (UM) at ({1.5/3},{2.5/3 - \anchor@sep}) {};
          \node [anchors] (UR) at ({2.5/3 - \anchor@sep},{2.5/3 - \anchor@sep}) {};
          \draw[mal] ([shift=(-60:.35)]MM) arc (-60:241:.35);
        \end{scope}
      \end{tikzpicture}
    \end{adjustbox}
  \end{lrbox}
  \scalebox{0.5}{\usebox{\my@scalebox}}
  \scalebox{1}{\usebox{\my@scalebox}}
  \scalebox{3}{\usebox{\my@scalebox}}
}

\makeatother

\begin{document}


\tikzset{%
  mal/.style={-{Latex[bend]},
    line width=1pt,
  },
  border box/.style = {line width=0.75pt, rounded corners=3pt},
  anchors/.style = { draw, line width=0.1pt },
}

Correct (single line):
\glyph

\tikzset{%
  mal/.append style = { double}
}

Boggus with 2 lines:
\glyph


\end{document}

Did I miss something?

enter image description here

1

I started by minimising your example. As far as I can tell, the problem is basically to draw a tightly curved, double line with an arrow, using a macro which also works for a single line.

My first thought was to draw the second line of the double manually, rather than having TikZ do it. (All double does is draw 2 lines - one thicker and then one thinner.)

Unfortunately, TikZ goes a bit crazy trying to do this and it is possible to persuade it to draw lines going off at seemingly random angles for no readily apparent reason.

So, using a brute force approach, I tried adding a second curve to my testing macro and set up a separate style for this. When the style is draw=none, the macro does exactly the same as the original. However, when it is passed keys, it draws another curve.

However, this isn't quite enough because where the curve should end varies with the details of the line width etc. So, I added a key to set the end angle and, for good measure, the start angle as well.

Here's the result

angled arrow on fake double line

If you don't want the white middle, you can play around removing the open key from the tip specification, of course.

Here's the code:

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{arrows.meta,bending}
\newcommand*\mymal{\tikz{%
    \draw [mal] (-60:.35) arc (-60:241:.35);
    \draw [mel] (-60:.35) arc (\melstartangle:\melstopangle:.35);
  }%
}
\begin{document}
\tikzset{%
  mal/.style={%
    -{Latex[bend]},
    line width=1pt,
  },
  mel/.style={draw=none},
  mel start angle/.store in=\melstartangle,
  mel stop angle/.store in=\melstopangle,
  mel angles/.code args={#1:#2}{%
    \tikzset{%
      mel start angle=#1,
      mel stop angle=#2,
    }%
  },
  mel angles=-60:241,
}
\mymal

\tikzset{%
  mal/.append style={line width=2.5pt, -{Latex[bend,fill=white]} },
  mel/.append style={line width=.75pt, draw=white},
  mel angles=-60:175
}
\mymal
\end{document}
| improve this answer | |
  • Ok thanks thus IIUC this is more related to a tikz issue. I'll try your solution to see if I can handle both single and doubled lined curves. – renard Aug 14 '16 at 22:13
  • @renard I tested it for both. Default assumes single (draw=none for the second style). – cfr Aug 15 '16 at 1:11
  • No idea what IIUC means. (If I understand correctly?) – cfr Aug 15 '16 at 1:11

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.