How to add caption for a TikZ picture?











up vote
68
down vote

favorite
28












I'm drawing a automaton figure, and I want to name it says 'M1' below the figure? A minimal example would be greatly appreciated. Thank you.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
node[state,initial] (q_0) {$q_0$};
node[state,accepting] (q_1) [right=of q_0] {$q_1$};
node[state] (q_2) [right=of q_1] {$q_2$};

path[->]
(q_0) edge node {a} (q_1)
(q_1) edge node {$lambda$} (q_2)
(q_2) edge [bend right] node {$lambda$} (q_0)
; %end path
end{tikzpicture}









share|improve this question
























  • Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures?
    – Martin Scharrer
    Jul 24 '11 at 21:20










  • The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture.
    – Chan
    Jul 24 '11 at 21:24















up vote
68
down vote

favorite
28












I'm drawing a automaton figure, and I want to name it says 'M1' below the figure? A minimal example would be greatly appreciated. Thank you.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
node[state,initial] (q_0) {$q_0$};
node[state,accepting] (q_1) [right=of q_0] {$q_1$};
node[state] (q_2) [right=of q_1] {$q_2$};

path[->]
(q_0) edge node {a} (q_1)
(q_1) edge node {$lambda$} (q_2)
(q_2) edge [bend right] node {$lambda$} (q_0)
; %end path
end{tikzpicture}









share|improve this question
























  • Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures?
    – Martin Scharrer
    Jul 24 '11 at 21:20










  • The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture.
    – Chan
    Jul 24 '11 at 21:24













up vote
68
down vote

favorite
28









up vote
68
down vote

favorite
28






28





I'm drawing a automaton figure, and I want to name it says 'M1' below the figure? A minimal example would be greatly appreciated. Thank you.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
node[state,initial] (q_0) {$q_0$};
node[state,accepting] (q_1) [right=of q_0] {$q_1$};
node[state] (q_2) [right=of q_1] {$q_2$};

path[->]
(q_0) edge node {a} (q_1)
(q_1) edge node {$lambda$} (q_2)
(q_2) edge [bend right] node {$lambda$} (q_0)
; %end path
end{tikzpicture}









share|improve this question















I'm drawing a automaton figure, and I want to name it says 'M1' below the figure? A minimal example would be greatly appreciated. Thank you.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto] 
node[state,initial] (q_0) {$q_0$};
node[state,accepting] (q_1) [right=of q_0] {$q_1$};
node[state] (q_2) [right=of q_1] {$q_2$};

path[->]
(q_0) edge node {a} (q_1)
(q_1) edge node {$lambda$} (q_2)
(q_2) edge [bend right] node {$lambda$} (q_0)
; %end path
end{tikzpicture}






tikz-pgf captions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 25 '11 at 18:11









morbusg

19.9k361136




19.9k361136










asked Jul 24 '11 at 19:33









Chan

3,882114665




3,882114665












  • Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures?
    – Martin Scharrer
    Jul 24 '11 at 21:20










  • The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture.
    – Chan
    Jul 24 '11 at 21:24


















  • Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures?
    – Martin Scharrer
    Jul 24 '11 at 21:20










  • The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture.
    – Chan
    Jul 24 '11 at 21:24
















Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures?
– Martin Scharrer
Jul 24 '11 at 21:20




Do you need a real caption like for figures with a running counter or just some text below it? You self-answer lets me goes it's the second case. In the first case should the pictures be labeled on their own, independent from the figures?
– Martin Scharrer
Jul 24 '11 at 21:20












The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture.
– Chan
Jul 24 '11 at 21:24




The text below a picture is what I needed, as provided in my answer. The reason that I used the word caption is because I googled and found that. I thought it was similar to a caption for a picture. There are two pictures being drawn next to each other, so I think the text solution is easier to manage in this particular situation. Nonetheless, I would agree with you on the first solution for a true caption for a picture.
– Chan
Jul 24 '11 at 21:24










3 Answers
3






active

oldest

votes

















up vote
98
down vote



accepted










Just include your code in a figure environment. In that way you'll be able to add a caption to it as a normal figure:



begin{figure}
centering
begin{tikzpicture}
<code>
end{tikzpicture}
caption{M1} label{fig:M1}
end{figure}





share|improve this answer

















  • 2




    Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
    – Chan
    Jul 24 '11 at 20:18






  • 4




    @Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
    – Caramdir
    Jul 24 '11 at 20:29






  • 1




    @Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
    – Chan
    Jul 24 '11 at 20:33






  • 8




    If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
    – Spike
    Jul 25 '11 at 7:22












  • @Spike: Although your comment was posted for a while, I still want to thank you for that.
    – Chan
    Aug 6 '11 at 0:12


















up vote
12
down vote













This is my solution using an extra node with text, it works pretty well.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
node[state,initial] (q_1) {$q_1$};
node[state,accepting] (q_2) [right=of q_1] {$q_2$};
node[state] (q_3) [below right=of q_1] {$q_3$};

path[->]
(q_1) edge [bend left] node {a} (q_2)
(q_1) edge [loop above] node {b} (q_1)
(q_2) edge [bend left] node {a,b} (q_3)
(q_3) edge [bend left] node {a} (q_2)
(q_3) edge [bend left] node {b} (q_1);

node [below=1cm, align=flush center,text width=8cm] at (q_3)
{
$M_1$
};
end{tikzpicture}





share|improve this answer

















  • 2




    The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
    – Benjamin McKay
    Dec 23 '14 at 21:06






  • 1




    how do I label this one??
    – David
    Feb 12 '15 at 17:49


















up vote
2
down vote













I've a similar solution using caption:



usepackage{caption}  


where in a beamer slide I would add caption via:



captionof{figure}{textbf{Confusion Matrix}}


as in:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
box/.style={draw,rectangle,minimum size=2cm,text width=1.5cm,align=left}]
matrix (conmat) [row sep=.1cm,column sep=.1cm] {
node (tpos) [box,
label=left:( mathbf{p'} ),
label=above:( mathbf{p} ),
] {True \ positive};
&
node (fneg) [box,
label=above:textbf{n},
label=above right:textbf{total},
label=right:( mathrm{P}' )] {False \ negative};
\
node (fpos) [box,
label=left:( mathbf{n'} ),
label=below left:textbf{total},
label=below:P] {False \ positive};
&
node (tneg) [box,
label=right:( mathrm{N}' ),
label=below:N] {True \ negative};
\
};
node [left=.05cm of conmat,text width=1.5cm,align=right] {textbf{actual \ value}};
node [above=.05cm of conmat] {textbf{prediction outcome}};
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}


Preview



slide with caption and confusion matrix





Simplified



For readability, without tikz code:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
% ... tikz ...
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}




The confusion matrix code comes from this answer.






share|improve this answer























  • Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
    – Jonathan Simon
    yesterday











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',
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%2f24000%2fhow-to-add-caption-for-a-tikz-picture%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
98
down vote



accepted










Just include your code in a figure environment. In that way you'll be able to add a caption to it as a normal figure:



begin{figure}
centering
begin{tikzpicture}
<code>
end{tikzpicture}
caption{M1} label{fig:M1}
end{figure}





share|improve this answer

















  • 2




    Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
    – Chan
    Jul 24 '11 at 20:18






  • 4




    @Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
    – Caramdir
    Jul 24 '11 at 20:29






  • 1




    @Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
    – Chan
    Jul 24 '11 at 20:33






  • 8




    If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
    – Spike
    Jul 25 '11 at 7:22












  • @Spike: Although your comment was posted for a while, I still want to thank you for that.
    – Chan
    Aug 6 '11 at 0:12















up vote
98
down vote



accepted










Just include your code in a figure environment. In that way you'll be able to add a caption to it as a normal figure:



begin{figure}
centering
begin{tikzpicture}
<code>
end{tikzpicture}
caption{M1} label{fig:M1}
end{figure}





share|improve this answer

















  • 2




    Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
    – Chan
    Jul 24 '11 at 20:18






  • 4




    @Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
    – Caramdir
    Jul 24 '11 at 20:29






  • 1




    @Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
    – Chan
    Jul 24 '11 at 20:33






  • 8




    If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
    – Spike
    Jul 25 '11 at 7:22












  • @Spike: Although your comment was posted for a while, I still want to thank you for that.
    – Chan
    Aug 6 '11 at 0:12













up vote
98
down vote



accepted







up vote
98
down vote



accepted






Just include your code in a figure environment. In that way you'll be able to add a caption to it as a normal figure:



begin{figure}
centering
begin{tikzpicture}
<code>
end{tikzpicture}
caption{M1} label{fig:M1}
end{figure}





share|improve this answer












Just include your code in a figure environment. In that way you'll be able to add a caption to it as a normal figure:



begin{figure}
centering
begin{tikzpicture}
<code>
end{tikzpicture}
caption{M1} label{fig:M1}
end{figure}






share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 24 '11 at 20:00









Spike

4,4131923




4,4131923








  • 2




    Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
    – Chan
    Jul 24 '11 at 20:18






  • 4




    @Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
    – Caramdir
    Jul 24 '11 at 20:29






  • 1




    @Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
    – Chan
    Jul 24 '11 at 20:33






  • 8




    If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
    – Spike
    Jul 25 '11 at 7:22












  • @Spike: Although your comment was posted for a while, I still want to thank you for that.
    – Chan
    Aug 6 '11 at 0:12














  • 2




    Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
    – Chan
    Jul 24 '11 at 20:18






  • 4




    @Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
    – Caramdir
    Jul 24 '11 at 20:29






  • 1




    @Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
    – Chan
    Jul 24 '11 at 20:33






  • 8




    If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
    – Spike
    Jul 25 '11 at 7:22












  • @Spike: Although your comment was posted for a while, I still want to thank you for that.
    – Chan
    Aug 6 '11 at 0:12








2




2




Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
– Chan
Jul 24 '11 at 20:18




Thank you for your quick response. However the picture position changes accordingly, it moves to the bottom of the page :(.
– Chan
Jul 24 '11 at 20:18




4




4




@Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
– Caramdir
Jul 24 '11 at 20:29




@Chan: Everything with caption should usually be a floating object, i.e. it should be automatically moved to the typographically most sensible position. That is what figure does. If you really don't want a float, then have a look at tex.stackexchange.com/questions/7210/….
– Caramdir
Jul 24 '11 at 20:29




1




1




@Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
– Chan
Jul 24 '11 at 20:33




@Caramdir: Thank you. In fact, I've just found a more elegant solution in the TikZ manual by using an extra node with text. Unfortunately, the compiler was freeze for some reasons.
– Chan
Jul 24 '11 at 20:33




8




8




If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
– Spike
Jul 25 '11 at 7:22






If you don't like the position of the figure you can specify it in the optional argument of the figure environment like that: begin{figure}[t]. Instead of t (top) you can use b (bottom), p (new page of floats) or h (here) or a combination of them. All of these options works well if LaTeX thinks that the result would be typographically correct.
– Spike
Jul 25 '11 at 7:22














@Spike: Although your comment was posted for a while, I still want to thank you for that.
– Chan
Aug 6 '11 at 0:12




@Spike: Although your comment was posted for a while, I still want to thank you for that.
– Chan
Aug 6 '11 at 0:12










up vote
12
down vote













This is my solution using an extra node with text, it works pretty well.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
node[state,initial] (q_1) {$q_1$};
node[state,accepting] (q_2) [right=of q_1] {$q_2$};
node[state] (q_3) [below right=of q_1] {$q_3$};

path[->]
(q_1) edge [bend left] node {a} (q_2)
(q_1) edge [loop above] node {b} (q_1)
(q_2) edge [bend left] node {a,b} (q_3)
(q_3) edge [bend left] node {a} (q_2)
(q_3) edge [bend left] node {b} (q_1);

node [below=1cm, align=flush center,text width=8cm] at (q_3)
{
$M_1$
};
end{tikzpicture}





share|improve this answer

















  • 2




    The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
    – Benjamin McKay
    Dec 23 '14 at 21:06






  • 1




    how do I label this one??
    – David
    Feb 12 '15 at 17:49















up vote
12
down vote













This is my solution using an extra node with text, it works pretty well.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
node[state,initial] (q_1) {$q_1$};
node[state,accepting] (q_2) [right=of q_1] {$q_2$};
node[state] (q_3) [below right=of q_1] {$q_3$};

path[->]
(q_1) edge [bend left] node {a} (q_2)
(q_1) edge [loop above] node {b} (q_1)
(q_2) edge [bend left] node {a,b} (q_3)
(q_3) edge [bend left] node {a} (q_2)
(q_3) edge [bend left] node {b} (q_1);

node [below=1cm, align=flush center,text width=8cm] at (q_3)
{
$M_1$
};
end{tikzpicture}





share|improve this answer

















  • 2




    The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
    – Benjamin McKay
    Dec 23 '14 at 21:06






  • 1




    how do I label this one??
    – David
    Feb 12 '15 at 17:49













up vote
12
down vote










up vote
12
down vote









This is my solution using an extra node with text, it works pretty well.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
node[state,initial] (q_1) {$q_1$};
node[state,accepting] (q_2) [right=of q_1] {$q_2$};
node[state] (q_3) [below right=of q_1] {$q_3$};

path[->]
(q_1) edge [bend left] node {a} (q_2)
(q_1) edge [loop above] node {b} (q_1)
(q_2) edge [bend left] node {a,b} (q_3)
(q_3) edge [bend left] node {a} (q_2)
(q_3) edge [bend left] node {b} (q_1);

node [below=1cm, align=flush center,text width=8cm] at (q_3)
{
$M_1$
};
end{tikzpicture}





share|improve this answer












This is my solution using an extra node with text, it works pretty well.



begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
node[state,initial] (q_1) {$q_1$};
node[state,accepting] (q_2) [right=of q_1] {$q_2$};
node[state] (q_3) [below right=of q_1] {$q_3$};

path[->]
(q_1) edge [bend left] node {a} (q_2)
(q_1) edge [loop above] node {b} (q_1)
(q_2) edge [bend left] node {a,b} (q_3)
(q_3) edge [bend left] node {a} (q_2)
(q_3) edge [bend left] node {b} (q_1);

node [below=1cm, align=flush center,text width=8cm] at (q_3)
{
$M_1$
};
end{tikzpicture}






share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 24 '11 at 21:09









Chan

3,882114665




3,882114665








  • 2




    The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
    – Benjamin McKay
    Dec 23 '14 at 21:06






  • 1




    how do I label this one??
    – David
    Feb 12 '15 at 17:49














  • 2




    The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
    – Benjamin McKay
    Dec 23 '14 at 21:06






  • 1




    how do I label this one??
    – David
    Feb 12 '15 at 17:49








2




2




The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
– Benjamin McKay
Dec 23 '14 at 21:06




The problem with your solution is that, when you want to included a figure with a caption that is not a tikz picture, the caption might be laid out quite differently, especially if your publisher has his/her own style for captions in a class or package file. For consistency of captioning, Spike's solution is my strong preference.
– Benjamin McKay
Dec 23 '14 at 21:06




1




1




how do I label this one??
– David
Feb 12 '15 at 17:49




how do I label this one??
– David
Feb 12 '15 at 17:49










up vote
2
down vote













I've a similar solution using caption:



usepackage{caption}  


where in a beamer slide I would add caption via:



captionof{figure}{textbf{Confusion Matrix}}


as in:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
box/.style={draw,rectangle,minimum size=2cm,text width=1.5cm,align=left}]
matrix (conmat) [row sep=.1cm,column sep=.1cm] {
node (tpos) [box,
label=left:( mathbf{p'} ),
label=above:( mathbf{p} ),
] {True \ positive};
&
node (fneg) [box,
label=above:textbf{n},
label=above right:textbf{total},
label=right:( mathrm{P}' )] {False \ negative};
\
node (fpos) [box,
label=left:( mathbf{n'} ),
label=below left:textbf{total},
label=below:P] {False \ positive};
&
node (tneg) [box,
label=right:( mathrm{N}' ),
label=below:N] {True \ negative};
\
};
node [left=.05cm of conmat,text width=1.5cm,align=right] {textbf{actual \ value}};
node [above=.05cm of conmat] {textbf{prediction outcome}};
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}


Preview



slide with caption and confusion matrix





Simplified



For readability, without tikz code:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
% ... tikz ...
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}




The confusion matrix code comes from this answer.






share|improve this answer























  • Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
    – Jonathan Simon
    yesterday















up vote
2
down vote













I've a similar solution using caption:



usepackage{caption}  


where in a beamer slide I would add caption via:



captionof{figure}{textbf{Confusion Matrix}}


as in:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
box/.style={draw,rectangle,minimum size=2cm,text width=1.5cm,align=left}]
matrix (conmat) [row sep=.1cm,column sep=.1cm] {
node (tpos) [box,
label=left:( mathbf{p'} ),
label=above:( mathbf{p} ),
] {True \ positive};
&
node (fneg) [box,
label=above:textbf{n},
label=above right:textbf{total},
label=right:( mathrm{P}' )] {False \ negative};
\
node (fpos) [box,
label=left:( mathbf{n'} ),
label=below left:textbf{total},
label=below:P] {False \ positive};
&
node (tneg) [box,
label=right:( mathrm{N}' ),
label=below:N] {True \ negative};
\
};
node [left=.05cm of conmat,text width=1.5cm,align=right] {textbf{actual \ value}};
node [above=.05cm of conmat] {textbf{prediction outcome}};
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}


Preview



slide with caption and confusion matrix





Simplified



For readability, without tikz code:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
% ... tikz ...
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}




The confusion matrix code comes from this answer.






share|improve this answer























  • Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
    – Jonathan Simon
    yesterday













up vote
2
down vote










up vote
2
down vote









I've a similar solution using caption:



usepackage{caption}  


where in a beamer slide I would add caption via:



captionof{figure}{textbf{Confusion Matrix}}


as in:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
box/.style={draw,rectangle,minimum size=2cm,text width=1.5cm,align=left}]
matrix (conmat) [row sep=.1cm,column sep=.1cm] {
node (tpos) [box,
label=left:( mathbf{p'} ),
label=above:( mathbf{p} ),
] {True \ positive};
&
node (fneg) [box,
label=above:textbf{n},
label=above right:textbf{total},
label=right:( mathrm{P}' )] {False \ negative};
\
node (fpos) [box,
label=left:( mathbf{n'} ),
label=below left:textbf{total},
label=below:P] {False \ positive};
&
node (tneg) [box,
label=right:( mathrm{N}' ),
label=below:N] {True \ negative};
\
};
node [left=.05cm of conmat,text width=1.5cm,align=right] {textbf{actual \ value}};
node [above=.05cm of conmat] {textbf{prediction outcome}};
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}


Preview



slide with caption and confusion matrix





Simplified



For readability, without tikz code:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
% ... tikz ...
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}




The confusion matrix code comes from this answer.






share|improve this answer














I've a similar solution using caption:



usepackage{caption}  


where in a beamer slide I would add caption via:



captionof{figure}{textbf{Confusion Matrix}}


as in:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
box/.style={draw,rectangle,minimum size=2cm,text width=1.5cm,align=left}]
matrix (conmat) [row sep=.1cm,column sep=.1cm] {
node (tpos) [box,
label=left:( mathbf{p'} ),
label=above:( mathbf{p} ),
] {True \ positive};
&
node (fneg) [box,
label=above:textbf{n},
label=above right:textbf{total},
label=right:( mathrm{P}' )] {False \ negative};
\
node (fpos) [box,
label=left:( mathbf{n'} ),
label=below left:textbf{total},
label=below:P] {False \ positive};
&
node (tneg) [box,
label=right:( mathrm{N}' ),
label=below:N] {True \ negative};
\
};
node [left=.05cm of conmat,text width=1.5cm,align=right] {textbf{actual \ value}};
node [above=.05cm of conmat] {textbf{prediction outcome}};
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}


Preview



slide with caption and confusion matrix





Simplified



For readability, without tikz code:



begin{frame}[fragile]
frametitle{Confusion Matrix}
begin{tikzpicture}[
% ... tikz ...
end{tikzpicture}
captionof{figure}{textbf{Confusion Matrix}}
end{frame}




The confusion matrix code comes from this answer.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Nov 30 at 14:51









Konrad

1467




1467












  • Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
    – Jonathan Simon
    yesterday


















  • Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
    – Jonathan Simon
    yesterday
















Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
– Jonathan Simon
yesterday




Should be the top answer, simple single-line command. Maybe remove all of that extraneous confusion matrix code, since it's just obscuring the (correct) answer?
– Jonathan Simon
yesterday


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f24000%2fhow-to-add-caption-for-a-tikz-picture%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 change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?