Re: Difficoltà con tikzmark

#82228
Up
0
Down
::

Elrond” post=81558edit: ti riferivi a questo con la frase «si ha come side effect che colore di sfondo ed annotazioni non sono più centrate»?

Esattamente.

Elrond” post=81558Con la mia definizione le ancore sono corrette attorno al contenuto del nodo (anche se comunque ho dovuto fare degli adattamenti), con la definizione tradizionale di [tt]\tikzmark[/tt] direi proprio di no (e senza la famosa baseline di egreg9 sarebbe ancora peggio).

Non condivido e ti spiego il perché.

Con la tua definizione stai introducendo allineamenti non corretti. Con la definizione originale si contrassegna sempre il punto in basso (a destra o a sinistra rispetto a come è posizionato il marcatore); con la soluzione di Enrico si contrassegna il punto allineato centralmente in verticale sempre a destra o a sinistra rispetto a come è posizionato il marcatore.

Codice:`
% Nel preambolo
\newcommand{\tikzmark}[2]{%
\tikz[baseline=-\the\dimexpr\fontdimen22\textfont2\relax,remember picture,overlay]\node (#1) {#2};
}

\newcommand{\realtikzmark}[1]{%
\tikz[baseline=-\the\dimexpr\fontdimen22\textfont2\relax,remember picture,overlay]\node (#1) {};
}
\def\vertalign{\the\dimexpr\fontdimen22\textfont2\relax}

\newcommand{\simpletikzmark}[1]{%
\tikz[remember picture,overlay]\node (#1) {};
}

\newcommand{\placemark}[1]{%
\tikz[remember picture,overlay]\draw[red] plot[mark=x] coordinates {(#1)};
}

% Nel documento

\scalebox{5}{
$x\simpletikzmark{a}$
\placemark{a}
}
\tikz[remember picture, overlay]\draw[dashed]($(a)-(0.5em,0)$)–($(a)+(25em,0)$);
\scalebox{5}{
$x\realtikzmark{b}$
\placemark{b}
}
\scalebox{5}{
$\tikzmark{c}{$x$}$
\placemark{c}
}
` produce:

[attachment=584]Senzanome_2013-01-23.jpg[/attachment]

Nota come la tua definizione a destra non sia correttamente allineata verticalmente. Detto questo, quando si va poi ad inserire annotazioni o ad evidenziare, la cosa importante è solo sapere dove è sistemato il contrassegno: che sia in basso, al centro è indifferente, anche se ovviamente si devono fare aggiustamenti diversi. In ogni caso, ti spiego perché la tua definizione di [tt]tikzmark[/tt] così scritta è esattamente uguale all’inserimento di un nodo normale.

Codice:`
\scalebox{4}{
$x\simpletikzmark{d}$
\begin{tikzpicture}[remember picture,overlay]
\draw[blue] ($(d.south)+(0,0)$)–
($(d.north)+(0,0.75ex)$)–
($(d.north)+(-0.75em,0.75ex)$)–
($(d.south)+(-0.75em,0)$)–cycle;
\end{tikzpicture}
\placemark{d}
}
\scalebox{4}{
$x\realtikzmark{e}$
\begin{tikzpicture}[remember picture,overlay]
\draw[blue] ($(e.south)+(0,-\vertalign)$)–
($(e.north)+(0,0.25ex)$)–
($(e.north)+(-0.75em,0.25ex)$)–
($(e.south)+(-0.75em,-\vertalign)$)–cycle;
\end{tikzpicture}
\placemark{e}
}
\scalebox{4}{
$\tikzmark{f}{$x$}$
\begin{tikzpicture}[remember picture,overlay]
\draw[blue] ($(f.south)+(0.6em,0)$)–
($(f.north)+(0.6em,0)$)–
($(f.north)+(-0.6em,0)$)–
($(f.south)+(-0.6em,0)$)–cycle;
\end{tikzpicture}
\placemark{f}
}
\scalebox{4}{
\begin{tikzpicture}[baseline=-0.5ex]
\node[draw=blue] (g) {$x$};
\draw[red] plot[mark=x] coordinates {(g)};
\end{tikzpicture}
}
` Risultato:

[attachment=585]Senzanome1.jpg[/attachment]

Come si può notare occorrono diversi aggiustamenti per ogni metodo: quelli a prima vista più semplici sono proprio quelli dati dalla tua definizione, che però è esattamente uguale ad inserire un nodo con l’opzione [tt]draw[/tt]. Quindi la macro tikzmark è inutile? No assolutamente, ma non funziona bene se viene passato il contenuto come argomento, altrimenti usa TikZ direttamente che è più diretto. Non che questa strada non sia già stata percorsa: la soluzione di Peter riportata sulla guida in effetti può essere vista come un tentativo di incapsulare il contenuto in due delimitatori (ma alla fine la storia è la stessa) e anche io nel mio piccolo ho fatto qualche tentativo Alignments by means of the tikzmark macro. Con un po’ di esperienza in più mi sento ora di condividere la risposta di Andrew nei commenti:

You are putting the stuff that you are highlighting inside the node and the \tikzmark was developed for precisely when this wasn’t a reasonable idea.

In definitiva, cambia poco che tu inserisca la formula come argomento o no: qualche aggiustamento lo devi fare comunque perciò è meglio non tirarsi dietro i problemi che questo approccio comporta. Un ultimo esempio: `
\scalebox{2.5}{
$
\begin{pmatrix}
0 & \tikzmark{x}{$0$} & 0\\
0 & 0 & 0\\
0 & \tikzmark{y}{$0$} & 0\\
\end{pmatrix}
$
\begin{tikzpicture}[remember picture, overlay]
\draw[dashed] ($(x.base)+(2em,0)$)–($(x.base)-(2em,0)$);
\draw[red,fill=red!20,opacity=0.2](x.north west)–(y.south west)–(y.south east)–(x.north east)–cycle;
\end{tikzpicture}
}
\scalebox{2.5}{
$
\begin{pmatrix}
0 & 0\simpletikzmark{w} & 0\\
0 & 0 & 0\\
0 & 0\simpletikzmark{z} & 0\\
\end{pmatrix}
$
\begin{tikzpicture}[remember picture, overlay]
\draw[dashed] ($(w.base)+(1.25em,0)$)–($(w.base)-(2em,0)$);
\draw[red,fill=red!20,opacity=0.2]
($(w.north west)+(-0.25em,1ex)$)–
($(z.south west)+(-0.25em,0)$)–
($(z.south east)+(-0.25em,0)$)–
($(w.north east)+(-0.25em,1ex)$)–cycle;
\end{tikzpicture}
}
\scalebox{2.5}{
$
\begin{pmatrix}
0 & \tikzmarkin{r}0 & 0 \\
0 & 0 & 0\\
0 & 0\tikzmarkend{r} & 0\\
\end{pmatrix}
$
}
` Risultato:

[attachment=586]Senzanome2.jpg[/attachment]

Nel primo esempio a sinistra ho usato la tua macro, in centro quella semplice e a destra [tt]hf-tikz[/tt] che nasconde all’utente i passaggi che si devono fare con gli altri metodi.

Il codice intero per completezza: `
\documentclass[a4paper,11pt]{article}
\usepackage[width=16cm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds,shapes.misc}
\usepackage{hf-tikz}

\newcommand{\tikzmark}[2]{%
\tikz[baseline=-\the\dimexpr\fontdimen22\textfont2\relax,remember picture,overlay]\node (#1) {#2};
}

\newcommand{\realtikzmark}[1]{%
\tikz[baseline=-\the\dimexpr\fontdimen22\textfont2\relax,remember picture,overlay]\node (#1) {};
}
\def\vertalign{\the\dimexpr\fontdimen22\textfont2\relax}

\newcommand{\simpletikzmark}[1]{%
\tikz[remember picture,overlay]\node (#1) {};
}

\newcommand{\placemark}[1]{%
\tikz[remember picture,overlay]\draw[red] plot[mark=x] coordinates {(#1)};
}

\begin{document}

\scalebox{5}{
$x\simpletikzmark{a}$
\placemark{a}
}
\tikz[remember picture, overlay]\draw[dashed]($(a)-(0.5em,0)$)–($(a)+(25em,0)$);
\scalebox{5}{
$x\realtikzmark{b}$
\placemark{b}
}
\scalebox{5}{
$\tikzmark{c}{$x$}$
\placemark{c}
}
\bigskip\bigskip

\scalebox{4}{
$x\simpletikzmark{d}$
\begin{tikzpicture}[remember picture,overlay]
\draw[blue] ($(d.south)+(0,0)$)–
($(d.north)+(0,0.75ex)$)–
($(d.north)+(-0.75em,0.75ex)$)–
($(d.south)+(-0.75em,0)$)–cycle;
\end{tikzpicture}
\placemark{d}
}
\scalebox{4}{
$x\realtikzmark{e}$
\begin{tikzpicture}[remember picture,overlay]
\draw[blue] ($(e.south)+(0,-\vertalign)$)–
($(e.north)+(0,0.25ex)$)–
($(e.north)+(-0.75em,0.25ex)$)–
($(e.south)+(-0.75em,-\vertalign)$)–cycle;
\end{tikzpicture}
\placemark{e}
}
\scalebox{4}{
$\tikzmark{f}{$x$}$
\begin{tikzpicture}[remember picture,overlay]
\draw[blue] ($(f.south)+(0.6em,0)$)–
($(f.north)+(0.6em,0)$)–
($(f.north)+(-0.6em,0)$)–
($(f.south)+(-0.6em,0)$)–cycle;
\end{tikzpicture}
\placemark{f}
}
\scalebox{4}{
\begin{tikzpicture}[baseline=-0.5ex]
\node[draw=blue] (g) {$x$};
\draw[red] plot[mark=x] coordinates {(g)};
\end{tikzpicture}
}

\bigskip\bigskip

\scalebox{2.5}{
$
\begin{pmatrix}
0 & \tikzmark{x}{$0$} & 0\\
0 & 0 & 0\\
0 & \tikzmark{y}{$0$} & 0\\
\end{pmatrix}
$
\begin{tikzpicture}[remember picture, overlay]
\draw[dashed] ($(x.base)+(2em,0)$)–($(x.base)-(2em,0)$);
\draw[red,fill=red!20,opacity=0.2](x.north west)–(y.south west)–(y.south east)–(x.north east)–cycle;
\end{tikzpicture}
}
\scalebox{2.5}{
$
\begin{pmatrix}
0 & 0\simpletikzmark{w} & 0\\
0 & 0 & 0\\
0 & 0\simpletikzmark{z} & 0\\
\end{pmatrix}
$
\begin{tikzpicture}[remember picture, overlay]
\draw[dashed] ($(w.base)+(1.25em,0)$)–($(w.base)-(2em,0)$);
\draw[red,fill=red!20,opacity=0.2]
($(w.north west)+(-0.25em,1ex)$)–
($(z.south west)+(-0.25em,0)$)–
($(z.south east)+(-0.25em,0)$)–
($(w.north east)+(-0.25em,1ex)$)–cycle;
\end{tikzpicture}
}
\scalebox{2.5}{
$
\begin{pmatrix}
0 & \tikzmarkin{r}0 & 0 \\
0 & 0 & 0\\
0 & 0\tikzmarkend{r} & 0\\
\end{pmatrix}
$
}
\end{document}
`

Ciao
Claudio

Attachments:
You must be logged in to view attached files.

Go to top