边缘的中间标签

边缘的中间标签

我想在虚线箭头旁边添加中间标签。有什么想法吗?

在此处输入图片描述

%%%%%%%%%%%%%%%%%% 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}

谢谢您的帮助!

答案1

您几乎已经完成了节点TEST2,您只需将其移动node最后一个坐标。也就是说,

(a) edge (b) node {foo}

你做

(a) edge  node {foo} (b)

如果希望标签与边缘平行,请使用

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

如果添加,还有一个更短的语法可用\usetikzlibrary{quotes},那就是

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

在代码中使用第一个语法:

在此处输入图片描述

\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}

答案2

使用以下方式编译渐近线

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);

在此处输入图片描述

相关内容