Se trovi qualche parte che ti fa dubitare, puoi lasciarci un commento e ti risponderemo il prima possibile.
Soluzione:
Senza didascalie:
documentclass{article}
usepackage{tikz}
usetikzlibrary{automata, backgrounds,calc,shapes}
begin{document}
begin{figure}[ht]
centering
tikzset{shorten >=1pt,
node distance=1cm,
font = tiny,
auto,%on grid
state/.style = {shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt}
}
begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
end{tikzpicture}
hfil
begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a11) edge node {}(a12)
(a11) edge node {}(a21);
end{tikzpicture}
vspace{11mm}
begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a12) edge node {}(a22)
(a21) edge node {}(a31);
end{tikzpicture}
hfil
begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a12) edge node {}(a22)
(a31) edge node {}(a32);
end{tikzpicture}
end{figure}
end{document}
Con didascalia e sottocapitoli:
documentclass{article}
usepackage{tikz}
usetikzlibrary{automata, backgrounds,calc,shapes}
usepackage{subfig}
begin{document}
begin{figure}[ht]
centering
tikzset{shorten >=1pt,
node distance=1cm,
font = tiny,
auto,%on grid
state/.style = {shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt}
}
subfloat[]{begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
end{tikzpicture}}
hfil
subfloat[]{begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a11) edge node {}(a12)
(a11) edge node {}(a21);
end{tikzpicture}}
vspace{11mm}
subfloat[]{begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a12) edge node {}(a22)
(a21) edge node {}(a31);
end{tikzpicture}}
hfil
subfloat[]{begin{tikzpicture}
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a12) edge node {}(a22)
(a31) edge node {}(a32);
end{tikzpicture}}
caption{my 2 x 2 images}
label{fig:fourimages}
end{figure}
end{document}
Fuori tema:
Il codice delle immagini può essere significativamente accorciato se si utilizza la libreria TikZ matrix
. Per esempio, il secondo esempio di cui sopra può essere scritto come:
documentclass{article}
usepackage{tikz}
usetikzlibrary{matrix}
usepackage{subfig}
begin{document}
begin{figure}[ht]
centering
tikzset{M/.style = {matrix of math nodes,
ampersand replacement=&,
column sep = 9mm,
row sep = 9mm,
nodes = {circle, draw, thick, minimum size=+3ex,
font=tiny, anchor=center},
},
every edge/.style = {draw, ->, thick}
}
subfloat[]{
begin{tikzpicture}
matrix (m1) [M]
{
a_{31} & a_{32} \
a_{21} & a_{22} \
a_{21} & a_{22} \
};
end{tikzpicture}}
hfil
subfloat[]{
begin{tikzpicture}
matrix (m2) [M]
{
a_{31} & a_{32} \
a_{21} & a_{22} \
a_{21} & a_{22} \
};
%
path (m2-1-1) edge (m2-1-2)
(m2-1-1) edge (m2-2-1);
end{tikzpicture}}
vspace{11mm}
subfloat[]{
begin{tikzpicture}
matrix (m3) [M]
{
a_{31} & a_{32} \
a_{21} & a_{22} \
a_{21} & a_{22} \
};
%
path (m3-1-2) edge (m3-2-2)
(m3-2-1) edge (m3-3-1);
end{tikzpicture}}
hfil
subfloat[]{
begin{tikzpicture}
matrix (m4) [M]
{
a_{31} & a_{32} \
a_{21} & a_{22} \
a_{21} & a_{22} \
};
path (m4-1-2) edge (m3-2-2)
(m3-3-1) edge (m3-3-2);
end{tikzpicture}}
caption{my 2 x 2 images}
label{fig:fourimages}
end{figure}
end{document}
Il risultato è lo stesso di prima.
Una soluzione con tabular
:
documentclass{article}
usepackage{tikz}
usetikzlibrary{shapes,backgrounds,calc}
begin{document}
begin{tabular}{[email protected]{hspace{1cm}}c}%@{space between columns}
begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = tiny,auto]%,on grid
tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
end{tikzpicture}
&
begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = tiny,auto]%,on grid
tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a11) edge node {}(a12)
(a11) edge node {}(a21);
end{tikzpicture}\[1cm]%space betweem rows
begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = tiny,auto]%,on grid
tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a12) edge node {}(a22)
(a21) edge node {}(a31);
end{tikzpicture}
&
begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = tiny,auto]%,on grid
tikzstyle{state}=[shape=circle,thick,draw,minimum width=+2ex,minimum height=+3ex,inner sep=+.2pt]
node[state] (a31) {$a_{31}$};
node[state,above of=a31] (a21) {$a_{21}$};
node[state, very thick, above of=a21] (a11) {$a_{11}$};
node[state,right of=a11] (a12) {$a_{12}$};
node[state,below of=a12] (a22) {$a_{22}$};
node[state,below of=a22] (a32) {$a_{32}$};
path[->,draw,thick]
(a12) edge node {}(a22)
(a31) edge node {}(a32);
end{tikzpicture}\
end{tabular}
end{document}
Questa risposta utilizza una matrice in due modi diversi. O una matrice di pic
oppure utilizzando matrici per disegnare i diagrammi secondari. Purtroppo non è possibile annidare le matrici... ancora.
Matrice di immagini: È possibile definire un'immagine per le cose che si ripetono e una semplice macro per aggiungere le frecce. In questo modo non è necessario ripetere tante cose. Il pic
può essere definito in modo tale da dover specificare solo le frecce, ad es.
pic{scheme={11->12,11->21}};
rende
L'immagine completa si ottiene con
matrix[column sep=1cm,row sep=1cm]{
pic{scheme}; & pic{scheme={11->12,11->21}};\
pic{scheme={12->22,21->31}}; & pic{scheme={12->22,31->32}};\
};
La distanza tra i nodi del cerchio è controllata da node distance
e la distanza tra i blocchi da row sep
e column sep
, rispettivamente.
Questo è il codice completo:
documentclass[tikz]{standalone}
usetikzlibrary{positioning}
begin{document}
begin{tikzpicture}[shorten >=1pt,node distance=1em,font = tiny,auto,
state/.style={shape=circle,draw,minimum width=+2ex,minimum
height=+3ex,inner sep=+.2pt},arr/.style={->,thick,draw},
pics/scheme/.style={code={%
path foreach X [count=mycolumn] in {-0.5,0.5}
{foreach Y [count=myrow] in {1,0,-1}
{(X,Y) node[state,
line width={0.6pt+ifthenelse(myrow+10*mycolumn==11,1,0)*0.4pt}
]
(-myrow-mycolumn)
{$a_{myrowmycolumn}$}
}};
defArrDraw##1##2->##3##4;{
draw[arr] (-##1-##2) -- (-##3-##4);}
edeftempnone{none}%
edeftemparg{#1}%
unlessifxtempargtempnone
foreach X in {#1}
{expandafterArrDrawX;}
fi
}},pics/scheme/.default=none]
matrix[column sep=1cm,row sep=1cm]{
pic{scheme}; & pic{scheme={11->12,11->21}};\
pic{scheme={12->22,21->31}}; & pic{scheme={12->22,31->32}};\
};
end{tikzpicture}
end{document}
Utilizzo di matrici per i diagrammi parziali: Ognuno di questi diagrammi è un semplice matrix of nodes
che può essere riempito automaticamente. positioning
consente di posizionare queste matrici l'una rispetto all'altra.
documentclass[tikz]{standalone}
usetikzlibrary{positioning,matrix}
begin{document}
begin{tikzpicture}[shorten >=1pt,node distance=1cm,font = tiny,auto,
state/.style={shape=circle,thick,draw,minimum width=+2ex,minimum
height=+3ex,inner sep=+.2pt},arr/.style={->,very thick,draw},
mymat/.style={matrix of nodes,nodes in empty cells,column sep=1em,
row sep=1em,cells={nodes={state,execute at begin node={%
$a_{thepgfmatrixcurrentrowthepgfmatrixcurrentcolumn}$}}}}]%,on grid
matrix[mymat] (mat11) { |[very thick]| & \
& \
& \};
matrix[mymat,right=of mat11] (mat12) { |[very thick]| & \
& \
& \};
draw[arr] (mat12-1-1) -- (mat12-1-2);
draw[arr] (mat12-1-1) -- (mat12-2-1);
matrix[mymat,below=of mat11] (mat21) { |[very thick]| & \
& \
& \};
draw[arr] (mat21-1-2) -- (mat21-2-2);
draw[arr] (mat21-2-1) -- (mat21-3-1);
matrix[mymat,right=of mat21] (mat22) { |[very thick]| & \
& \
& \};
draw[arr] (mat22-1-2) -- (mat22-2-2);
draw[arr] (mat22-3-1) -- (mat22-3-2);
end{tikzpicture}
end{document}
ADDENDUM: È molto facile integrare le didascalie.
documentclass{article}
usepackage{tikz}
usepackage{subcaption}
usetikzlibrary{calc,positioning}
tikzset{
state/.style={shape=circle,draw,minimum width=+2ex,minimum
height=+3ex,inner sep=+.2pt},arr/.style={->,thick,draw},
pics/scheme/.style={code={%
begin{scope}[local bounding box=-bb]
path foreach X [count=mycolumn] in {-0.5,0.5}
{foreach Y [count=myrow] in {1,0,-1}
{(X,Y) node[state,
line width={0.6pt+ifthenelse(myrow+10*mycolumn==11,1,0)*0.4pt}
]
(-myrow-mycolumn)
{$a_{myrowmycolumn}$}
}};
end{scope}
tikzset{ie86/.cd,#1}
}},ie86/.cd,arrows/.code={defArrDraw##1##2->##3##4;{
draw[arr] (-##1-##2) -- (-##3-##4);}
edeftempnone{none}%
edeftemparg{#1}%
unlessifxtempargtempnone
foreach XX in {#1}
{expandafterArrDrawXX;}
fi},arrows/.default=none,
caption/.code={path let p1=($(-bb.east)-(-bb.west)$) in
(-bb.south) node[below,text width=x1,align=center,font=normalsize]
{begin{subfigure}{x1}
caption{#1}
end{subfigure}};}}
begin{document}
begin{figure}
centering
begin{tikzpicture}[shorten >=1pt,node distance=1em,font = tiny]
matrix[column sep=6mm,row sep=6mm]{
pic{scheme={caption={abc}}}; &
pic{scheme={arrows={11->12,11->21},caption={}}};\
pic{scheme={arrows={12->22,21->31},caption={blub}}}; &
pic{scheme={arrows={12->22,31->32},caption={bla}}};\
};
end{tikzpicture}
caption{Several graphs.}
end{figure}
end{document}
Ti mostriamo le recensioni e le valutazioni degli utenti
Se il nostro post ti è stato utile, sarebbe molto utile se lo condividessi con il resto dei programmatori e ci aiutassi a diffondere questo contenuto.