
私はメモ用の素敵な「コールアウト機能」を持つためのいくつかの小さなコマンドを考案しました。次の MWE を検討してください (問題もそこで説明されています)。
\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}
これは(私見ですが)素晴らしいものを出力します:
\margincallout
問題は、時にはコマンドが役に立つということだ前にノード\roundmark
名を定義する 。
いずれにせよ、ドキュメントには 2 つのパスが必要です。ラベルの前方参照のようなものを記述できるのではないかと考えていましたが、解決策が見つかりません。
次のパスで解決されるノードを参照することは可能ですか?
アップデート:
そこで を試してみましたtikzmark
が、何かおかしなことが起こっているに違いありません。見てください:
\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}
最初の呼び出し(テキスト内)は、ある程度は機能しますが、線は引かれていません。そして、2番目と3番目の呼び出し(ポイントをマークするものの中へグラフ)オーバーレイで図全体を変換します...
良い点は、前方へのコールアウトが機能することですが、線が引かれていません。困惑しています。
答え1
(これを追加しますその上元の回答に取って代わるので、何そして気にしないどうやって、いつ、そしてもちろんなぜ元の回答を読む必要はありません。
速報:tikzmark
再び進化
tikzmark
このサイト上の質問を中心に、当初からかなりの進化を遂げてきました。その過程で獲得した重要な機能の1つは、保存した座標を他の場所で使用できる機能です。前文書内でのその出現に。
最初から持っていた特性の一つは、それが使用されることを意図していたことです外コマンド\tikz
またはtikzpicture
環境。内部的には、TikZ の通常の座標記憶サービスに完全にアクセスできるので、 は必要ないと考えられていました\tikzmark
。
しかし、前述の重要な特徴はないtikzpicture
TikZ が提供するものです。宣言前に内の座標を参照する方法はありません。そのため、それを実行したい場合は、新しいものが必要です。
この質問の重要な特徴は、質問者が a の内側と外側の座標を参照するのに同じメカニズムを使用したいということですtikzpicture
。つまり、この透視座標機能を tikzpictures 内に提供する正しい方法は、tikzmark を拡張することだと考えられます。
これは非常に簡単であることがわかりました。簡単に言うと、tikzmark はラベルを tikzpicture の原点に関連付け、すべての面倒な作業は座標系で行われます。拡張機能は潜在的なオフセットを追加するもので、tikz がページ上の tikzpicture の原点がどこにあるかを把握したら、オフセットを適用します。これを tikzpicture 内にいるかどうかを確認するテストと組み合わせると、すべて完了です。
(この新しいバージョンに切り替える場合は、再コンパイルする前に aux ファイルを削除する必要があります。そうしないと、最初の再コンパイル時に多くのエラーが発生します。)
構文内部tikzpicture は\tikzmark{label}{coordinate}
、たとえばです\tikmark{a}{(3,4)}
。これは、座標が現在の画像内の(pic cs:a)
点を指すことを意味します。(3,4)
この新しいバージョンのtikzmarkは以下からダウンロードできます。ギットハブ: ダウンロードtikzmark.dtx
して実行しtex tikzmark.dtx
、ファイルを生成します。
だから、新しい、改良された \tikzmark
コードは再び適切な状態に戻りました。
\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}
(下記と同じ画像)
元の回答は次のとおりです:
ここでいくつか...
tikzmark
(まず、との相互作用にバグを発見しましたmarginpar
。バグのあるバージョンはCTANのバージョンよりも新しいのではないかと思います。何でも2番目の例では、バグのあるバージョンを使用していました。とにかく、更新されたバージョンはgithubで入手可能。
第二に、そしてもっと重要なことは\tikzmark
、内部環境tikzpicture
。そうすると、問題が発生します。正規表現を使用して HTML を解析するよりもさらに深刻です。重要なのは、環境内にいる場合はtikzpicture
、tikz のすべてのノードと座標配置にアクセスでき、tikzmark は必要ないということです。
(念のため言っておきますが、私が「tikzpicture 内で tikzmark を使用しないでください」と何度言っても、人々はそれを使いたがっているようです。勇気を出して、それを機能させる方法を考え出すべきかもしれません。)
確かに、これはコールアウト コードの 2 つのバージョンが必要であることを意味します。1 つはマークが tikzpicture 内にある場合用、もう 1 つはマークが tikzpicture 内にない場合用です。おそらく、これを回避する巧妙なコーディング方法があるでしょうが、私は頭が小さいので、今そのように考えることはできません。
したがって、これはスタイル コンテストでは決して優勝できませんが、正しい結果になると思われる、コードの動作バージョンを以下に示します。
\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}