给定以下图形面板(多个图形)
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htp]
\setlength{\lineskip}{0pt}
\centering
\includegraphics[width=4cm]{snow.jpg}
\includegraphics[width=4cm]{snow.jpg}\\
\includegraphics[width=4cm]{snow.jpg}
\includegraphics[width=4cm]{snow.jpg}
\caption{Some caption}
\end{figure}
\end{document}
答案1
此示例使用tikz
和tikzmark
库来添加四个字母。
(您不需要理解 tikz 代码)
该命令\InsertLabels{<x offset>}{y offset}
将添加粗体字母A,b,C和d每幅图像的左上角都有一个 x-y 偏移。
在使用之前\InsertLabels
,您不应该(1)使用命令加载一张图像(假设四张图像具有相同的纵横比)\settoheight{\imageheight}{...
来确定图像的高度;(2)按照代码所示在所有四张图像\tikzmark{<unique name>}
之前添加所有图像。\includegraphics
使用命令\FontLabel
设置标签的字体。
不要混淆姓名这里使用的标记 a、b、c 和 d 与要插入到图像中的字母一起放在命令节点内的括号中,即{c}
。
\documentclass{article}
\usepackage{graphicx}
%**************************************************** added <<<<<<<<<<<<<
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\newlength{\imageheight}
\settoheight{\imageheight}{% measure the image height
\includegraphics[width=4cm]{example-image} % your image <<<<<<<<<<<<<<<<<
}
\newcommand{\FontLabel}{\sffamily\bfseries\large}% set the font of the labels <<<<<<<<
\newcommand{\InsertLabels}[2]{%
\begin{tikzpicture}[overlay,remember picture]
\node[font=\FontLabel] at ( $ (pic cs:a) +(#1,\imageheight-#2) $ ){a};%
\node[font=\FontLabel] at ( $ (pic cs:b) +(#1,\imageheight-#2) $ ){b};%
\node[font=\FontLabel] at ( $ (pic cs:c) +(#1,\imageheight-#2) $ ){c};%
\node[font=\FontLabel] at ( $ (pic cs:d) +(#1,\imageheight-#2) $ ){d};%
\end{tikzpicture}
}
%****************************************************
\begin{document}
\begin{figure}[htp]
\setlength{\lineskip}{0pt}
\centering
\tikzmark{a}\includegraphics[width=4cm]{example-image} % tikzmark added <<<<<<<<
\tikzmark{b}\includegraphics[width=4cm]{example-image}\\ % tikzmark added <<<<<<<<
\tikzmark{c}\includegraphics[width=4cm]{example-image} % tikzmark added <<<<<<<<
\tikzmark{d}\includegraphics[width=4cm]{example-image} % tikzmark added <<<<<<<<
\caption{Some caption}
\end{figure}
\InsertLabels{3ex}{3ex}% \InsertLabels{<x offset>}{y offset}
\end{document}
该tikzmark
库使用pic
坐标系,因此使用 来调用标记pic cs: mark name
。例如(pic cs:a)
。
该库calc
允许符号+(< xshift >, < yshift >)
引用原点的某个点。
仅使用两个节点即可获得等效结果tikz
:一个节点包含图像,另一个节点将粗体字母放置在图像内,并使用图像的左上角作为参考。
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}% added <<<<<<<<<<<<
\begin{document}
\begin{figure}[htp]
\setlength{\lineskip}{0pt}
\centering
\begin{tikzpicture}
\node[anchor=north west,inner sep=0pt] at (0,0){\includegraphics[width=4cm]{example-image}};
\node[font=\sffamily\bfseries\large] at (3ex,-3ex) {a};
\end{tikzpicture}
\begin{tikzpicture}
\node[anchor=north west,inner sep=0pt] at (0,0){\includegraphics[width=4cm]{example-image}};
\node[font=\sffamily\bfseries\large] at (3ex,-3ex) {b};
\end{tikzpicture}
\begin{tikzpicture}
\node[anchor=north west,inner sep=0pt] at (0,0){\includegraphics[width=4cm]{example-image}};
\node[font=\sffamily\bfseries\large] at (3ex,-3ex) {c};
\end{tikzpicture}
\begin{tikzpicture}
\node[anchor=north west,inner sep=0pt] at (0,0){\includegraphics[width=4cm]{example-image}};
\node[font=\sffamily\bfseries\large] at (3ex,-3ex) {d};
\end{tikzpicture}
\caption{Some caption}
\end{figure}
\end{document}