Arrow and label positing in a .pic using tikz












5















I am trying to draw a figure, which repeatedly contains a similar type of pictures. Hence I am using .pic provided by tikz in the following way:



documentclass[tikz, border=2px]{standalone}
usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

% define colors and other constants
colorlet{line color}{black!30}
defline thickness{1pt}

% define primitive shapes for the drawing
tikzset{
line/.style={
-, draw=line color, line width=line thickness},
z plus joint/.pic={
draw[black, line width=line thickness, fill=gray!50] (0,0)
circle (0.5);
draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
(270:0.4) arc (270:150:0.4);
draw[latex-,blue, shorten <=2pt] (-0.5, 0.5) -- ++ (-0.5, 0.5)
node[above=2pt, black]{#1};
},
z minus joint/.pic={
pic[yscale=-1, rotate=180] {z plus joint=#1};},
}


begin{document}
begin{tikzpicture}[node distance=2cm]
path[line] (0, 0) pic {z plus joint=1} --
(2, 0) pic {z minus joint=3} --
(4, 0) pic {z minus joint=2} --
(4, 2) pic {z plus joint=4} --
(4, 4) pic {z minus joint=6};
end{tikzpicture}
end{document}


Please see below the generated figure:



enter image description here



I need the following two types of orientation for arrows:




  • Left side titled arrow

  • Right side titled arrow


I am looking for a way to provide an extra argument to the pic which can decide the orientation of the arrow. For example, see the following pseudo code:



begin{tikzpicture}[node distance=2cm]
path[line] (0, 0) pic {z plus joint={1}{right}} --
(2, 0) pic {z minus joint={3}{right}} --
(4, 0) pic {z minus joint={2}{left}} --
(4, 2) pic {z plus joint={4}{left}} --
(4, 4) pic {z minus joint={6}{left}};
end{tikzpicture}


PS: Since the orientation has only two possible values, i.e., left and right, we can have left as default










share|improve this question



























    5















    I am trying to draw a figure, which repeatedly contains a similar type of pictures. Hence I am using .pic provided by tikz in the following way:



    documentclass[tikz, border=2px]{standalone}
    usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

    % define colors and other constants
    colorlet{line color}{black!30}
    defline thickness{1pt}

    % define primitive shapes for the drawing
    tikzset{
    line/.style={
    -, draw=line color, line width=line thickness},
    z plus joint/.pic={
    draw[black, line width=line thickness, fill=gray!50] (0,0)
    circle (0.5);
    draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
    draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
    (270:0.4) arc (270:150:0.4);
    draw[latex-,blue, shorten <=2pt] (-0.5, 0.5) -- ++ (-0.5, 0.5)
    node[above=2pt, black]{#1};
    },
    z minus joint/.pic={
    pic[yscale=-1, rotate=180] {z plus joint=#1};},
    }


    begin{document}
    begin{tikzpicture}[node distance=2cm]
    path[line] (0, 0) pic {z plus joint=1} --
    (2, 0) pic {z minus joint=3} --
    (4, 0) pic {z minus joint=2} --
    (4, 2) pic {z plus joint=4} --
    (4, 4) pic {z minus joint=6};
    end{tikzpicture}
    end{document}


    Please see below the generated figure:



    enter image description here



    I need the following two types of orientation for arrows:




    • Left side titled arrow

    • Right side titled arrow


    I am looking for a way to provide an extra argument to the pic which can decide the orientation of the arrow. For example, see the following pseudo code:



    begin{tikzpicture}[node distance=2cm]
    path[line] (0, 0) pic {z plus joint={1}{right}} --
    (2, 0) pic {z minus joint={3}{right}} --
    (4, 0) pic {z minus joint={2}{left}} --
    (4, 2) pic {z plus joint={4}{left}} --
    (4, 4) pic {z minus joint={6}{left}};
    end{tikzpicture}


    PS: Since the orientation has only two possible values, i.e., left and right, we can have left as default










    share|improve this question

























      5












      5








      5


      0






      I am trying to draw a figure, which repeatedly contains a similar type of pictures. Hence I am using .pic provided by tikz in the following way:



      documentclass[tikz, border=2px]{standalone}
      usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

      % define colors and other constants
      colorlet{line color}{black!30}
      defline thickness{1pt}

      % define primitive shapes for the drawing
      tikzset{
      line/.style={
      -, draw=line color, line width=line thickness},
      z plus joint/.pic={
      draw[black, line width=line thickness, fill=gray!50] (0,0)
      circle (0.5);
      draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
      draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
      (270:0.4) arc (270:150:0.4);
      draw[latex-,blue, shorten <=2pt] (-0.5, 0.5) -- ++ (-0.5, 0.5)
      node[above=2pt, black]{#1};
      },
      z minus joint/.pic={
      pic[yscale=-1, rotate=180] {z plus joint=#1};},
      }


      begin{document}
      begin{tikzpicture}[node distance=2cm]
      path[line] (0, 0) pic {z plus joint=1} --
      (2, 0) pic {z minus joint=3} --
      (4, 0) pic {z minus joint=2} --
      (4, 2) pic {z plus joint=4} --
      (4, 4) pic {z minus joint=6};
      end{tikzpicture}
      end{document}


      Please see below the generated figure:



      enter image description here



      I need the following two types of orientation for arrows:




      • Left side titled arrow

      • Right side titled arrow


      I am looking for a way to provide an extra argument to the pic which can decide the orientation of the arrow. For example, see the following pseudo code:



      begin{tikzpicture}[node distance=2cm]
      path[line] (0, 0) pic {z plus joint={1}{right}} --
      (2, 0) pic {z minus joint={3}{right}} --
      (4, 0) pic {z minus joint={2}{left}} --
      (4, 2) pic {z plus joint={4}{left}} --
      (4, 4) pic {z minus joint={6}{left}};
      end{tikzpicture}


      PS: Since the orientation has only two possible values, i.e., left and right, we can have left as default










      share|improve this question














      I am trying to draw a figure, which repeatedly contains a similar type of pictures. Hence I am using .pic provided by tikz in the following way:



      documentclass[tikz, border=2px]{standalone}
      usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

      % define colors and other constants
      colorlet{line color}{black!30}
      defline thickness{1pt}

      % define primitive shapes for the drawing
      tikzset{
      line/.style={
      -, draw=line color, line width=line thickness},
      z plus joint/.pic={
      draw[black, line width=line thickness, fill=gray!50] (0,0)
      circle (0.5);
      draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
      draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
      (270:0.4) arc (270:150:0.4);
      draw[latex-,blue, shorten <=2pt] (-0.5, 0.5) -- ++ (-0.5, 0.5)
      node[above=2pt, black]{#1};
      },
      z minus joint/.pic={
      pic[yscale=-1, rotate=180] {z plus joint=#1};},
      }


      begin{document}
      begin{tikzpicture}[node distance=2cm]
      path[line] (0, 0) pic {z plus joint=1} --
      (2, 0) pic {z minus joint=3} --
      (4, 0) pic {z minus joint=2} --
      (4, 2) pic {z plus joint=4} --
      (4, 4) pic {z minus joint=6};
      end{tikzpicture}
      end{document}


      Please see below the generated figure:



      enter image description here



      I need the following two types of orientation for arrows:




      • Left side titled arrow

      • Right side titled arrow


      I am looking for a way to provide an extra argument to the pic which can decide the orientation of the arrow. For example, see the following pseudo code:



      begin{tikzpicture}[node distance=2cm]
      path[line] (0, 0) pic {z plus joint={1}{right}} --
      (2, 0) pic {z minus joint={3}{right}} --
      (4, 0) pic {z minus joint={2}{left}} --
      (4, 2) pic {z plus joint={4}{left}} --
      (4, 4) pic {z minus joint={6}{left}};
      end{tikzpicture}


      PS: Since the orientation has only two possible values, i.e., left and right, we can have left as default







      tikz-pgf






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Ravi JoshiRavi Joshi

      6991816




      6991816






















          1 Answer
          1






          active

          oldest

          votes


















          4














          Something like this? -1 for left and 1 for right.



          documentclass[tikz, border=2px]{standalone}
          usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

          % define colors and other constants
          colorlet{line color}{black!30}
          defline thickness{1pt}

          % define primitive shapes for the drawing
          tikzset{
          line/.style={
          -, draw=line color, line width=line thickness},
          pics/z plus joint/.style n args={2}{code={
          draw[black, line width=line thickness, fill=gray!50] (0,0)
          circle (0.5);
          draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
          draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
          (270:0.4) arc (270:150:0.4);
          draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5)
          node[above=2pt, black]{#1};
          }},
          pics/z minus joint/.style n args={2}{code={
          pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
          }


          begin{document}
          begin{tikzpicture}[node distance=2cm]
          path[line] (0, 0) pic {z plus joint={1}{1}}
          -- (2, 0) pic {z minus joint={3}{1}} --
          (4, 0) pic {z minus joint={2}{-1}} --
          (4, 2) pic {z plus joint={4}{-1}} --
          (4, 4) pic {z minus joint={6}{-1}}
          ;
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer



















          • 1





            Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

            – Ravi Joshi
            21 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f478537%2farrow-and-label-positing-in-a-pic-using-tikz%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          Something like this? -1 for left and 1 for right.



          documentclass[tikz, border=2px]{standalone}
          usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

          % define colors and other constants
          colorlet{line color}{black!30}
          defline thickness{1pt}

          % define primitive shapes for the drawing
          tikzset{
          line/.style={
          -, draw=line color, line width=line thickness},
          pics/z plus joint/.style n args={2}{code={
          draw[black, line width=line thickness, fill=gray!50] (0,0)
          circle (0.5);
          draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
          draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
          (270:0.4) arc (270:150:0.4);
          draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5)
          node[above=2pt, black]{#1};
          }},
          pics/z minus joint/.style n args={2}{code={
          pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
          }


          begin{document}
          begin{tikzpicture}[node distance=2cm]
          path[line] (0, 0) pic {z plus joint={1}{1}}
          -- (2, 0) pic {z minus joint={3}{1}} --
          (4, 0) pic {z minus joint={2}{-1}} --
          (4, 2) pic {z plus joint={4}{-1}} --
          (4, 4) pic {z minus joint={6}{-1}}
          ;
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer



















          • 1





            Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

            – Ravi Joshi
            21 hours ago
















          4














          Something like this? -1 for left and 1 for right.



          documentclass[tikz, border=2px]{standalone}
          usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

          % define colors and other constants
          colorlet{line color}{black!30}
          defline thickness{1pt}

          % define primitive shapes for the drawing
          tikzset{
          line/.style={
          -, draw=line color, line width=line thickness},
          pics/z plus joint/.style n args={2}{code={
          draw[black, line width=line thickness, fill=gray!50] (0,0)
          circle (0.5);
          draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
          draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
          (270:0.4) arc (270:150:0.4);
          draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5)
          node[above=2pt, black]{#1};
          }},
          pics/z minus joint/.style n args={2}{code={
          pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
          }


          begin{document}
          begin{tikzpicture}[node distance=2cm]
          path[line] (0, 0) pic {z plus joint={1}{1}}
          -- (2, 0) pic {z minus joint={3}{1}} --
          (4, 0) pic {z minus joint={2}{-1}} --
          (4, 2) pic {z plus joint={4}{-1}} --
          (4, 4) pic {z minus joint={6}{-1}}
          ;
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer



















          • 1





            Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

            – Ravi Joshi
            21 hours ago














          4












          4








          4







          Something like this? -1 for left and 1 for right.



          documentclass[tikz, border=2px]{standalone}
          usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

          % define colors and other constants
          colorlet{line color}{black!30}
          defline thickness{1pt}

          % define primitive shapes for the drawing
          tikzset{
          line/.style={
          -, draw=line color, line width=line thickness},
          pics/z plus joint/.style n args={2}{code={
          draw[black, line width=line thickness, fill=gray!50] (0,0)
          circle (0.5);
          draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
          draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
          (270:0.4) arc (270:150:0.4);
          draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5)
          node[above=2pt, black]{#1};
          }},
          pics/z minus joint/.style n args={2}{code={
          pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
          }


          begin{document}
          begin{tikzpicture}[node distance=2cm]
          path[line] (0, 0) pic {z plus joint={1}{1}}
          -- (2, 0) pic {z minus joint={3}{1}} --
          (4, 0) pic {z minus joint={2}{-1}} --
          (4, 2) pic {z plus joint={4}{-1}} --
          (4, 4) pic {z minus joint={6}{-1}}
          ;
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer













          Something like this? -1 for left and 1 for right.



          documentclass[tikz, border=2px]{standalone}
          usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

          % define colors and other constants
          colorlet{line color}{black!30}
          defline thickness{1pt}

          % define primitive shapes for the drawing
          tikzset{
          line/.style={
          -, draw=line color, line width=line thickness},
          pics/z plus joint/.style n args={2}{code={
          draw[black, line width=line thickness, fill=gray!50] (0,0)
          circle (0.5);
          draw[black, line width=line thickness, fill=white] (0,0) circle (0.3);
          draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}]
          (270:0.4) arc (270:150:0.4);
          draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5)
          node[above=2pt, black]{#1};
          }},
          pics/z minus joint/.style n args={2}{code={
          pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
          }


          begin{document}
          begin{tikzpicture}[node distance=2cm]
          path[line] (0, 0) pic {z plus joint={1}{1}}
          -- (2, 0) pic {z minus joint={3}{1}} --
          (4, 0) pic {z minus joint={2}{-1}} --
          (4, 2) pic {z plus joint={4}{-1}} --
          (4, 4) pic {z minus joint={6}{-1}}
          ;
          end{tikzpicture}
          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          marmotmarmot

          107k5129243




          107k5129243








          • 1





            Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

            – Ravi Joshi
            21 hours ago














          • 1





            Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

            – Ravi Joshi
            21 hours ago








          1




          1





          Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

          – Ravi Joshi
          21 hours ago





          Perfect. Now I understood the beauty of defining the pic using pics/z plus joint/.style n args={2}{code={ syntax! Thank you very much.

          – Ravi Joshi
          21 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f478537%2farrow-and-label-positing-in-a-pic-using-tikz%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to label and detect the document text images

          Vallis Paradisi

          Tabula Rosettana