8

I want this layout but I can't control the placement of s1, s2 and s3. How do I achieve this. My MWE follows.

enter image description here

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[ht]
  \centering
  \begin{tikzpicture}
    \coordinate (Origin)   at (0,0);
    \coordinate (XAxisMin) at (-2.0,0);
    \coordinate (XAxisMax) at (2.0,0);
    \coordinate (YAxisMin) at (0,-2.2);
    \coordinate (YAxisMax) at (0,2.2);
    \draw  (XAxisMin) -- (XAxisMax);
    \draw  (YAxisMin) -- (YAxisMax);
    \coordinate (P1) at (-2,-2);
    \coordinate (P2) at (-1,-1.74);
    \coordinate (P3) at (0.82,0);
    \coordinate (P4) at (2,2);
    \draw [thick,green] (P1) -- (P2) -- (P3) -- (P4);
    \draw (P1) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above:$p_1$](){};
    \draw (P2) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above:$p_2$](){};
    \draw (P3) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above left:$p_3$](){};
    \draw (P4) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above left:$p_4$](){};
    \draw[red,decoration={brace,mirror,raise=10pt},decorate](P1) -- node[below=10pt] {$s_1$}(P2);
    \draw[red,decoration={brace,mirror,raise=10pt},decorate](P2) -- node[right=16pt] {$s_2$}(P3);
    \draw[red,decoration={brace,mirror,raise=10pt},decorate](P3) -- node[right=16pt] {$s_3$}(P4);
    \end{tikzpicture}
\end{figure}
\end{document}
6

If you agree, that braces labels is oriented with brace (what is some have expected to be), tha solution is relative simple. Use \draw[brace ...] (Pi) -- node[sloped,below=12pt] {Si} (Pj);

Complete code, in which I take liberty to make it shorter (as possible), is:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}

\begin{document}
\begin{figure}[ht]
  \centering
  \begin{tikzpicture}[
dot/.style = {circle, fill=black, 
              minimum size=1mm, inner sep=2pt,
              node contents = {},
              label=120:#1}, %< --- changed
brc/.style = {red,
              decoration={brace,mirror,raise=10pt},
              decorate}
                    ]
    \coordinate (Origin)   at (0,0);
    \coordinate (XAxisMin) at (-2.0,0);
    \coordinate (XAxisMax) at (2.0,0);
    \coordinate (YAxisMin) at (0,-2.2);
    \coordinate (YAxisMax) at (0,2.2);
\draw  (XAxisMin) -- (XAxisMax);
\draw  (YAxisMin) -- (YAxisMax);
    \coordinate (P1) at (-2,-2);
    \coordinate (P2) at (-1,-1.74);
    \coordinate (P3) at (0.82,0);
    \coordinate (P4) at (2,2);
\draw   (P1) node[dot=$p_1$] --
        (P2) node[dot=$p_2$] --
        (P3) node[dot=$p_3$] --
        (P4) node[dot=$p_4$];
\draw[brc](P1) -- node[sloped,below=12pt] {$s_1$} (P2);
\draw[brc](P2) -- node[sloped,below=12pt] {$s_2$}(P3);
\draw[brc](P3) -- node[sloped,below=12pt] {$s_3$}(P4);
    \end{tikzpicture}
\end{figure}
\end{document}

Above code generate the following graph:

enter image description here

Edit: Only slightly improved position of node labels ...

4

A bit tedious, but you can modify the pos and the distance. The nodes are positioned relative to the path between the points, not on the shifted path along the brace. So when you place a node directly below the mid point of the path between P1 and P2, it ends up to the left of the middle of the brace, because of the angle of the line.

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,angles,quotes}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[ht]
  \centering
  \begin{tikzpicture}
    \coordinate (Origin)   at (0,0);
    \coordinate (XAxisMin) at (-2.0,0);
    \coordinate (XAxisMax) at (2.0,0);
    \coordinate (YAxisMin) at (0,-2.2);
    \coordinate (YAxisMax) at (0,2.2);
    \draw  (XAxisMin) -- (XAxisMax);
    \draw  (YAxisMin) -- (YAxisMax);
    \coordinate (P1) at (-2,-2);
    \coordinate (P2) at (-1,-1.74);
    \coordinate (P3) at (0.82,0);
    \coordinate (P4) at (2,2);
    \draw [thick,green] (P1) -- (P2) -- (P3) -- (P4);
    \draw (P1) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above:$p_1$](){};
    \draw (P2) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above:$p_2$](){};
    \draw (P3) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above left:$p_3$](){};
    \draw (P4) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above left:$p_4$](){};
    \draw[red,decoration={brace,mirror,raise=10pt},decorate](P1) -- node[below=12pt,pos=0.7] {$s_1$} (P2);
    \draw[red,decoration={brace,mirror,raise=10pt},decorate](P2) -- node[right=20pt,pos=0.25] {$s_2$} (P3);
    \draw[red,decoration={brace,mirror,raise=10pt},decorate](P3) -- node[right=15pt,pos=0.35] {$s_3$} (P4);
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

3

You could set a node S1 midway along the brace between P1 and P2. Then, using the calc library, you find the midpoint M1 between points P1 and P2. Lastly, you place the brace label in a node some distance beyond the path from M1 to S1. Repeat for the other braces.

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,angles,quotes,calc}

\begin{document}
\begin{figure}[ht]
  \centering
  \begin{tikzpicture}[
dot/.style = {circle, fill=black, 
              minimum size=1mm, inner sep=2pt,
              node contents = {},
              label=above:#1},
brc/.style = {red,
              decoration={brace,mirror,raise=10pt},
              decorate}
                    ]
    \coordinate (Origin)   at (0,0);
    \coordinate (XAxisMin) at (-2.0,0);
    \coordinate (XAxisMax) at (2.0,0);
    \coordinate (YAxisMin) at (0,-2.2);
    \coordinate (YAxisMax) at (0,2.2);
\draw  (XAxisMin) -- (XAxisMax);
\draw  (YAxisMin) -- (YAxisMax);
    \coordinate (P1) at (-2,-2);
    \coordinate (P2) at (-1,-1.74);
    \coordinate (P3) at (0.82,0);
    \coordinate (P4) at (2,2);
    \coordinate (M1) at ($(P1)!0.5!(P2)$);
    \coordinate (M2) at ($(P2)!0.5!(P3)$);
    \coordinate (M3) at ($(P3)!0.5!(P4)$);
\draw [thick,green] (P1) -- (P2) -- (P3) -- (P4);
    \draw (P1) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above:$p_1$](){};
    \draw (P2) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above:$p_2$](){};
    \draw (P3) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above left:$p_3$](){};
    \draw (P4) node[circle,fill,minimum size=1mm,inner sep=2pt,label=above left:$p_4$](){};\draw[brc](P1) -- node(S1)[sloped,below=12pt] {} (P2);
\draw[brc](P2) -- node(S2)[sloped,below=12pt] {}(P3);
\draw[brc](P3) -- node(S3)[sloped,below=12pt] {}(P4);
\path[red] (M1) to ($(M1)!1.2!(S1)$) node{$s_1$};
\path[red] (M2) to ($(M2)!1.2!(S2)$) node{$s_2$};
\path[red] (M3) to ($(M3)!1.2!(S3)$) node{$s_3$};
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

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.