图片周围的坐标框

图片周围的坐标框

我想在图片周围绘制如下框架,而不改变图片的比例。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
   \begin{tikzpicture}[gray,thin]
        \draw (-6,0) rectangle (6,7);
        %bottom marks
        \foreach \x in {-6,-5.6,..., 6} 
        \draw (\x,0) -- (\x, .1) ;            
        \foreach \x/\num in {-4/-1.0,-2/-0.5,0/0.0,2/0.5,4/1.0}
        \draw (\x,0) node[below]{$\num$}-- (\x,.2);

        %top marks
        \foreach \x in {-6,-5.6,..., 6} 
        \draw (\x,7) -- (\x, 6.9) ;            
        \foreach \x in {-4,-2,...,4}
        \draw (\x,7)-- (\x,6.8);

        %left marks
        \foreach \y in {0,0.35,...,7}
        \draw (-6,\y) -- (-5.9,\y);
        \foreach \y/\num in {1.4/-0.5,2.8/0.0,4.2/0.5,5.6/1.0} 
        {
        \draw (-6,\y) node[left]{$\num$} -- (-5.8,\y);
        }

        %right marks
        \foreach \y in {0,0.35,...,7}
        \draw (6,\y) -- (5.9,\y);
        \foreach \y in {1.4,2.8,...,5.7} 
         {
         \draw (6,\y) -- (5.8,\y);
         }
    \end{tikzpicture}
    \end{figure}
\end{document}

我的主要问题是我不知道如何让框架与图片匹配而不使图片变形。我首先在图片周围放置一个矩形,但我不知道如何以方便的方式放置刻度线。我想,我需要西南角和东北角的坐标。有办法得到它们吗?

答案1

像这样吗?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{graphicx}
\begin{document}
\begin{figure}
  \centering
  \begin{tikzpicture}[gray,thin,
    Frame/.style={gray},
    Tick/.style={gray},
    SubTick/.style={gray},
    ]
    \node[inner sep=0pt](Img){\includegraphics[scale=0.7]{example-image}};
    \coordinate(LL) at (Img.south west);%% Lower left corner
    \coordinate(LR) at (Img.south east);%% Lower right corner
    \coordinate(UL) at (Img.north west);%% Upper left corner
    \coordinate(UR) at (Img.north east);%% Upper right corner
    %%
    \draw[Frame] (LL) rectangle (UR);
    \foreach \subtick [evaluate=\subtick as \subpos using \subtick/20] in {1,...,20}{%
      \draw[SubTick]($(LL)!\subpos!(UL)$)--+(0.2,0);
      \draw[SubTick]($(LR)!\subpos!(UR)$)--+(-0.2,0);
      \draw[SubTick]($(LL)!\subpos!(LR)$)--+(0,0.2);
      \draw[SubTick]($(UL)!\subpos!(UR)$)--+(0,-0.2);
    }
    \foreach \tick [evaluate=\tick as \pos using \tick/4,evaluate=\tick as \lab using -1+\tick*0.5] in {0,...,4}{%
      \draw[Tick] ($(LL)!\pos!(UL)$)--+(0.4,0)node[pos=0,left]{$\lab$};
      \draw[Tick] ($(LR)!\pos!(UR)$)--+(-0.4,0)node[pos=0,right]{$\lab$};
      \draw[Tick] ($(LL)!\pos!(LR)$)--+(0,0.4)node[pos=0,below]{$\lab$};
      \draw[Tick] ($(UL)!\pos!(UR)$)--+(0,-0.4)node[pos=0,above]{$\lab$};
    }
  \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

相关内容