Creating boxes around items in Tikz matrix












2















I have the following Tikz picture:



   begin{center}
begin{tikzpicture}[>=stealth,sloped]
matrix (tree) [%
matrix of nodes,
minimum size=1cm,
column sep=2.5cm,
row sep=1cm,
]
{
$v_1$ & & $v_3$ & $f_2$ & $v_5$ \
& $f_1$ & & & \
$v_2$ & & $v_4$ & & \
};
draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
end{tikzpicture}
end{center}


Is it possible to get boxes around the $v_i$ and $f_j$? For instance circles?
I would like to have different boxes for the $v_i$ and $f_j$, because they have a different meaning.



I'm new to Tikz btw.



Kind regards,
Jens










share|improve this question




















  • 2





    You can add nodes={circle,draw} to the matrix style.

    – Kpym
    11 hours ago











  • @Kpym Please add an answer :) Avoid solutions in comments.

    – JouleV
    10 hours ago











  • @JouleV you can do it, I have no time now, thanks.

    – Kpym
    10 hours ago











  • Thanks for the suggestion, but I would like different boxes for the $v_i$ and $f_j$. And I presume that this is not possible in setting the matrix style. Am I correct?

    – Jens Wagemaker
    10 hours ago
















2















I have the following Tikz picture:



   begin{center}
begin{tikzpicture}[>=stealth,sloped]
matrix (tree) [%
matrix of nodes,
minimum size=1cm,
column sep=2.5cm,
row sep=1cm,
]
{
$v_1$ & & $v_3$ & $f_2$ & $v_5$ \
& $f_1$ & & & \
$v_2$ & & $v_4$ & & \
};
draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
end{tikzpicture}
end{center}


Is it possible to get boxes around the $v_i$ and $f_j$? For instance circles?
I would like to have different boxes for the $v_i$ and $f_j$, because they have a different meaning.



I'm new to Tikz btw.



Kind regards,
Jens










share|improve this question




















  • 2





    You can add nodes={circle,draw} to the matrix style.

    – Kpym
    11 hours ago











  • @Kpym Please add an answer :) Avoid solutions in comments.

    – JouleV
    10 hours ago











  • @JouleV you can do it, I have no time now, thanks.

    – Kpym
    10 hours ago











  • Thanks for the suggestion, but I would like different boxes for the $v_i$ and $f_j$. And I presume that this is not possible in setting the matrix style. Am I correct?

    – Jens Wagemaker
    10 hours ago














2












2








2








I have the following Tikz picture:



   begin{center}
begin{tikzpicture}[>=stealth,sloped]
matrix (tree) [%
matrix of nodes,
minimum size=1cm,
column sep=2.5cm,
row sep=1cm,
]
{
$v_1$ & & $v_3$ & $f_2$ & $v_5$ \
& $f_1$ & & & \
$v_2$ & & $v_4$ & & \
};
draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
end{tikzpicture}
end{center}


Is it possible to get boxes around the $v_i$ and $f_j$? For instance circles?
I would like to have different boxes for the $v_i$ and $f_j$, because they have a different meaning.



I'm new to Tikz btw.



Kind regards,
Jens










share|improve this question
















I have the following Tikz picture:



   begin{center}
begin{tikzpicture}[>=stealth,sloped]
matrix (tree) [%
matrix of nodes,
minimum size=1cm,
column sep=2.5cm,
row sep=1cm,
]
{
$v_1$ & & $v_3$ & $f_2$ & $v_5$ \
& $f_1$ & & & \
$v_2$ & & $v_4$ & & \
};
draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
end{tikzpicture}
end{center}


Is it possible to get boxes around the $v_i$ and $f_j$? For instance circles?
I would like to have different boxes for the $v_i$ and $f_j$, because they have a different meaning.



I'm new to Tikz btw.



Kind regards,
Jens







tikz-pgf tikz-trees






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 10 hours ago









AboAmmar

34.5k32985




34.5k32985










asked 11 hours ago









Jens WagemakerJens Wagemaker

1326




1326








  • 2





    You can add nodes={circle,draw} to the matrix style.

    – Kpym
    11 hours ago











  • @Kpym Please add an answer :) Avoid solutions in comments.

    – JouleV
    10 hours ago











  • @JouleV you can do it, I have no time now, thanks.

    – Kpym
    10 hours ago











  • Thanks for the suggestion, but I would like different boxes for the $v_i$ and $f_j$. And I presume that this is not possible in setting the matrix style. Am I correct?

    – Jens Wagemaker
    10 hours ago














  • 2





    You can add nodes={circle,draw} to the matrix style.

    – Kpym
    11 hours ago











  • @Kpym Please add an answer :) Avoid solutions in comments.

    – JouleV
    10 hours ago











  • @JouleV you can do it, I have no time now, thanks.

    – Kpym
    10 hours ago











  • Thanks for the suggestion, but I would like different boxes for the $v_i$ and $f_j$. And I presume that this is not possible in setting the matrix style. Am I correct?

    – Jens Wagemaker
    10 hours ago








2




2





You can add nodes={circle,draw} to the matrix style.

– Kpym
11 hours ago





You can add nodes={circle,draw} to the matrix style.

– Kpym
11 hours ago













@Kpym Please add an answer :) Avoid solutions in comments.

– JouleV
10 hours ago





@Kpym Please add an answer :) Avoid solutions in comments.

– JouleV
10 hours ago













@JouleV you can do it, I have no time now, thanks.

– Kpym
10 hours ago





@JouleV you can do it, I have no time now, thanks.

– Kpym
10 hours ago













Thanks for the suggestion, but I would like different boxes for the $v_i$ and $f_j$. And I presume that this is not possible in setting the matrix style. Am I correct?

– Jens Wagemaker
10 hours ago





Thanks for the suggestion, but I would like different boxes for the $v_i$ and $f_j$. And I presume that this is not possible in setting the matrix style. Am I correct?

– Jens Wagemaker
10 hours ago










1 Answer
1






active

oldest

votes


















1














If you want to have the same "box" for all nodes



You can add option nodes={draw,circle} if you want all nodes to be in circle "box":



documentclass[tikz]{standalone}
usetikzlibrary{matrix}
begin{document}
begin{tikzpicture}[>=stealth,sloped]
matrix (tree) [%
matrix of nodes,
minimum size=1cm,
column sep=2.5cm,
row sep=1cm,
nodes={draw,circle}
]
{
$v_1$ & & $v_3$ & $f_2$ & $v_5$\
& $f_1$ & & & \
$v_2$ & & $v_4$ & & \
};
draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
end{tikzpicture}
end{document}


enter image description here



All credits go to Kpym, and this nice proposal is shown in this answer by the author's request.



If you want different styles for different types of nodes



using matrix is still ok, but it is more complicated. I propose a normal solution:



documentclass[tikz]{standalone}
begin{document}
begin{tikzpicture}[>=stealth,sloped]
begin{scope}[every node/.style={minimum size=1cm,draw,circle}]
node (v1) at (0,0) {$v_1$};
node (v2) at (0,-2) {$v_2$};
node (v3) at (5,0) {$v_3$};
node (v4) at (5,-2) {$v_4$};
node (v5) at (10,0) {$v_5$};
end{scope}
begin{scope}[every node/.style={minimum size=1cm,draw,rectangle}]
node (f1) at (2.5,-1) {$f_1$};
node (f2) at (7.5,0) {$f_2$};
end{scope}
draw[->] (v1) -- (f1) node [near end,above, rounded corners] {$1$};
draw[->] (v2) -- (f1) node [near end,below] {$2$};
draw[->] (f1) -- (v3) node [near start,above] {$1$};
draw[->] (f1) -- (v4) node [near start,below] {$2$};
draw[->] (v3) -- (f2) node [near end,above] {$1$};
draw[->] (f2) -- (v5) node [near start,above] {$1$};
end{tikzpicture}
end{document}


enter image description here






share|improve this answer
























    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%2f483015%2fcreating-boxes-around-items-in-tikz-matrix%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









    1














    If you want to have the same "box" for all nodes



    You can add option nodes={draw,circle} if you want all nodes to be in circle "box":



    documentclass[tikz]{standalone}
    usetikzlibrary{matrix}
    begin{document}
    begin{tikzpicture}[>=stealth,sloped]
    matrix (tree) [%
    matrix of nodes,
    minimum size=1cm,
    column sep=2.5cm,
    row sep=1cm,
    nodes={draw,circle}
    ]
    {
    $v_1$ & & $v_3$ & $f_2$ & $v_5$\
    & $f_1$ & & & \
    $v_2$ & & $v_4$ & & \
    };
    draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
    draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
    draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
    draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
    draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
    draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
    end{tikzpicture}
    end{document}


    enter image description here



    All credits go to Kpym, and this nice proposal is shown in this answer by the author's request.



    If you want different styles for different types of nodes



    using matrix is still ok, but it is more complicated. I propose a normal solution:



    documentclass[tikz]{standalone}
    begin{document}
    begin{tikzpicture}[>=stealth,sloped]
    begin{scope}[every node/.style={minimum size=1cm,draw,circle}]
    node (v1) at (0,0) {$v_1$};
    node (v2) at (0,-2) {$v_2$};
    node (v3) at (5,0) {$v_3$};
    node (v4) at (5,-2) {$v_4$};
    node (v5) at (10,0) {$v_5$};
    end{scope}
    begin{scope}[every node/.style={minimum size=1cm,draw,rectangle}]
    node (f1) at (2.5,-1) {$f_1$};
    node (f2) at (7.5,0) {$f_2$};
    end{scope}
    draw[->] (v1) -- (f1) node [near end,above, rounded corners] {$1$};
    draw[->] (v2) -- (f1) node [near end,below] {$2$};
    draw[->] (f1) -- (v3) node [near start,above] {$1$};
    draw[->] (f1) -- (v4) node [near start,below] {$2$};
    draw[->] (v3) -- (f2) node [near end,above] {$1$};
    draw[->] (f2) -- (v5) node [near start,above] {$1$};
    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer




























      1














      If you want to have the same "box" for all nodes



      You can add option nodes={draw,circle} if you want all nodes to be in circle "box":



      documentclass[tikz]{standalone}
      usetikzlibrary{matrix}
      begin{document}
      begin{tikzpicture}[>=stealth,sloped]
      matrix (tree) [%
      matrix of nodes,
      minimum size=1cm,
      column sep=2.5cm,
      row sep=1cm,
      nodes={draw,circle}
      ]
      {
      $v_1$ & & $v_3$ & $f_2$ & $v_5$\
      & $f_1$ & & & \
      $v_2$ & & $v_4$ & & \
      };
      draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
      draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
      draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
      draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
      draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
      draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
      end{tikzpicture}
      end{document}


      enter image description here



      All credits go to Kpym, and this nice proposal is shown in this answer by the author's request.



      If you want different styles for different types of nodes



      using matrix is still ok, but it is more complicated. I propose a normal solution:



      documentclass[tikz]{standalone}
      begin{document}
      begin{tikzpicture}[>=stealth,sloped]
      begin{scope}[every node/.style={minimum size=1cm,draw,circle}]
      node (v1) at (0,0) {$v_1$};
      node (v2) at (0,-2) {$v_2$};
      node (v3) at (5,0) {$v_3$};
      node (v4) at (5,-2) {$v_4$};
      node (v5) at (10,0) {$v_5$};
      end{scope}
      begin{scope}[every node/.style={minimum size=1cm,draw,rectangle}]
      node (f1) at (2.5,-1) {$f_1$};
      node (f2) at (7.5,0) {$f_2$};
      end{scope}
      draw[->] (v1) -- (f1) node [near end,above, rounded corners] {$1$};
      draw[->] (v2) -- (f1) node [near end,below] {$2$};
      draw[->] (f1) -- (v3) node [near start,above] {$1$};
      draw[->] (f1) -- (v4) node [near start,below] {$2$};
      draw[->] (v3) -- (f2) node [near end,above] {$1$};
      draw[->] (f2) -- (v5) node [near start,above] {$1$};
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer


























        1












        1








        1







        If you want to have the same "box" for all nodes



        You can add option nodes={draw,circle} if you want all nodes to be in circle "box":



        documentclass[tikz]{standalone}
        usetikzlibrary{matrix}
        begin{document}
        begin{tikzpicture}[>=stealth,sloped]
        matrix (tree) [%
        matrix of nodes,
        minimum size=1cm,
        column sep=2.5cm,
        row sep=1cm,
        nodes={draw,circle}
        ]
        {
        $v_1$ & & $v_3$ & $f_2$ & $v_5$\
        & $f_1$ & & & \
        $v_2$ & & $v_4$ & & \
        };
        draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
        draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
        draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
        draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
        draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
        draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
        end{tikzpicture}
        end{document}


        enter image description here



        All credits go to Kpym, and this nice proposal is shown in this answer by the author's request.



        If you want different styles for different types of nodes



        using matrix is still ok, but it is more complicated. I propose a normal solution:



        documentclass[tikz]{standalone}
        begin{document}
        begin{tikzpicture}[>=stealth,sloped]
        begin{scope}[every node/.style={minimum size=1cm,draw,circle}]
        node (v1) at (0,0) {$v_1$};
        node (v2) at (0,-2) {$v_2$};
        node (v3) at (5,0) {$v_3$};
        node (v4) at (5,-2) {$v_4$};
        node (v5) at (10,0) {$v_5$};
        end{scope}
        begin{scope}[every node/.style={minimum size=1cm,draw,rectangle}]
        node (f1) at (2.5,-1) {$f_1$};
        node (f2) at (7.5,0) {$f_2$};
        end{scope}
        draw[->] (v1) -- (f1) node [near end,above, rounded corners] {$1$};
        draw[->] (v2) -- (f1) node [near end,below] {$2$};
        draw[->] (f1) -- (v3) node [near start,above] {$1$};
        draw[->] (f1) -- (v4) node [near start,below] {$2$};
        draw[->] (v3) -- (f2) node [near end,above] {$1$};
        draw[->] (f2) -- (v5) node [near start,above] {$1$};
        end{tikzpicture}
        end{document}


        enter image description here






        share|improve this answer













        If you want to have the same "box" for all nodes



        You can add option nodes={draw,circle} if you want all nodes to be in circle "box":



        documentclass[tikz]{standalone}
        usetikzlibrary{matrix}
        begin{document}
        begin{tikzpicture}[>=stealth,sloped]
        matrix (tree) [%
        matrix of nodes,
        minimum size=1cm,
        column sep=2.5cm,
        row sep=1cm,
        nodes={draw,circle}
        ]
        {
        $v_1$ & & $v_3$ & $f_2$ & $v_5$\
        & $f_1$ & & & \
        $v_2$ & & $v_4$ & & \
        };
        draw[->] (tree-1-1) -- (tree-2-2) node [near end,above, rounded corners] {$1$};
        draw[->] (tree-3-1) -- (tree-2-2) node [near end,below] {$2$};
        draw[->] (tree-2-2) -- (tree-1-3) node [near start,above] {$1$};
        draw[->] (tree-2-2) -- (tree-3-3) node [near start,below] {$2$};
        draw[->] (tree-1-3) -- (tree-1-4) node [near end,above] {$1$};
        draw[->] (tree-1-4) -- (tree-1-5) node [near start,above] {$1$};
        end{tikzpicture}
        end{document}


        enter image description here



        All credits go to Kpym, and this nice proposal is shown in this answer by the author's request.



        If you want different styles for different types of nodes



        using matrix is still ok, but it is more complicated. I propose a normal solution:



        documentclass[tikz]{standalone}
        begin{document}
        begin{tikzpicture}[>=stealth,sloped]
        begin{scope}[every node/.style={minimum size=1cm,draw,circle}]
        node (v1) at (0,0) {$v_1$};
        node (v2) at (0,-2) {$v_2$};
        node (v3) at (5,0) {$v_3$};
        node (v4) at (5,-2) {$v_4$};
        node (v5) at (10,0) {$v_5$};
        end{scope}
        begin{scope}[every node/.style={minimum size=1cm,draw,rectangle}]
        node (f1) at (2.5,-1) {$f_1$};
        node (f2) at (7.5,0) {$f_2$};
        end{scope}
        draw[->] (v1) -- (f1) node [near end,above, rounded corners] {$1$};
        draw[->] (v2) -- (f1) node [near end,below] {$2$};
        draw[->] (f1) -- (v3) node [near start,above] {$1$};
        draw[->] (f1) -- (v4) node [near start,below] {$2$};
        draw[->] (v3) -- (f2) node [near end,above] {$1$};
        draw[->] (f2) -- (v5) node [near start,above] {$1$};
        end{tikzpicture}
        end{document}


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 10 hours ago









        JouleVJouleV

        10.3k22558




        10.3k22558






























            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%2f483015%2fcreating-boxes-around-items-in-tikz-matrix%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)