我有一个tikzpicture
包含多个节点的环境。对于下面的 MWE 示例,我有两个节点 - 一个图像和另一个节点,相对于图像放置在左侧。
如果我使用一个简单的centering
命令,整个页面tikzpicture
就会水平居中。但是,我想要做的是让图像节点水平居中。我该如何实现呢?
\documentclass[12pt, a4paper]{article}
\usepackage[a4paper, total={17cm, 25cm}]{geometry}
\usepackage{tikz}
\begin{document}
This line shows the width of the text across the page as a visual guideline how the image is centered horizontally on the page.
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\node[anchor = south west, inner sep=0pt] (image) at (0,0)
{\includegraphics[width=.6\textwidth]{example-image-a}};
\begin{scope}[x = {(image.south east)},y = {(image.north west)}]
\node [anchor=east] at (-0.05,0.5) {annotation};
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
输出为:
我应该如何更改代码,以便 x 坐标image.center
在页面上水平居中?提前谢谢您。
答案1
我使用命令来完成\useasboundingbox
。如下所示:
\documentclass[12pt, a4paper]{article}
\usepackage[a4paper, total={17cm, 25cm}]{geometry}
\usepackage{tikz}
\begin{document}
This line shows the width of the text across the page as a visual guideline how the image is centered horizontally on the page.
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\node (image) at (0,0) {\includegraphics[width=.6\textwidth]{example-image-a}};
\useasboundingbox (image.south east) rectangle (image.north west); % <-- to center wrt this rectangle
\node at (image.west) [left] {annotation};
\end{tikzpicture}
\end{figure}
\end{document}