在 \begin{figure} 中画线并放置文字

在 \begin{figure} 中画线并放置文字

我有这个数字

在此处输入图片描述

\begin{figure}
    \centering
    \captionsetup[subfigure]{labelformat=empty}
    \includegraphics[width=\textwidth]{Figure_1.pdf}
    \caption{}
\end{figure}

我想在其上方画两条线,并在线的中间放置文字,如下图所示。

在此处输入图片描述

我尝试使用该\draw功能,但无法得到我想要的线条。我该怎么办?

\begin{figure}
    \centering
    \captionsetup[subfigure]{labelformat=empty}
    \begin{tikzpicture}
    \draw (-10,0) -- (3,0);
    \end{tikzpicture}
    \includegraphics[width=\textwidth]{Figure_1.pdf}
    \caption{}
\end{figure}

答案1

像这样?

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
    \centering
    \captionsetup[subfigure]{labelformat=empty}
%    \begin{tikzpicture}
%    \draw (-10,0) -- (3,0);
%    \end{tikzpicture}
        \hspace{0.75cm}
        \begin{minipage}{.78\textwidth}
            \centering
            text

            \rule{\textwidth}{2pt}
        \end{minipage}\hfill%
        \begin{minipage}{.1\textwidth}
            \centering
            text

            \rule{\textwidth}{2pt}
        \end{minipage}%
        \hspace{0.2cm}
        \vskip0.5em
    \includegraphics[width=\textwidth]{NpPlW}
    \caption{}
\end{figure}

\end{document}

在此处输入图片描述

答案2

这是使用 TikZ 的一种方法,它提供了一组旋钮以便于自定义,并为水平规则提供了圆形端点(当然,如果需要,可以更改)。如果您要添加多个这样的图例,这将非常方便,因为对于每个图例,您只需输入类似以下内容:

\draw[legend=from (startpoint) to (endpoint)
      with offset \myRuleOffset and width \myRuleWidth node somenodename
      label text {Some text} offset by \myLabelOffset
      rule options {fill=blue!40} label options {color=red!20!black}];

完整示例:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, fit}

\begin{document}

\begin{figure}
  \centering
  \begin{tikzpicture}[
      legend/.style args={from #1to #2with offset #3and width #4node #5label
                          text #6 offset by #7rule options #8 label options #9}{%
        insert path={
          let \p1 = ($#1 + (0,#3) + (0,#4)$),
              \p2 = ($#2 + (0,#3)$)
          in
          node[inner sep=0, fit=(\p1) (\p2), rounded corners=0.5*#4,
               #8, label={[label distance=#7, anchor=base, #9]above:{#6}}]
            (#5) {}
          }}]

    % Parameters shared between our two legends
    \def\myRuleOffset{0.5cm}
    \def\myRuleWidth{2pt}
    \def\myLabelOffset{0.25cm}

    % The image node
    \node[inner sep=0] (img)
      { \includegraphics[width=\linewidth]{example-image} };

    % The left legend stops a bit before two thirds of the image width
    \coordinate (rightEndOfLeftLegend) at
      ($ (img.north west)!0.65!(img.north east) $);
    % The right legends starts a bit after two thirds of the image width
    \coordinate (leftEndOfRightLegend) at
      ($ (img.north west)!0.68!(img.north east) $);

    % Left legend (creates a rectangle-shaped node named 'leftrule')
    \draw[legend=from (img.north west) to (rightEndOfLeftLegend)
          with offset \myRuleOffset and width \myRuleWidth node leftrule
          label text {Left label} offset by \myLabelOffset
          rule options {fill=blue!40} label options {color=red!20!black}];
    % Right legend (creates a rectangle-shaped node named 'rightrule')
    \draw[legend=from (leftEndOfRightLegend) to (img.north east)
          with offset \myRuleOffset and width \myRuleWidth node rightrule
          label text {Right label} offset by \myLabelOffset
          rule options {fill=orange!40} label options {color=red!20!black}];
  \end{tikzpicture}
  \caption{Your caption here}
\end{figure}

\end{document}

截屏

放大两个规则端点:

规则端点(放大)

当然,上述代码不依赖于任何figure环境——此环境在示例中仅用于演示目的。

相关内容