如何正确定位锚定 TikZ 节点中包含的图形?

如何正确定位锚定 TikZ 节点中包含的图形?

在这个 MWE 中,\myfig似乎水平移动了一半\pgflinewidth

\documentclass{article}
\usepackage{tikz}
\def\myfig{\includegraphics[height=1cm, width=\linewidth]{example-image-a4-numbered}}
% just fooling around:

\begin{document}

Reference:\\
\myfig

This works:\\
\begin{tikzpicture}
    \draw (0,0) node[inner sep=0] { \myfig };
\end{tikzpicture}

Overfull hbox (about 0.4pt too wide):\\
\begin{tikzpicture}
    \draw (0,0) node[inner sep=0, anchor=south west] { \myfig };
\end{tikzpicture}

Overfull hbox (about 0.2pt too wide):\\
\begin{tikzpicture}
    \draw (0,0) node[inner sep=0, anchor=south west, outer xsep=0] { \myfig };
\end{tikzpicture}

Overfull hbox (about 2pt too wide):\\
\begin{tikzpicture}
    \pgfsetlinewidth{10\pgflinewidth}
    \draw (0,0) node[inner sep=0, anchor=south west, outer xsep=0] { \myfig };
\end{tikzpicture}

Workaround:\\
\begin{tikzpicture}
    \pgfsetlinewidth{100\pgflinewidth}
    \draw (0,0) node[inner sep=0, anchor=south west, outer xsep=-\pgflinewidth/2] { \myfig };
\end{tikzpicture}

\end{document}

有没有比我正在使用的更好的解决方法?

相关内容