Fitting Shapes Around Irregular Nodes In TikZ
I have the following Hasse diagram
which uses the following code:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
I am attempting to draw a box around some of the nodes like so:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
node[draw,dotted,fit=(ab) (a) (b)] {};
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
which (unsurprisingly) ends up looking like this:
What I would like (ideally) is to make some round corner triangle that covers the nodes (ab), (a) and (b) such that (ac) remains uncovered. I'm quite new to tikz (though I use tikz-cd a fair amount) so I'm unsure which library would help without overly convoluting the code (several answers I've read I wouldn't be able to adapt for my purposes without explanation).
Any help appreciated, thanks!
tikz-pgf tikzlibrary
add a comment |
I have the following Hasse diagram
which uses the following code:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
I am attempting to draw a box around some of the nodes like so:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
node[draw,dotted,fit=(ab) (a) (b)] {};
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
which (unsurprisingly) ends up looking like this:
What I would like (ideally) is to make some round corner triangle that covers the nodes (ab), (a) and (b) such that (ac) remains uncovered. I'm quite new to tikz (though I use tikz-cd a fair amount) so I'm unsure which library would help without overly convoluting the code (several answers I've read I wouldn't be able to adapt for my purposes without explanation).
Any help appreciated, thanks!
tikz-pgf tikzlibrary
You need to tell TikZ that you want a triangle. The default node shape is a rectangle, which is precisely what you get. Also you can rotate a fit withrotate fit
. However, instead of doing all this, samcarter's nice answer is the way to go.
– marmot
Jan 7 at 15:43
add a comment |
I have the following Hasse diagram
which uses the following code:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
I am attempting to draw a box around some of the nodes like so:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
node[draw,dotted,fit=(ab) (a) (b)] {};
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
which (unsurprisingly) ends up looking like this:
What I would like (ideally) is to make some round corner triangle that covers the nodes (ab), (a) and (b) such that (ac) remains uncovered. I'm quite new to tikz (though I use tikz-cd a fair amount) so I'm unsure which library would help without overly convoluting the code (several answers I've read I wouldn't be able to adapt for my purposes without explanation).
Any help appreciated, thanks!
tikz-pgf tikzlibrary
I have the following Hasse diagram
which uses the following code:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
I am attempting to draw a box around some of the nodes like so:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
node[draw,dotted,fit=(ab) (a) (b)] {};
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
which (unsurprisingly) ends up looking like this:
What I would like (ideally) is to make some round corner triangle that covers the nodes (ab), (a) and (b) such that (ac) remains uncovered. I'm quite new to tikz (though I use tikz-cd a fair amount) so I'm unsure which library would help without overly convoluting the code (several answers I've read I wouldn't be able to adapt for my purposes without explanation).
Any help appreciated, thanks!
tikz-pgf tikzlibrary
tikz-pgf tikzlibrary
edited Jan 7 at 13:26
samcarter
86.9k795279
86.9k795279
asked Jan 7 at 12:17
BenBen
206
206
You need to tell TikZ that you want a triangle. The default node shape is a rectangle, which is precisely what you get. Also you can rotate a fit withrotate fit
. However, instead of doing all this, samcarter's nice answer is the way to go.
– marmot
Jan 7 at 15:43
add a comment |
You need to tell TikZ that you want a triangle. The default node shape is a rectangle, which is precisely what you get. Also you can rotate a fit withrotate fit
. However, instead of doing all this, samcarter's nice answer is the way to go.
– marmot
Jan 7 at 15:43
You need to tell TikZ that you want a triangle. The default node shape is a rectangle, which is precisely what you get. Also you can rotate a fit with
rotate fit
. However, instead of doing all this, samcarter's nice answer is the way to go.– marmot
Jan 7 at 15:43
You need to tell TikZ that you want a triangle. The default node shape is a rectangle, which is precisely what you get. Also you can rotate a fit with
rotate fit
. However, instead of doing all this, samcarter's nice answer is the way to go.– marmot
Jan 7 at 15:43
add a comment |
2 Answers
2
active
oldest
votes
You can do it also with tikz-cd
.
With execute at end picture={...}
you can add any TikZ command you need to execute after drawing you tikzcd
.
The crossing over
idea is by Sebastiano's deleted answer.
If you don't want to name the matrix
you can use tikzcdmatrixname
directly (see this answer by marmot, for example).
To set some options for all the tikzcd
of your document, you could use tikzcdset{...}
, see Section 2 Controlling the appearance of diagrams of the package documentation.
The matrix syntax is analogous to any other LaTeX table: &
to separate the cells and \
to separate the rows.
The command ar
is an abbreviation for arrow
. Its options u
, d
, l
and r
mean up, down, left and right (the direction of the arrow).
The option execute at end picture={...}
allows you to add some TikZ commands to be executed after the drawing of the diagram.
mymatr-n-m
is the element at row n
and column m
of matrix mymatr
.
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
create the point comodo
with coordinate x = the one of mymatr-2-1.north west
and coordinate y = the mymatr-3-1.south west
.
draw (A) -- (B);
draws a line from A to B.
dashed
and rounded corners
are options with obviuos meaning.
yshift=...
shifts the coordinate vertically, xshift=...
horizontally.
cycle
at the end tells that the path has to go from here to the starting point.
documentclass[a4paper,12pt]{article}
usepackage{tikz-cd}
tikzcdset{
every arrow/.append style={dash},
every diagram/.style={
row sep=50pt,
column sep=30pt
},
}
begin{document}
begin{tikzcd}[
every matrix/.style={name=mymatr},
execute at end picture={
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
draw[dashed, rounded corners] ([yshift=3pt]mymatr-2-1.north west) -- ([yshift=-3pt]comodo) -- ([yshift=-3pt, xshift=2pt]mymatr-3-2.south east) -- ([yshift=4pt, xshift=2pt]mymatr-3-2.north east) -- ([yshift=3pt]mymatr-2-1.north east) -- cycle;
}
]
& {a,b,c} ar[ld] ar[d] ar[rd]\
{a,b} ar[d] & {a,c} ar[ld] ar[rd] & {b,c} ar[d, crossing over] ar[ld, crossing over] \
{a} ar[rd] & {b} ar[lu, crossing over] ar[d, crossing over] & {c} ar[ld] \
& {}
end{tikzcd}
end{document}
2
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
1
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
|
show 3 more comments
To be more flexible you can manually draw the path around your desired nodes:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
draw[dotted,rounded corners=20pt] ([yshift=0.9cm]ab.north west) -- ([xshift=-0.15cm,yshift=-0.1cm]a.south west) -- ([xshift=0.7cm,yshift=-0.1cm]b.south east) -- cycle;
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
@Ben Nosouth east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the}
from ab should be inside the path shift the b corner right and the ab corner upwards,
– samcarter
Jan 7 at 13:40
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468950%2ffitting-shapes-around-irregular-nodes-in-tikz%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do it also with tikz-cd
.
With execute at end picture={...}
you can add any TikZ command you need to execute after drawing you tikzcd
.
The crossing over
idea is by Sebastiano's deleted answer.
If you don't want to name the matrix
you can use tikzcdmatrixname
directly (see this answer by marmot, for example).
To set some options for all the tikzcd
of your document, you could use tikzcdset{...}
, see Section 2 Controlling the appearance of diagrams of the package documentation.
The matrix syntax is analogous to any other LaTeX table: &
to separate the cells and \
to separate the rows.
The command ar
is an abbreviation for arrow
. Its options u
, d
, l
and r
mean up, down, left and right (the direction of the arrow).
The option execute at end picture={...}
allows you to add some TikZ commands to be executed after the drawing of the diagram.
mymatr-n-m
is the element at row n
and column m
of matrix mymatr
.
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
create the point comodo
with coordinate x = the one of mymatr-2-1.north west
and coordinate y = the mymatr-3-1.south west
.
draw (A) -- (B);
draws a line from A to B.
dashed
and rounded corners
are options with obviuos meaning.
yshift=...
shifts the coordinate vertically, xshift=...
horizontally.
cycle
at the end tells that the path has to go from here to the starting point.
documentclass[a4paper,12pt]{article}
usepackage{tikz-cd}
tikzcdset{
every arrow/.append style={dash},
every diagram/.style={
row sep=50pt,
column sep=30pt
},
}
begin{document}
begin{tikzcd}[
every matrix/.style={name=mymatr},
execute at end picture={
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
draw[dashed, rounded corners] ([yshift=3pt]mymatr-2-1.north west) -- ([yshift=-3pt]comodo) -- ([yshift=-3pt, xshift=2pt]mymatr-3-2.south east) -- ([yshift=4pt, xshift=2pt]mymatr-3-2.north east) -- ([yshift=3pt]mymatr-2-1.north east) -- cycle;
}
]
& {a,b,c} ar[ld] ar[d] ar[rd]\
{a,b} ar[d] & {a,c} ar[ld] ar[rd] & {b,c} ar[d, crossing over] ar[ld, crossing over] \
{a} ar[rd] & {b} ar[lu, crossing over] ar[d, crossing over] & {c} ar[ld] \
& {}
end{tikzcd}
end{document}
2
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
1
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
|
show 3 more comments
You can do it also with tikz-cd
.
With execute at end picture={...}
you can add any TikZ command you need to execute after drawing you tikzcd
.
The crossing over
idea is by Sebastiano's deleted answer.
If you don't want to name the matrix
you can use tikzcdmatrixname
directly (see this answer by marmot, for example).
To set some options for all the tikzcd
of your document, you could use tikzcdset{...}
, see Section 2 Controlling the appearance of diagrams of the package documentation.
The matrix syntax is analogous to any other LaTeX table: &
to separate the cells and \
to separate the rows.
The command ar
is an abbreviation for arrow
. Its options u
, d
, l
and r
mean up, down, left and right (the direction of the arrow).
The option execute at end picture={...}
allows you to add some TikZ commands to be executed after the drawing of the diagram.
mymatr-n-m
is the element at row n
and column m
of matrix mymatr
.
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
create the point comodo
with coordinate x = the one of mymatr-2-1.north west
and coordinate y = the mymatr-3-1.south west
.
draw (A) -- (B);
draws a line from A to B.
dashed
and rounded corners
are options with obviuos meaning.
yshift=...
shifts the coordinate vertically, xshift=...
horizontally.
cycle
at the end tells that the path has to go from here to the starting point.
documentclass[a4paper,12pt]{article}
usepackage{tikz-cd}
tikzcdset{
every arrow/.append style={dash},
every diagram/.style={
row sep=50pt,
column sep=30pt
},
}
begin{document}
begin{tikzcd}[
every matrix/.style={name=mymatr},
execute at end picture={
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
draw[dashed, rounded corners] ([yshift=3pt]mymatr-2-1.north west) -- ([yshift=-3pt]comodo) -- ([yshift=-3pt, xshift=2pt]mymatr-3-2.south east) -- ([yshift=4pt, xshift=2pt]mymatr-3-2.north east) -- ([yshift=3pt]mymatr-2-1.north east) -- cycle;
}
]
& {a,b,c} ar[ld] ar[d] ar[rd]\
{a,b} ar[d] & {a,c} ar[ld] ar[rd] & {b,c} ar[d, crossing over] ar[ld, crossing over] \
{a} ar[rd] & {b} ar[lu, crossing over] ar[d, crossing over] & {c} ar[ld] \
& {}
end{tikzcd}
end{document}
2
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
1
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
|
show 3 more comments
You can do it also with tikz-cd
.
With execute at end picture={...}
you can add any TikZ command you need to execute after drawing you tikzcd
.
The crossing over
idea is by Sebastiano's deleted answer.
If you don't want to name the matrix
you can use tikzcdmatrixname
directly (see this answer by marmot, for example).
To set some options for all the tikzcd
of your document, you could use tikzcdset{...}
, see Section 2 Controlling the appearance of diagrams of the package documentation.
The matrix syntax is analogous to any other LaTeX table: &
to separate the cells and \
to separate the rows.
The command ar
is an abbreviation for arrow
. Its options u
, d
, l
and r
mean up, down, left and right (the direction of the arrow).
The option execute at end picture={...}
allows you to add some TikZ commands to be executed after the drawing of the diagram.
mymatr-n-m
is the element at row n
and column m
of matrix mymatr
.
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
create the point comodo
with coordinate x = the one of mymatr-2-1.north west
and coordinate y = the mymatr-3-1.south west
.
draw (A) -- (B);
draws a line from A to B.
dashed
and rounded corners
are options with obviuos meaning.
yshift=...
shifts the coordinate vertically, xshift=...
horizontally.
cycle
at the end tells that the path has to go from here to the starting point.
documentclass[a4paper,12pt]{article}
usepackage{tikz-cd}
tikzcdset{
every arrow/.append style={dash},
every diagram/.style={
row sep=50pt,
column sep=30pt
},
}
begin{document}
begin{tikzcd}[
every matrix/.style={name=mymatr},
execute at end picture={
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
draw[dashed, rounded corners] ([yshift=3pt]mymatr-2-1.north west) -- ([yshift=-3pt]comodo) -- ([yshift=-3pt, xshift=2pt]mymatr-3-2.south east) -- ([yshift=4pt, xshift=2pt]mymatr-3-2.north east) -- ([yshift=3pt]mymatr-2-1.north east) -- cycle;
}
]
& {a,b,c} ar[ld] ar[d] ar[rd]\
{a,b} ar[d] & {a,c} ar[ld] ar[rd] & {b,c} ar[d, crossing over] ar[ld, crossing over] \
{a} ar[rd] & {b} ar[lu, crossing over] ar[d, crossing over] & {c} ar[ld] \
& {}
end{tikzcd}
end{document}
You can do it also with tikz-cd
.
With execute at end picture={...}
you can add any TikZ command you need to execute after drawing you tikzcd
.
The crossing over
idea is by Sebastiano's deleted answer.
If you don't want to name the matrix
you can use tikzcdmatrixname
directly (see this answer by marmot, for example).
To set some options for all the tikzcd
of your document, you could use tikzcdset{...}
, see Section 2 Controlling the appearance of diagrams of the package documentation.
The matrix syntax is analogous to any other LaTeX table: &
to separate the cells and \
to separate the rows.
The command ar
is an abbreviation for arrow
. Its options u
, d
, l
and r
mean up, down, left and right (the direction of the arrow).
The option execute at end picture={...}
allows you to add some TikZ commands to be executed after the drawing of the diagram.
mymatr-n-m
is the element at row n
and column m
of matrix mymatr
.
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
create the point comodo
with coordinate x = the one of mymatr-2-1.north west
and coordinate y = the mymatr-3-1.south west
.
draw (A) -- (B);
draws a line from A to B.
dashed
and rounded corners
are options with obviuos meaning.
yshift=...
shifts the coordinate vertically, xshift=...
horizontally.
cycle
at the end tells that the path has to go from here to the starting point.
documentclass[a4paper,12pt]{article}
usepackage{tikz-cd}
tikzcdset{
every arrow/.append style={dash},
every diagram/.style={
row sep=50pt,
column sep=30pt
},
}
begin{document}
begin{tikzcd}[
every matrix/.style={name=mymatr},
execute at end picture={
coordinate (comodo) at (mymatr-2-1.north west |- mymatr-3-1.south west);
draw[dashed, rounded corners] ([yshift=3pt]mymatr-2-1.north west) -- ([yshift=-3pt]comodo) -- ([yshift=-3pt, xshift=2pt]mymatr-3-2.south east) -- ([yshift=4pt, xshift=2pt]mymatr-3-2.north east) -- ([yshift=3pt]mymatr-2-1.north east) -- cycle;
}
]
& {a,b,c} ar[ld] ar[d] ar[rd]\
{a,b} ar[d] & {a,c} ar[ld] ar[rd] & {b,c} ar[d, crossing over] ar[ld, crossing over] \
{a} ar[rd] & {b} ar[lu, crossing over] ar[d, crossing over] & {c} ar[ld] \
& {}
end{tikzcd}
end{document}
edited Jan 8 at 11:29
answered Jan 7 at 21:54
CarLaTeXCarLaTeX
30.2k447127
30.2k447127
2
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
1
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
|
show 3 more comments
2
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
1
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
2
2
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
Surely is better you answer that mine. :-) Today is not a very beautiful day for me with LaTeX. There is cold here and I'm not concentrate with my mind (without translator). Is it exact in English? Very good. The fear of doing something wrong is so much that I'm keeping myself "hidden". I hope very much that Hupfer invites me to his forest :-)
– Sebastiano
Jan 7 at 22:41
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
@Sebastiano You gave me the idea. Your English is understandable :)
– CarLaTeX
Jan 7 at 22:44
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
Boh. Are you sure? :-( I don't like the reproaches since I was a little boy :-(:-(:-(. Good night and gold dreams.
– Sebastiano
Jan 7 at 22:46
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
@Sebastiano It was not a reproach, it was a compliment!
– CarLaTeX
Jan 8 at 3:40
1
1
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
@Ben Some more info added, let me know if you need more.
– CarLaTeX
Jan 8 at 11:30
|
show 3 more comments
To be more flexible you can manually draw the path around your desired nodes:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
draw[dotted,rounded corners=20pt] ([yshift=0.9cm]ab.north west) -- ([xshift=-0.15cm,yshift=-0.1cm]a.south west) -- ([xshift=0.7cm,yshift=-0.1cm]b.south east) -- cycle;
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
@Ben Nosouth east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the}
from ab should be inside the path shift the b corner right and the ab corner upwards,
– samcarter
Jan 7 at 13:40
add a comment |
To be more flexible you can manually draw the path around your desired nodes:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
draw[dotted,rounded corners=20pt] ([yshift=0.9cm]ab.north west) -- ([xshift=-0.15cm,yshift=-0.1cm]a.south west) -- ([xshift=0.7cm,yshift=-0.1cm]b.south east) -- cycle;
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
@Ben Nosouth east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the}
from ab should be inside the path shift the b corner right and the ab corner upwards,
– samcarter
Jan 7 at 13:40
add a comment |
To be more flexible you can manually draw the path around your desired nodes:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
draw[dotted,rounded corners=20pt] ([yshift=0.9cm]ab.north west) -- ([xshift=-0.15cm,yshift=-0.1cm]a.south west) -- ([xshift=0.7cm,yshift=-0.1cm]b.south east) -- cycle;
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
To be more flexible you can manually draw the path around your desired nodes:
documentclass[a4paper, 12pt]{article}
usepackage[utf8]{inputenc}
usepackage{tikz}
usetikzlibrary{fit}
begin{document}
begin{figure}[h]
centering
begin{tikzpicture}
node (abc) at (0,4) {${a,b,c}$};
node (ab) at (-2,2) {${a,b}$};
node (ac) at (0,2) {${a,c}$};
node (bc) at (2,2) {${b,c}$};
node (a) at (-2,0) {${a}$};
node (b) at (0,0) {${b}$};
node (c) at (2,0) {${c}$};
node (empty) at (0,-2) {${}$};
draw (abc) -- (ab) -- (a) -- (empty) -- (c) -- (bc) -- (abc) -- (ac) -- (a)
(ac) -- (c)
(b) -- (empty);
draw[preaction={draw=white, -,line width=6pt}] (ab) -- (b) -- (bc);
draw[dotted,rounded corners=20pt] ([yshift=0.9cm]ab.north west) -- ([xshift=-0.15cm,yshift=-0.1cm]a.south west) -- ([xshift=0.7cm,yshift=-0.1cm]b.south east) -- cycle;
end{tikzpicture}
label{fig:hasse}
end{figure}
end{document}
edited Jan 7 at 13:38
answered Jan 7 at 13:21
samcartersamcarter
86.9k795279
86.9k795279
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
@Ben Nosouth east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the}
from ab should be inside the path shift the b corner right and the ab corner upwards,
– samcarter
Jan 7 at 13:40
add a comment |
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
@Ben Nosouth east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the}
from ab should be inside the path shift the b corner right and the ab corner upwards,
– samcarter
Jan 7 at 13:40
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
+1, That's very close to what I'm after. I've played around with the numbers to try and get a shape that I'm happier with, though I'm not familiar with the syntax (for example I don't know if it's possible to get something like b.south east east) which is making it hard to get it to just the right shape (eg not cutting off the right bracket of (ab) while remaining symmetric). I will leave the question open to see if anyone has an improvement for the time being.
– Ben
Jan 7 at 13:35
@Ben No
south east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the }
from ab should be inside the path shift the b corner right and the ab corner upwards,– samcarter
Jan 7 at 13:40
@Ben No
south east south
is not possible, you can just use shifts to move the corners to the positions you want. I adjusted the positions a bit. If the }
from ab should be inside the path shift the b corner right and the ab corner upwards,– samcarter
Jan 7 at 13:40
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468950%2ffitting-shapes-around-irregular-nodes-in-tikz%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
You need to tell TikZ that you want a triangle. The default node shape is a rectangle, which is precisely what you get. Also you can rotate a fit with
rotate fit
. However, instead of doing all this, samcarter's nice answer is the way to go.– marmot
Jan 7 at 15:43