如何用线条和带圆圈的数字注释图形

如何用线条和带圆圈的数字注释图形

我想用 LaTeX 中的注释替换静态图像注释,使它们大小相同。我总是使用图形,有时也使用子图形。

我如何才能得到与图片中相同的线条,并且带有数字https://tex.stackexchange.com/a/7045/50965? 我可以重复使用那个带圈的代码吗?

注释图像

我尝试并搜索了一些 tikz 解决方案,但不熟悉如何解决这个问题。

该特定图像(在子图中)的代码是:

\documentclass{scrbook}
\usepackage{tikz}

\begin{figure}[tph]
\hspace{5mm}\subfloat[figure 1 description]{%
\begin{minipage}[b][1\totalheight][c]{0.4\columnwidth}%
\noindent \begin{center}
\includegraphics[width=1\columnwidth]{path/To/Image}
\par\end{center}%
\end{minipage}



}\hfill{}\subfloat[mentioned figure from question]{\noindent \begin{centering}
\begin{minipage}[b][5.5cm][c]{0.4\columnwidth}%
\noindent \begin{center}
\includegraphics[width=1\columnwidth]{path/To/Image}
\par\end{center}%
\end{minipage}
\par\end{centering}



}\hspace{5mm}

\protect\caption{de}


\end{figure}

答案1

这很简单,也可能是重复的。无论如何,我都会发布此内容,如果此内容被关闭,我将删除此答案。

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0,0) {\includegraphics[width=4in]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        %% next four lines will help you to locate the point needed by forming a grid. comment these four lines in the final picture.↓
  %      \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
%        \draw[help lines,xstep=.05,ystep=.05] (0,0) grid (1,1);
%        \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
%        \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y};}
        %% upto here↑
        \draw[dashed,-latex] (0.8,0.8) -- +(1.1in,0.2in)node[anchor=west] {1};
        \draw[dashed,-latex] (0.6,0.6) -- +(1.9in,0)node[anchor=west] {2};
        \draw[dashed,-latex] (0.4,0.5) -- +(-2in,0)node[anchor=east] {3};
        \draw[dashed,-latex] (0.5,0.4) -- +(-2.4in,-0.5in)node[anchor=east] {4};
    \end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

您可以在常规fu=igures/ subfigures 中使用它,就像这样。我修改了minipage尺寸。在您的情况下将其回滚。此外,使用\centering比更好\begin{center}... \end{center}

\documentclass{article}
\usepackage{subfig}
\usepackage{tikz}
\tikzset{mynode/.style={draw,solid,circle,inner sep=1pt}}
\begin{document}
\begin{figure}[tph]
\subfloat[figure 1 description]{%
\begin{minipage}{0.4\columnwidth}%
\centering
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0,0) {\includegraphics[width=0.5\columnwidth]{example-image-a}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \draw[dashed,-latex] (0.8,0.8) -- +(1.1cm,0.2cm)node[mynode,anchor=west] {1};
        \draw[dashed,-latex] (0.6,0.6) -- +(1.9cm,0)node[mynode,anchor=west] {2};
        \draw[dashed,-latex] (0.4,0.5) -- +(-2cm,0)node[mynode,anchor=east] {3};
        \draw[dashed,-latex] (0.5,0.4) -- +(-2.4cm,-0.5cm)node[mynode,anchor=east] {4};
    \end{scope}
\end{tikzpicture}
\end{minipage}
}\hfill{}
\subfloat[mentioned figure from question]{
\centering
\begin{minipage}{0.4\columnwidth}%
\centering
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0,0) {\includegraphics[width=0.5\columnwidth]{example-image-B}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \draw[dashed,-latex] (0.8,0.8) -- +(1.1cm,0.2cm)node[mynode,anchor=west] {1};
        \draw[dashed,-latex] (0.6,0.6) -- +(1.9cm,0)node[mynode,anchor=west] {2};
        \draw[dashed,-latex] (0.4,0.5) -- +(-2cm,0)node[mynode,anchor=east] {3};
        \draw[dashed,-latex] (0.5,0.4) -- +(-2.4cm,-0.5cm)node[mynode,anchor=east] {4};
    \end{scope}
\end{tikzpicture}
\end{minipage}
}
\caption{de}
\end{figure}
\end{document}

在此处输入图片描述

您可以定义style一个node

\tikzset{mynode/.style={draw,solid,circle,inner sep=1pt}}

并像使用它一样

\draw[dashed,-latex] (0.8,0.8) -- +(1.1cm,0.2cm)node[mynode,anchor=west] {1};

来自@Hug 的附录:

这个答案很有帮助,但我还想展示完整的答案以获得理想的结果,同时还具有以下令人高兴的副作用:

  • 图像比例不可知论(通过相对位置,而不是厘米)
  • 白色填充圆圈数字,因此可以将它们放在图形内(通过样式选项实现)
  • 使用样式根据配色方案轻松为线条着色(我使用 Adob​​e kuler web 应用程序为我自己定制配色方案)
  • 线条末端无箭头(无 -latex 选项)

这产生了以下 MWE(有 8 种不同颜色可供选择):

\documentclass{scrbook}
\usepackage{tikz}
%colors
\definecolor{1c1}{RGB}{188,162,6}
\definecolor{1c2}{RGB}{137,129,80}
\definecolor{1c3}{RGB}{239,167,31}
\definecolor{1c4}{RGB}{88,194,241}
\definecolor{1c5}{RGB}{6,180,188}

% stiles used
\tikzset{mynode/.style={draw=black,solid,circle,fill=white,inner sep=2pt, thick, text=black}}
%draw=black to get a black circle, fill=white so it actually has a   
%background and text=black to not get that rendered in the specified color
\tikzset{arrow line/.style={dashed, line width= 2.5pt, color=#1}}
%color is given as a paramter so one can put these two styles in the  
%preamble and easily use throughout the document, line width as it was to small on my images on a page

\begin{figure}[tbph]
\hspace{5mm}\subfloat[figure a]{%
\begin{minipage}[b][1\totalheight][c]{0.4\columnwidth}%
\noindent \begin{center}
\includegraphics[width=1\columnwidth]{path/to/image_a}
\par\end{center}%
\end{minipage}



}\hfill{}\subfloat[description of figure a]{\noindent \centering%
\begin{minipage}[b][5cm][c]{0.4\columnwidth}%
\noindent \begin{center}
\centering
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0,0) {\includegraphics[width=0.7\columnwidth]{path/to/image}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
% uncomment the 4 lines for a grid to help with positioning
        % \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
        % \draw[help lines,xstep=.05,ystep=.05] (0,0) grid (1,1);
        % \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
        % \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y};}

% uncomment until line above
        \draw[arrow line=1c1] (0.8,0.8) -- +(0.275,0)node[mynode,anchor=west] {\Large 1};
%1c1 is the code for the color, you can enter 1c2 here, too
        \draw[arrow line=1c1] (0.6,0.55) -- +(0.475,0)node[mynode,anchor=west] {\Large 2};
        \draw[arrow line=1c1] (0.35,0.45) -- +(-0.425,0)node[mynode,anchor=east] {\Large 3};
        \draw[arrow line=1c1] (0.375,0.275) -- +(-0.45,-.15)node[mynode,anchor=east] {\Large 4};
    \end{scope}
\end{tikzpicture}
\par\end{center}%
\end{minipage}

}\hspace{5mm}

\protect\caption{outside caption}


\end{figure}

得到如下图像:

最终生成的图像

所以,非常感谢 Harish Kumar,没有他的帮助我不可能实现这个目标。

相关内容