Tikz 覆蓋回憶錄中的子圖

Tikz 覆蓋回憶錄中的子圖

假設我在文件中排版了以下程式碼memoir

\begin{figure}
\centering
\subbottom[]{
\label{sub1}
\includegraphics[width=0.4\linewidth]{test.png}}%
\subbottom[]{
\label{sub2}
\includegraphics[width=0.4\linewidth]{test.png}}%
\caption{\subcaptionref{sub1}: Left of the figure. \subcaptionref{sub2}: Right of the figure}
\end{figure}

產生下圖:

在此輸入影像描述

我希望能夠在每個圖像上疊加一些文字和數學公式(相對於每個圖像的座標)。

我讀了這兩篇文章:

我真的很喜歡第一個中描述的解決方案,即使用tikz命令來覆蓋文字和公式。

然而,他們提供的範例需要使用tikzpicture環境,這似乎阻止我\subbottom[]在回憶錄中使用子圖。

如何將tikzpicture and範圍與subbottomin結合使用memoir

為了舉例說明,假設我想將符號覆蓋$\phi$在左側子圖的中心,將符號$\psi$覆蓋在右側子圖的中心(兩者都在小白框內)。

答案1

當您詢問 tikz 方式時,這是一種。當然,您可以大量整理程式碼並建立命令等,但下面的範例向您展示了一種可能的方法

\documentclass{memoir}

\usepackage{graphicx}
\newsubfloat{figure}
\usepackage{tikz}

\begin{document}

\begin{figure}
\centering
\subbottom[]{%
\label{sub1}
\begin{tikzpicture}[inner sep=0pt,remember picture]
\node at (0,0) {\includegraphics[width=0.4\linewidth]{test.jpg}};
\node[fill=green!20] (a) at (1,1) {A node};
\end{tikzpicture}
}%
\subbottom[]{
\label{sub2}
\begin{tikzpicture}[inner sep=0pt,remember picture]
\node at (0,0) {\includegraphics[width=0.4\linewidth]{test.jpg}};
\node[fill=red!20] (b) at (0.5,0.5) {A node};
\end{tikzpicture}
}%
\begin{tikzpicture}[remember picture,overlay]
 \draw[->,red,very thick] (a) to[bend right] (b);
\end{tikzpicture}

\caption{\subcaptionref{sub1}: Left of the figure. \subcaptionref{sub2}: Right
of the figure}
\end{figure}

\end{document}

基本上,您可以將圖片放在一個節點中,也可以將其他節點放在上面。透過告訴 tikz 記住節點,您可以稍後連接這些節點

在此輸入影像描述

答案2

為此,您實際上並不需要 TikZ。然而,它確實在疊加圖形方面允許更多的自由度和可變性。按原樣,可以透過以下方式進行覆蓋\ooalign

在此輸入影像描述

\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newsubfloat{figure}% Allows \subbottom and \subtop in figure
\newsavebox{\myfig}
\begin{document}
\begin{figure}
  \centering
  \savebox{\myfig}{\includegraphics[width=0.4\linewidth]{tiger}}% Store image
  \subbottom[]{%
    \label{sub1}%
    \ooalign{\usebox{\myfig}\cr\hss\raisebox{\dimexpr.5\ht\myfig-.5\baselineskip}{\colorbox{white}{\Huge$\phi$}}\hss}}%
  \subbottom[]{%
    \label{sub2}%
    \usebox{\myfig}}%
  \caption{\subcaptionref{sub1}:~Left of the figure. \subcaptionref{sub2}:~Right of the figure}
\end{figure}
\end{document}

將影像設定在框中 ( \myfig) 以獲得適當的高度(通過\ht\myfig)。\ooalign疊加雙重內容(影像和公式),同時\raisebox將公式垂直移動到位。

這個答案快速課程\ooalign

相關內容