Re: Diagrammi che si spostano in Beamer

#76257
Up
0
Down
::

Bresciani” post=75414Salve,
ho un piccolo problema con beamer. Devo fare una presentazione in cui c’è un diagramma, fatto con una matrice in tikz, le cui entrate cambiano cambiando pagina. Cioè, ho questa matrice, fissa, con alcune componenti fisse, e altre componenti che cambiano passando da una pagina all’altra. Il problema è che, nel cambiare pagina, ricreando il grafico, poiché le entrate sono diverse e hanno diverse dimensioni, si spostano i pezzi del grafico, anche quelli che non cambiano e che quindi sarebbe bello se fossero fissi. C’è un modo di fargli calcolare le dimensioni una sola volta, in modo che, da una pagina all’altra, cambino solo le entrate e non le dimensioni? Allego un pezzo di codice di esempio.

`
\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{default}

\usepackage{amsmath,amssymb,amsthm,amstext,tikz}
\usetikzlibrary{matrix,arrows,calc}

\begin{document}
\begin{frame}
\only<1>{
\begin{center}
\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]
\matrix (m) [matrix of math nodes, row sep=0.5em,
column sep=1em, text height=1ex, text depth=0.25ex, ampersand replacement=\&]
{ ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
4n-4 \& ~ \& <1\otimes x'^2> \& 0 \& \cdots \& \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
2n-2 \& ~ \& <1\otimes x'> \& 0 \& \cdots \& \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
0 \& ~ \& <1\otimes1'> \& 0 \& \cdots \& \& 0 \& ~ \& ~ \\
~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
~ \& ~ \& 0 \& ~ \& ~ \& 2n-1 \& ~ \& ~ \& ~ \\};
\path[->,>=angle 90]
(m-7-2.center) edge (m-7-8)
(m-7-2.center) edge (m-1-2);
\path[->,font=\scriptsize]
(m-2-3) edge node[auto] {} (m-4-6)
(m-4-3) edge node[auto] {} (m-6-6);
\end{tikzpicture}
\end{center}
}
\only<2>{
\begin{center}
\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]
\matrix (m) [matrix of math nodes, row sep=0.5em,
column sep=1em, text height=1ex, text depth=0.25ex, ampersand replacement=\&]
{ ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
4n-4 \& ~ \& 0 \& 0 \& \cdots \& 0 \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
2n-2 \& ~ \& 0 \& 0 \& \cdots \& 0 \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
0 \& ~ \& <1\otimes1'> \& 0 \& \cdots \& 0 \& 0 \& ~ \& ~ \\
~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
~ \& ~ \& 0 \& ~ \& ~ \& 2n-1 \& ~ \& ~ \& ~ \\};
\path[->,>=angle 90]
(m-7-2.center) edge (m-7-8)
(m-7-2.center) edge (m-1-2);
%~ \path[->,font=\scriptsize]
%~ (m-2-3) edge node[auto] {} (m-4-6)
%~ (m-4-3) edge node[auto] {} (m-6-6);
\end{tikzpicture}
\end{center}
}
\end{frame}

\end{document}
`

Ciao,

ho provato a riscrivere il tuo codice usando solo una volta l’ambiente tikzpicture:

`
\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{lmodern} % evita i warning :
% 1) LaTeX Font Warning: Font shape `OT1/cmss/m/n' in size <4> not available
% 2) LaTeX Font Warning: Size substitutions with differences
\usetheme{default} % può essere omesso (meglio usetheme di usepackage)

\usepackage{amsmath,amssymb,amsthm,amstext,tikz}
\usetikzlibrary{matrix,arrows,calc}

\begin{document}
\begin{frame}

\centering
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=0.5em,
column sep=1em, text height=1ex, text depth=0.25ex, ampersand replacement=\&]
{ ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
4n-4 \& ~ \& \only<1>{<1\otimes x'^2>}\only<2>{0} \& 0 \& \cdots \& \only<1>{}\only<2>{0} \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
2n-2 \& ~ \& \only<1>{<1\otimes x'>}\only<2>{0} \& 0 \& \cdots \& \only<1>{}\only<2>{0} \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
0 \& ~ \& <1\otimes1'> \& 0 \& \cdots \& \only<1>{}\only<2>{0} \& 0 \& ~ \& ~ \\
~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
~ \& ~ \& 0 \& ~ \& ~ \& 2n-1 \& ~ \& ~ \& ~ \\};
\path[->,>=angle 90]
(m-7-2.center) edge (m-7-8)
(m-7-2.center) edge (m-1-2);
\path<1>[->,font=\scriptsize]
(m-2-3) edge node[auto] {} (m-4-6)
(m-4-3) edge node[auto] {} (m-6-6);
\end{tikzpicture}
\end{frame}

\end{document}
`
Le entrate della matrice cambiano come nel tuo esempio (il risultato è praticamente uguale). Il problema è che le dimensioni della matrice cambiano, come hai visto, con la dimensione delle entrate; se proprio vuoi che la spaziatura sia fissa, puoi ricorrere ad un approccio diverso e un po’ più lungo, ossia definire tutti i nodi a mano specificandone la posizione. Ad esempio:

`
\node (A) {$<1\otimes x'^2>$};
\node[below of=A] (B) {$\vdots$};

`
Come dicevo, lo svantaggio è che devi definire tutto a mano, ma questo ti garantisce sicuramente di mantenere le dimensioni che ti sei prefissato.

Altrimenti, una soluzione non proprio pulitissima, è di aumentare la spaziatura fra colonne:

`
\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{lmodern} % evita i warning :
% 1) LaTeX Font Warning: Font shape `OT1/cmss/m/n' in size <4> not available
% 2) LaTeX Font Warning: Size substitutions with differences
\usetheme{default} % può essere omesso (meglio usetheme di usepackage)

\usepackage{amsmath,amssymb,amsthm,amstext,tikz}
\usetikzlibrary{matrix,arrows,calc}

\begin{document}
\begin{frame}
\only<1>{
\begin{center}
\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]
\matrix (m) [matrix of math nodes, row sep=0.5em,
column sep=1em, text height=1ex, text depth=0.25ex, ampersand replacement=\&]
{ ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
4n-4 \& ~ \& <1\otimes x'^2> \& 0 \& \cdots \& \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
2n-2 \& ~ \& <1\otimes x'> \& 0 \& \cdots \& \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
0 \& ~ \& <1\otimes1'> \& 0 \& \cdots \& \& 0 \& ~ \& ~ \\
~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
~ \& ~ \& 0 \& ~ \& ~ \& 2n-1 \& ~ \& ~ \& ~ \\};
\path[->,>=angle 90]
(m-7-2.center) edge (m-7-8)
(m-7-2.center) edge (m-1-2);
\path[->,font=\scriptsize]
(m-2-3) edge node[auto] {} (m-4-6)
(m-4-3) edge node[auto] {} (m-6-6);
\end{tikzpicture}
\end{center}
}
\only<2>{
\begin{center}
\begin{tikzpicture}[description/.style={fill=white,inner sep=2pt}]
\matrix (m) [matrix of math nodes, row sep=0.5em,
column sep=1.35em, text height=1ex, text depth=0.25ex, ampersand replacement=\&]
{ ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
4n-4 \& ~ \& 0 \& 0 \& \cdots \& 0 \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
2n-2 \& ~ \& 0 \& 0 \& \cdots \& 0 \& 0 \& ~ \& ~ \\
~ \& ~ \& \vdots \& ~ \& ~ \& \vdots \& \vdots \& ~ \& ~ \\
0 \& ~ \& <1\otimes1'> \& 0 \& \cdots \& 0 \& 0 \& ~ \& ~ \\
~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \& ~ \\
~ \& ~ \& 0 \& ~ \& ~ \& 2n-1 \& ~ \& ~ \& ~ \\};
\path[->,>=angle 90]
(m-7-2.center) edge (m-7-8)
(m-7-2.center) edge (m-1-2);
%~ \path[->,font=\scriptsize]
%~ (m-2-3) edge node[auto] {} (m-4-6)
%~ (m-4-3) edge node[auto] {} (m-6-6);
\end{tikzpicture}
\end{center}
}
\end{frame}

\end{document}
`
ma è estremamente difficile ricalcare le stesse dimensioni del matrice precedente così.

Ciao
Claudio

Go to top