
Следующий код принадлежит @domenico-camasta
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\node(a){\includegraphics[width=0.8\textwidth]{example-image-a}};
\node at (a.north east)
[
anchor=center,
xshift=0mm,
yshift=0mm
]
{
\includegraphics[width=0.3\textwidth]{example-image-b}
};
\end{tikzpicture}
\end{figure}
\end{document}
Смотрите такжеНаложить два изображения в статье
Как мне нужно переписать
a.north east
в примере выше, если я хочу разместить изображение B:
1) в центре изображения А
2) в центре к востоку от изображения А?
решение1
Посмотрите в главе 72руководство по tikz и pgfо shape
библиотеке. Там вы найдете список форм узлов и для каждой из них показана диаграмма с предопределенными якорями, похожая на эту для rectangle
формы по умолчанию:
(Обратите внимание, что якоря 10
и 130
являются всего лишь примерами, вы можете использовать любую степень от 0 до 360.)
Следовательно, вам нужны якоря center
и east
, как в коде ниже.
Обратите внимание также, что вы, вероятно, захотите установить inner sep=0
для a
узла, чтобы удалить «отступ» между содержимым узла и границей.
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\node [inner sep=0] (a){\includegraphics[width=0.8\textwidth]{example-image}};
\node at (a.north east)
[
anchor=center,
xshift=0mm,
yshift=0mm
]
{
\includegraphics[width=0.3\textwidth]{example-image-a}
};
\node at (a.center) {\includegraphics[width=0.3\textwidth]{example-image-b}};
\node at (a.east) {\includegraphics[width=0.3\textwidth]{example-image-c}};
\end{tikzpicture}
\end{figure}
\end{document}
решение2
Позиционирование по умолчанию — с использованием center
, а якорь по умолчанию — center
, поэтому просто node at (a)
поместим узел в a.center
. Положение «центр-восток» — просто east
, соответственно.
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\node(a)[inner sep=0pt]{\includegraphics[width=0.8\textwidth]{example-image-a}};
\node at (a)
{
\includegraphics[width=0.3\textwidth]{example-image-b}
}
node at (a.east)
{
\includegraphics[width=0.3\textwidth]{example-image-b}
};
\end{tikzpicture}
\end{figure}
\end{document}