使用 \ref 作為圖形的一部分

使用 \ref 作為圖形的一部分

是否可以將引用作為包含在 LaTeX 文件中的圖形的一部分?
如果是這樣,這種圖形的首選格式是什麼(EPS,...)?

小樣:

小樣

我正在使用 pdflatex 進行編譯。

答案1

一種方法是將\includegraphics{...}TikZ 放在裡面node,然後node用 TikZ 將另一個放在圖像頂部,其中該節點包含\ref{...}\label{...}命令,這取決於您是否想要引用或標籤在 TikZ 內部圖片。

下面使用 TikZ 進行覆蓋的程式碼\includegrpahics{...}取自這個問題在 TeX.SX 上。

varwidth包用於將enumerate環境放入 TikZ 中node。看這個答案以獲得解釋。

\documentclass{article}

\usepackage{tikz}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{varwidth}

\begin{document}

Here, we will reference a label that is set on top of the picture with \verb|tikz| (\ref{fig:1}).

\begin{figure}[h!]
\centering
\begin{tikzpicture}
    \node at (0,0) {\includegraphics[width=.6\textwidth]{example-image}};
    \node at (1.2,2) {\begin{varwidth}{2in}\begin{enumerate}[label={Fig.~\arabic*}]\item{Hi, let's reference this\label{fig:1}}\end{enumerate}\end{varwidth}};
\end{tikzpicture}
\end{figure}

Here, we will do the opposite of this; we will put the \verb|\ref{...}| inside the \verb|node|, as a reference to example 1:

\begin{enumerate}

    \item{\label{ex:1}Example 1}

\end{enumerate}

\begin{figure}[h!]
\centering
\begin{tikzpicture}
    \node at (0,0) {\includegraphics[width=.6\textwidth]{example-image}};
    \node at (1.2,2) {Look at example~\ref{ex:1}};
\end{tikzpicture}
\end{figure}

\end{document}

在此輸入影像描述

相關內容