
Ich habe mir ein paar kleine Befehle ausgedacht, um eine nette „Callout-Funktion“ für meine Notizen zu haben; beachten Sie bitte das folgende MWE (dort wird das Problem auch erklärt):
\documentclass{book}
\usepackage{tikz}
\tikzset{remember picture,
round mark/.style={
circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
},
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}
\usepackage{xparse}
\newcommand{\roundmark}[1]{\tikz[overlay, remember picture, baseline=-0.5ex]
\node [round mark, anchor=west] (#1) {};}
\NewDocumentCommand \addline {O{} m m }{%
\begin{tikzpicture}[overlay,remember picture]
\draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (#3);
\end{tikzpicture}%
}
\NewDocumentCommand \margincallout {O{} m +m }{%
\marginpar{
\begin{tikzpicture}[overlay,remember picture]
\node [ anchor=west, draw=orange, fill=yellow!20,
text width=\marginparwidth, align=left, font=\small,
#1 ] (expl@#2)
at (0,0) {
#3
};
\draw[ultra thick, yellow,->] (expl@#2) -- (#2);
\end{tikzpicture}}%
}
\begin{document}
I can mark thing in \roundmark{a}the main text and then have nice callouts from the marginpar to this point.
\margincallout{a}{This is a callout, a nice one and it's ok.}
% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
\begin{center}
\begin{tikzpicture}[remember picture,
]
\begin{axis}[
width=7cm,
xmin=0, xmax=10, domain=0:10,
enlarge y limits = 0.2,
ylabel = {Sensor R (\si{k\ohm})},
xlabel = {Kryporad (\si{\krypt})},
legend pos = north west,
legend style={nodes=right},
]
\addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
\addplot[blue, dashed] {143 + 16.8*x};
\legend{non-linear fit, linear fit}
\end{axis}
\node [round mark] (hor-axis) at (4,-0.5) {};
\node [round mark] (ver-axis) at (-0.5,4) {};
%\draw (0,0) grid (5,5);
\end{tikzpicture}
\end{center}
\caption{With a bit of guesswork I can mark things in the graphics, too}
\label{fig:calibR}
\end{figure}
\margincallout[yshift=3cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addline{hor-axis}{ver-axis}
Uncomment the following to see the error:
%But if I want to put the callout \textbf{before} the mark,
%as in \margincallout{future}{A forward callout} it will not work, and give me an error.
%The mark will be \roundmark{future}here, for example.
\end{document}
das gibt (meiner Meinung nach) etwas Nettes aus:
Das Problem ist, dass es manchmal nützlich ist, den \margincallout
Befehl zu habenVordas \roundmark
den Knotennamen definiert.
Das Dokument erfordert ohnehin zwei Durchläufe. Ich dachte, dass es vielleicht möglich wäre, so etwas wie Vorwärtsverweise für das Label zu schreiben, aber ich finde keine Lösung.
Ist es möglich, auf Knoten zu verweisen, die im nächsten Durchgang aufgelöst werden?
AKTUALISIEREN:
Also habe ich es mit versucht tikzmark
, aber hier muss etwas seltsam laufen. Schauen Sie:
\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{remember picture,
round mark/.style={
circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
},
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}
\usepackage{xparse}
\newcommand{\rtikzmark}[1]{\tikzmark[{
\node [baseline=-0.5ex, round mark, anchor=west]{}}]{#1}}
\NewDocumentCommand \addline {O{} m m }{%
\begin{tikzpicture}[overlay,remember picture]
\draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (pic cs:#3);
\end{tikzpicture}%
}
\NewDocumentCommand \margincallout {O{} m +m }{%
\marginpar{
\begin{tikzpicture}[overlay,remember picture]
\node [ anchor=west, draw=orange, fill=yellow!20,
text width=\marginparwidth, align=left, font=\small,
#1 ] (expl@#2)
at (0,0) {
#3
};
\draw[ultra thick, yellow,->] (expl@#2) -- (pic cs: #2);
\end{tikzpicture}}%
}
\begin{document}
I can mark thing in \rtikzmark{a}the main text and then have nice callouts from the marginpar to this point.
\margincallout{a}{This is a callout, a nice one and it's ok.}
% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
\begin{center}
\begin{tikzpicture}[remember picture,
]
\begin{axis}[
width=7cm,
xmin=0, xmax=10, domain=0:10,
enlarge y limits = 0.2,
ylabel = {Sensor R (\si{k\ohm})},
xlabel = {Kryporad (\si{\krypt})},
legend pos = north west,
legend style={nodes=right},
]
\addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
\addplot[blue, dashed] {143 + 16.8*x};
\legend{non-linear fit, linear fit}
\end{axis}
\node [round mark] at (4,-0.5) {}; \tikzmark{hor-axis};
\node [round mark] at (-0.5,4) {}; \tikzmark{ver-axis};
%\draw (0,0) grid (5,5);
\end{tikzpicture}
\end{center}
\caption{With a bit of guesswork I can mark things in the graphics, too}
\label{fig:calibR}
\end{figure}
\margincallout[yshift=3cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addline{hor-axis}{ver-axis}
Uncomment the following to see the error:
But if I want to put the callout \textbf{before} the mark,
as in \margincallout{future}{A forward callout} it will not work, and give me an error.
The mark will be \rtikzmark{future}here, for example.
\end{document}
Der erste Anruf (im Text) funktioniert irgendwie, aber dann wird die Linie nicht gezeichnet. Und der zweite und dritte Anruf (der eine markiert Punktehineindie Grafik) transformiert die gesamte Figur in Überlagerung...
Das Gute ist, dass der Weiterleitungsaufruf funktioniert, aber die Linie wird nicht gezeichnet. Ich bin verwirrt.
Antwort1
(Ich füge dies hinzuüberweil es die ursprüngliche Antwort ersetzt und jemand, der nur nach derWasund kümmert sich nicht um dieWie,Wannund schon gar nicht dieWarumSie sollten sich nicht die Mühe machen, die ursprüngliche Antwort zu lesen.)
Stop Press: tikzmark
entwickelt sich weiter
tikzmark
hat seit seiner Einführung eine beträchtliche Entwicklung durchlaufen, die hauptsächlich durch Fragen auf dieser Website vorangetrieben wurde. Eine der wichtigsten Funktionen, die es im Laufe der Zeit erhalten hat, war die Möglichkeit, die gespeicherten Koordinaten zu verwendenvorzu seinem Vorkommen im Dokument.
Eines seiner Attribute, das es von Anfang an hatte, war, dass es dazu bestimmt war, verwendet zu werdendraußenein \tikz
Befehl oder tikzpicture
eine Umgebung. Darin, so die Überlegung, hat man dann vollen Zugriff auf TikZs normalen Koordinatenspeicherdienst und daher besteht kein Bedarf für ein \tikzmark
.
Das oben erwähnte Hauptmerkmal ist jedochnichtetwas, das TikZ bereitstellt. Es gibt keine Möglichkeit, tikzpicture
vor der Deklaration auf eine Koordinate innerhalb von a zu verweisen. Wenn man das also tun möchte, braucht man etwas Neues.
Das Schlüsselmerkmal dieser Frage ist, dass der Fragesteller denselben Mechanismus verwenden möchte, um auf Koordinaten innerhalb von a tikzpicture
wie außerhalb davon zu verweisen. Das legt nahe, dass die richtige Art, diese Hellseherei-Koordinatenfunktion innerhalb von tikzpictures bereitzustellen, darin besteht, das tikzmark zu erweitern.
Dies erwies sich als recht einfach. Kurz gesagt, Tikzmark verknüpft ein Label mit dem Ursprung eines Tikzbilds und die ganze Schwerstarbeit wird im Koordinatensystem erledigt. Die Erweiterung besteht darin, einen möglichen Offset hinzuzufügen, sodass Tikz, sobald es herausgefunden hat, wo auf der Seite der Ursprung des besagten Tikzbilds liegt, den Offset anwendet. Kombinieren Sie dies mit einem Test, um zu sehen, ob wir uns in einem Tikzbild befinden, und alles ist erledigt.
(Beachten Sie bitte, dass Sie beim Wechsel zu dieser neuen Version die AUX-Datei vor dem Neukompilieren löschen sollten, da sonst beim ersten Neukompilieren zahlreiche Fehler auftreten.)
Die SyntaxinnenEin Tikz-Bild ist \tikzmark{label}{coordinate}
beispielsweise \tikmark{a}{(3,4)}
. Dies bedeutet, dass die Koordinate auf den Punkt im aktuellen Bild (pic cs:a)
zeigt .(3,4)
Sie können diese neue Version von Tikzmark herunterladen vongithub: herunterladen tikzmark.dtx
und ausführen tex tikzmark.dtx
, um die Dateien zu generieren.
Also mit demNeu verbessert \tikzmark
, der Code ist nun wieder in einem sinnvollen Zustand:
\documentclass{book}
%\url{http://tex.stackexchange.com/q/295903/86}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{remember picture,
round mark/.style={
circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
},
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}
\usepackage{xparse}
\newcommand{\rtikzmark}[1]{\tikzmark[{
\node [baseline=-0.5ex, round mark, anchor=west]{}}]{#1}}
\NewDocumentCommand \addline {O{} m m }{%
\begin{tikzpicture}[overlay,remember picture]
\draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (pic cs:#3);
\end{tikzpicture}%
}
\NewDocumentCommand \margincallout {O{} m +m }{%
\marginpar{
\begin{tikzpicture}[overlay,remember picture]
\node [ anchor=west, draw=orange, fill=yellow!20,
text width=\marginparwidth, align=left, font=\small,
#1 ] (expl@#2)
at (0,0) {
#3
};
\draw[ultra thick, yellow,->] (expl@#2) -- (pic cs:#2);
\end{tikzpicture}}%
}
\begin{document}
I can mark thing in \rtikzmark{a}the main text and then have nice callouts from the marginpar to this point.
\margincallout{a}{This is a callout, a nice one and it's ok.}
% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
\begin{center}
\begin{tikzpicture}[remember picture,
]
\begin{axis}[
width=7cm,
xmin=0, xmax=10, domain=0:10,
enlarge y limits = 0.2,
ylabel = {Sensor R (\si{k\ohm})},
xlabel = {Kryporad (\si{\krypt})},
legend pos = north west,
legend style={nodes=right},
]
\addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
\addplot[blue, dashed] {143 + 16.8*x};
\legend{non-linear fit, linear fit}
\end{axis}
\node [round mark] at (4,-0.5) (hor-axis) {};
\node [round mark] at (-0.5,4) (ver-axis) {};
\node [round mark] at (0,0) (origin) {};
\tikzmark{hor-axis}{(hor-axis)}
\tikzmark{ver-axis}{(ver-axis)}
\tikzmark{origin}{(origin)}
%\draw (0,0) grid (5,5);
\end{tikzpicture}
\end{center}
\caption{With a bit of guesswork I can mark things in the graphics, too}
\label{fig:calibR}
\end{figure}
\margincallout[yshift=4cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addline{hor-axis}{ver-axis}
\addline{hor-axis}{origin}
Uncomment the following to see the error:
But if I want to put the callout \textbf{before} the mark,
as in \margincallout{future}{A forward callout} it will not work, and give me an error.
The mark will be \rtikzmark{future}here, for example.
\end{document}
(Dasselbe Bild wie unten)
Ursprüngliche Antwort:
Ein paar Dinge hier ...
(Zunächst habe ich einen Fehler tikzmark
in der Interaktion mit gefunden marginpar
. Ich habe den Verdacht, dass die Version mit dem Fehler neuer ist als die Version auf CTAN, da Sie nicht hätten bekommen sollenirgendetwasin Ihrem zweiten Beispiel, wenn Sie die fehlerhafte Version verwenden. Wie auch immer, eine aktualisierte Version istverfügbar auf github.)
Zweitens, und das ist noch wichtiger, \tikzmark
ist es nicht dafür gedacht,inneneine tikzpicture
Umgebung. Wenn Sie das tun, kann etwas schiefgehen. Das ist noch schlimmer als die Verwendung von Regex zum Parsen von HTML. Der Punkt ist, dass Sie, wenn Sie sich in einer tikzpicture
Umgebung befinden, Zugriff auf alle Knoten- und Koordinatenpositionierungssachen von Tikz haben und Tikzmark nicht benötigen.
(Wobei es egal zu sein scheint, wie oft ich sage „Verwenden Sie Tikzmark nicht in einem Tikzpicture“, die Leute scheinen es verwenden zu wollen. Vielleicht sollte ich in den sauren Apfel beißen und herausfinden, wie es funktioniert.)
Zugegeben, das bedeutet, dass Sie zwei Versionen Ihres Callout-Codes benötigen: eine, wenn sich die Markierung in einem Tikz-Bild befindet, und eine, wenn sie sich nicht darin befindet. Es gibt wahrscheinlich raffinierte Möglichkeiten, dies zu codieren, um dies zu vermeiden, aber ich bin ein Bär mit kleinem Gehirn und kann zu dieser Stunde nicht so weit denken.
Obwohl dies bei einem Stilwettbewerb nie den Sieg bringen wird, ist hier eine funktionierende Version Ihres Codes, die meiner Meinung nach das richtige Ergebnis liefern sollte.
\documentclass{book}
%\url{http://tex.stackexchange.com/q/295903/86}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{remember picture,
round mark/.style={
circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
},
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9}
\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}
\usepackage{xparse}
\newcommand{\rtikzmark}[1]{\tikzmark[{
\node [baseline=-0.5ex, round mark, anchor=west]{}}]{#1}}
\NewDocumentCommand \addline {O{} m m }{%
\begin{tikzpicture}[overlay,remember picture]
\draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (pic cs:#3);
\end{tikzpicture}%
}
\NewDocumentCommand \addlineb {O{} m m }{%
\begin{tikzpicture}[overlay,remember picture]
\draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (#3);
\end{tikzpicture}%
}
\NewDocumentCommand \margincallout {O{} m +m }{%
\marginpar{
\begin{tikzpicture}[overlay,remember picture]
\node [ anchor=west, draw=orange, fill=yellow!20,
text width=\marginparwidth, align=left, font=\small,
#1 ] (expl@#2)
at (0,0) {
#3
};
\draw[ultra thick, yellow,->] (expl@#2) -- (pic cs:#2);
\end{tikzpicture}}%
}
\NewDocumentCommand \margincalloutb {O{} m +m }{%
\marginpar{
\begin{tikzpicture}[overlay,remember picture]
\node [ anchor=west, draw=orange, fill=yellow!20,
text width=\marginparwidth, align=left, font=\small,
#1 ] (expl@#2)
at (0,0) {
#3
};
\draw[ultra thick, yellow,->] (expl@#2) -- (#2);
\end{tikzpicture}}%
}
\begin{document}
I can mark thing in \rtikzmark{a}the main text and then have nice callouts from the marginpar to this point.
\margincallout{a}{This is a callout, a nice one and it's ok.}
% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
\begin{center}
\begin{tikzpicture}[remember picture,
]
\begin{axis}[
width=7cm,
xmin=0, xmax=10, domain=0:10,
enlarge y limits = 0.2,
ylabel = {Sensor R (\si{k\ohm})},
xlabel = {Kryporad (\si{\krypt})},
legend pos = north west,
legend style={nodes=right},
]
\addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
\addplot[blue, dashed] {143 + 16.8*x};
\legend{non-linear fit, linear fit}
\end{axis}
\node [round mark] at (4,-0.5) (hor-axis) {};
\node [round mark] at (-0.5,4) (ver-axis) {};
\node [round mark] at (0,0) (origin) {};
%\draw (0,0) grid (5,5);
\end{tikzpicture}
\end{center}
\caption{With a bit of guesswork I can mark things in the graphics, too}
\label{fig:calibR}
\end{figure}
\margincalloutb[yshift=4cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addlineb{hor-axis}{ver-axis}
\addlineb{hor-axis}{origin}
Uncomment the following to see the error:
But if I want to put the callout \textbf{before} the mark,
as in \margincallout{future}{A forward callout} it will not work, and give me an error.
The mark will be \rtikzmark{future}here, for example.
\end{document}