如何在 TiKz 中打印与其边框之一对齐的 \pic?

如何在 TiKz 中打印与其边框之一对齐的 \pic?

以下 MWE 显示了如何绘制具有缩放比例的背景图像并向其中添加预定义的“PowerSupply”图片。这很有效,但问题是,我想要设置图片的位置需要与其边框之一对齐(取决于使用的角度)。

在这种情况下,我将图片旋转了 270°。我给出的安装位置是在\pic at (3590,2000) {PowerSupply};门下方所示墙壁的左侧。这个位置完全合适,但图片位置可能与他的中心位置对齐。因此图片显示在墙的“内部”。我想将它与北边界对齐(在这种情况下,因为角度为 270°),使其在左边几个点处。

\documentclass{article}%
\usepackage[a4paper,left=10mm,right=10mm,top=10mm,bottom=10mm]{geometry}%
\usepackage{courier}%
\usepackage[T1]{fontenc}%
\usepackage[parfill]{parskip}%
\usepackage[utf8]{inputenc}%
\usepackage{caption}%
\usepackage{graphicx}%
\usepackage{tikz}%
\tikzset{
PowerSupply/.pic={
\node{\includegraphics[scale=0.09,angle=270]{powerSupply.png}};},
}

\begin{document}
\pagenumbering{gobble}
\vspace*{\fill}
\begin{figure}[h!]
\centering
\scalebox{1.0}{
\begin{tikzpicture}[x=0.01mm, y=-0.01mm]
\node[inner sep=0pt] (ground_floor) {\includegraphics[width=99.0mm,height=107.4mm]{groundFloor.png}};
\tikzset{shift=(ground_floor.north west)}
[![enter image description here][1]][1]
\draw[blue, ->, line width=1pt] (0,0) -- (10000,0);
\foreach \x in {0,1000,...,9000} \draw[blue, line width=1pt] (\x,-100) --node[black, above=1mm]{\tiny\x mm} (\x,100);

\draw[blue, ->, line width=1pt] (0,0) -- (0,11000);
\foreach \y in {0,1000,...,10000} \draw[blue, line width=1pt] (-100,\y) --node[black, left=1mm]{\tiny\y mm} (100,\y);

\pic at (3590,2000) {PowerSupply};
\end{tikzpicture}}
\caption{Ground Floor}
\end{figure}
\vfill
\clearpage
\end{document}

例子

示例图片 一楼

电源

答案1

您只需将一个设置anchor为节点并将设置inner sep为 0pt 即可:

\documentclass{article}
\usepackage[a4paper, margin=10mm]{geometry}
\usepackage{tikz}

\tikzset{
    PowerSupply/.pic={
        \node[anchor=east, inner sep=0pt]{\includegraphics[scale=0.09, angle=270]{powerSupply}};
    },
}

\begin{document}
\pagenumbering{gobble}
\vfill
\begin{figure}[h!]
\centering
\begin{tikzpicture}[x=0.01mm, y=-0.01mm]
    \node[inner sep=0pt] (ground_floor)   
        {\includegraphics[width=99.0mm, height=107.4mm]{groundFloor}};
    
    \begin{scope}[shift=(ground_floor.north west)]
        \draw[blue, ->, line width=1pt] (0,0) -- (10000,0);
        \draw[blue, ->, line width=1pt] (0,0) -- (0,11000);
        
        \foreach \x in {0,1000,...,9000} {
            \draw[blue, line width=1pt] (\x,-100) -- 
                node[black, above=1mm] {\tiny\x mm} (\x,100);
        }
        \foreach \y in {0,1000,...,10000} {
            \draw[blue, line width=1pt] (-100,\y) --
                node[black, left=1mm]{\tiny\y mm} (100,\y);
        }
        
        \pic at (3590,2000) {PowerSupply};
    \end{scope}
\end{tikzpicture}
\caption{Ground Floor}
\end{figure}
\vfill
\clearpage
\end{document}

在此处输入图片描述

为了能够自由旋转\pic,也许最好旋转\pic而不是图片中节点内的图像:

\tikzset{
    PowerSupply/.pic={
        \node[anchor=north, inner sep=0pt]{\includegraphics[scale=0.09]{powerSupply}};
    },
}

\pic[rotate=270, transform shape] at (3590,2000) {PowerSupply};

这种简单的符号也可以用 Ti直接 Z:

\documentclass{article}
\usepackage[a4paper, margin=10mm]{geometry}
\usepackage{tikz}

\tikzset{
    PowerSupply/.pic={
        \begin{scope}[scale=350]
            \draw[red, thick, line cap=round] 
                (0,0) -- (0,0.5)
                (-0.5,0.5) -- (0.5,0.5)
                (-0.5,1) arc[start angle=180, end angle=360, radius=0.5];
        \end{scope}
    },
}

\begin{document}
\pagenumbering{gobble}
\vfill
\begin{figure}[h!]
\centering
\begin{tikzpicture}[x=0.01mm, y=-0.01mm]
    \node[inner sep=0pt] (ground_floor)   
        {\includegraphics[width=99.0mm, height=107.4mm]{groundFloor}};
    
    \begin{scope}[shift=(ground_floor.north west)]
        \draw[blue, ->, line width=1pt] (0,0) -- (10000,0);
        \draw[blue, ->, line width=1pt] (0,0) -- (0,11000);
        
        \foreach \x in {0,1000,...,9000} {
            \draw[blue, line width=1pt] (\x,-100) -- 
                node[black, above=1mm] {\tiny\x mm} (\x,100);
        }
        \foreach \y in {0,1000,...,10000} {
            \draw[blue, line width=1pt] (-100,\y) --
                node[black, left=1mm]{\tiny\y mm} (100,\y);
        }

        \pic[rotate=270] at (3590,2000) {PowerSupply};
    \end{scope}
\end{tikzpicture}
\caption{Ground Floor}
\end{figure}
\vfill
\clearpage
\end{document}

在此处输入图片描述

相关内容