4

I would like to add midway label next to the dashed arrow. any idea how to do so?

enter image description here

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}
%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre
%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)
\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_figlab}
%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{fig2D/.style={font={\sansmath\sffamily\Large}, line width=0.4mm, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm,}}

%%%%%%%%%%%%%%%%%%%%%%%% DOTTED TRIANGLOID %%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{pics/dotted triangloid/.style={code={%
    \tikzset{dotted triangloid/.cd,#1}%
    \def\pv##1{\pgfkeysvalueof{/tikz/dotted triangloid/##1}}
    \draw [solid, pic actions, fill=\pv{fill}]
    %%  point o - bas gauche
    (0,0) coordinate (o)
    node [circle, fill=black, scale=0.5, label={[below, inner sep=\pv{inner sep}, shift={(-2pt,-6pt)}]\pv{labo}}] {}
    %% point a - bas droite
    (\pv{scale}*\pv{width},0) coordinate (a)
    node [circle, fill=black, scale=0.5, label={[below, inner sep=\pv{inner sep}, shift={(0pt,-6pt)}]\pv{laba}}] {}
    %% point b - sommet
    ({\pv{scale}*\pv{offset})},\pv{scale}*\pv{height}) coordinate (b)
    node [circle, fill=black, scale=0.5, label={[above, inner sep=\pv{inner sep},]\pv{labb}}] {}
    %% jonction entre les points
     (o) 
     -- (a) 
     node [midway, label={[below, inner sep=\pv{inner sep},shift={(0pt,-6pt)}]\pv{labA}}] {}
     -- (b)
     node [midway, label={[above right, inner sep=\pv{inner sep},]\pv{labB}}] {}
     -- (o)
     node [midway, label={[above left, inner sep=\pv{inner sep},,shift={(-2pt,0pt)}]\pv{labC}}] {}
     ;
  }},
  dotted triangloid/.cd,
  width/.initial=5,
  height/.initial=2,
  offset/.initial=0,
  labA/.initial=,
  labB/.initial=,
  labC/.initial=,
  labo/.initial=,
  laba/.initial=,
  labb/.initial=,
  inner sep/.initial=0pt,
  fill/.initial=black!0,
  scale/.initial=1,
}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[fig2D]

\pic {dotted triangloid={width=8.82, height=6.47, offset=2.35, labo=B, laba=C, labb=A, fill= orange!20}};

\path
    (o) -- (b) node [circle, pos=0.333, fill=black, scale=0.5, label=left: D] (d) {}
    (a) -- (b) node [circle, pos=0.333, fill=black, scale=0.5, label=above right: E] (e) {}
;
\draw
    (d) -- (e)
    (o) +(-6pt, 0) coordinate (o')
    (b) +(-6pt, 0) coordinate (b')
    (b) +(6pt, 0) coordinate (b'')
    (d) +(-6pt, -3pt) coordinate (d')
    (d) +(-6pt, 3pt) coordinate (d'')
    (o') edge[<->, densely dashed, label={[left]TEST 1}] (d') node [midway]{TEST2}
    (d'') edge[<->, densely dashed, label={[left]TEST 3}] (b')
;

\end{tikzpicture}
\end{document}

Thanks for the help!

1
  • 1
    Quick try: node [midway, above]{TEST2}.
    – FHZ
    Apr 14, 2020 at 17:00

2 Answers 2

3

You're almost there with the TEST2 node, you just need to move the node to before the last coordinate. That is, instead of

(a) edge (b) node {foo}

you do

(a) edge  node {foo} (b)

If you want the label parallel to the edge, use

(a) edge  node[sloped,above] {foo} (b)

There is also a shorter syntax available if you add \usetikzlibrary{quotes}, and that is

(a) edge["foo"sloped] (b)

Using the first syntax in your code:

enter image description here

\documentclass[border=10pt]{standalone}
%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre
%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)
\usepackage{xcolor}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}

%\input{types/f2d_figlab}
%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\tikzset{fig2D/.style={font={\sansmath\sffamily\Large}, line width=0.4mm, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm,}}

%%%%%%%%%%%%%%%%%%%%%%%% DOTTED TRIANGLOID %%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{pics/dotted triangloid/.style={code={%
    \tikzset{dotted triangloid/.cd,#1}%
    \def\pv##1{\pgfkeysvalueof{/tikz/dotted triangloid/##1}}
    \draw [solid, pic actions, fill=\pv{fill}]
    %%  point o - bas gauche
    (0,0) coordinate (o)
    node [circle, fill=black, scale=0.5, label={[below, inner sep=\pv{inner sep}, shift={(-2pt,-6pt)}]\pv{labo}}] {}
    %% point a - bas droite
    (\pv{scale}*\pv{width},0) coordinate (a)
    node [circle, fill=black, scale=0.5, label={[below, inner sep=\pv{inner sep}, shift={(0pt,-6pt)}]\pv{laba}}] {}
    %% point b - sommet
    ({\pv{scale}*\pv{offset})},\pv{scale}*\pv{height}) coordinate (b)
    node [circle, fill=black, scale=0.5, label={[above, inner sep=\pv{inner sep},]\pv{labb}}] {}
    %% jonction entre les points
     (o) 
     -- (a) 
     node [midway, label={[below, inner sep=\pv{inner sep},shift={(0pt,-6pt)}]\pv{labA}}] {}
     -- (b)
     node [midway, label={[above right, inner sep=\pv{inner sep},]\pv{labB}}] {}
     -- (o)
     node [midway, label={[above left, inner sep=\pv{inner sep},,shift={(-2pt,0pt)}]\pv{labC}}] {}
     ;
  }},
  dotted triangloid/.cd,
  width/.initial=5,
  height/.initial=2,
  offset/.initial=0,
  labA/.initial=,
  labB/.initial=,
  labC/.initial=,
  labo/.initial=,
  laba/.initial=,
  labb/.initial=,
  inner sep/.initial=0pt,
  fill/.initial=black!0,
  scale/.initial=1,
}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[fig2D]

\pic {dotted triangloid={width=8.82, height=6.47, offset=2.35, labo=B, laba=C, labb=A, fill= orange!20}};

\path
    (o) -- (b) node [circle, pos=0.333, fill=black, scale=0.5, label=left: D] (d) {}
    (a) -- (b) node [circle, pos=0.333, fill=black, scale=0.5, label=above right: E] (e) {}
;
\draw
    (d) -- (e)
    (o) +(-6pt, 0) coordinate (o')
    (b) +(-6pt, 0) coordinate (b')
    (b) +(6pt, 0) coordinate (b'')
    (d) +(-6pt, -3pt) coordinate (d')
    (d) +(-6pt, 3pt) coordinate (d'')
    (o') edge[<->, densely dashed] node [sloped,above] {bar} (d') 
    (d'') edge[<->, densely dashed] node [sloped,above] {foo} (b')
;

\end{tikzpicture}
\end{document}
1
  • thank you very much!
    – Nilcouv
    Apr 15, 2020 at 7:48
2

Compile with Asymptote.

size(300);
unitsize(1cm);

pair A=(0,0),B=4*dir(80),C=(5,0);
pair D=A+0.3*(B-A),E=C+0.3*(B-C);

real distance=.3;
pair D1=D+distance*dir(degrees(B-D)+90),
     B1=B+distance*dir(degrees(B-D)+90),
     D2=D+.2*dir(degrees(B-D)+90),
     A1=A+.2*dir(degrees(D-A)+90);
draw(A--B--C--cycle);
draw("TEST2",D--E);
draw(rotate(degrees(B-D))*Label("TEST1",align=(0,0),UnFill),B1--D1,dashed,Arrows());
draw(rotate(degrees(D-A))*"TEST3",D2--A1,dashed,Arrows());
// OR
// draw(Label("TEST1",Rotate(-dir(B1--D1)),align=(0,0),UnFill),B1--D1,dashed,Arrows());
// draw(Label("TEST3",Rotate(dir(A1--D2))),D2--A1,dashed,Arrows());
label("$A$",A,dir(-135));
label("$B$",B,dir(90));
label("$C$",C,dir(-45));
dot(D^^E);

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .