图形内两个函数图形下方的文本

图形内两个函数图形下方的文本

有没有办法在以下代码中的一些函数图下添加额外的文本?我需要它们在同一张图中并排出现在页面上,并且我不希望使用额外的标题。文本应该是单行解释。

\begin{figure}
   \begin{tikzpicture}
      \begin{axis}[
      width=0.45\textwidth,
      ...]
         \addplot [mark=*,mark size=0.7] {(1-x)^(1/3)}
      \end{axis}
      %%%% Add some text below this function plot <-----
   \end{tikzpicture}
   \begin{tikzpicture} 
      \begin{axis}[
      width=0.45\textwidth,
      ...]
         \addplot [mark=*,mark size=0.7] {x^3-x}
      \end{axis}
      %%%% Add some text below the second function plot <-----
   \end{tikzpicture}
 \begin{end}

答案1

您可以(误)使用标题。更改标题的位置并使用它。

\documentclass{Article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
   \begin{tikzpicture}[baseline=(current bounding box.north)]
      \begin{axis}[
      width=0.45\textwidth,clip=false,
      title style={at={(0.5,-0.2)},text width=0.45\textwidth,anchor=north,align=center},
      title={here comes some text below the first picture to demonstrate the dummy text.}
      ]
         \addplot [mark=*,mark size=0.7] {(1-x)^(1/3)};
      \end{axis}
   \end{tikzpicture}
   \begin{tikzpicture}[baseline=(current bounding box.north)]
      \begin{axis}[
      width=0.45\textwidth,
      title style={at={(0.5,-0.2)},text width=0.45\textwidth,anchor=north,align=center},
      title={here comes some text.}
      ]
         \addplot [mark=*,mark size=0.7] {x^3-x};
      \end{axis}
   \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

由于标签考虑了图片的宽度,居中的文本可能总是看起来有点偏离中心。

\documentclass{article}
\usepackage{pgfplots}
\usepackage{showframe}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}
    \begin{minipage}{.35\linewidth}
   \begin{tikzpicture}[baseline=(current bounding box.north)]
      \begin{axis}[
      width=\linewidth
      ]
         \addplot [mark=*,mark size=0.7] {(1-x)^(1/3)};
      \end{axis}
   \end{tikzpicture}%
   \par\centering text
   \end{minipage}\hfill%
    \begin{minipage}{.55\linewidth}
   \begin{tikzpicture}[baseline=(current bounding box.north)]
      \begin{axis}[
      width=\linewidth,
      ]
         \addplot [mark=*,mark size=0.7] {x^3-x};
      \end{axis}
   \end{tikzpicture}
   \par\centering text
   \end{minipage}

   \centering
   this is text, centered
   \end{figure}
\end{document}

如果您想节省一些输入,您可以将其放入某种宏中,但我认为这次不值得。

您可能正在寻找子标题?不错的宏,subcaption由包提供subcaption

答案3

如果您为轴指定一个名称,则可以通过其锚点(东北、西南等)访问边框。您还可以获得框的精确尺寸,它不是 0.45\textwidth。

\documentclass{standalone}
\usepackage{pgfplots}

\newlength{\tempwidth}

\begin{document}
\fbox{% no figures in standalone class
      \begin{tikzpicture}
      \begin{axis}[name=first,width=0.45\textwidth]
         \addplot [mark=*,mark size=0.7] {(1-x)^(1/3)};
      \end{axis}
      \pgfextractx{\tempwidth}{\pgfpointdiff{\pgfpointanchor{first}{west}}{\pgfpointanchor{first}{east}}}
      \node[below=3mm] at (first.south) 
        {\parbox{\tempwidth}{\centering Add some text below the first function}};
   \end{tikzpicture}
   \begin{tikzpicture} 
      \begin{axis}[name=second,width=0.45\textwidth]
         \addplot [mark=*,mark size=0.7] {x^3-x};
      \end{axis}
      \pgfextractx{\tempwidth}{\pgfpointdiff{\pgfpointanchor{second}{west}}{\pgfpointanchor{second}{east}}}
      \node[below=3mm] at (second.south) 
        {\parbox{\tempwidth}{\centering Add some text below the second function}};
   \end{tikzpicture}}
\end{document}

轴下方的文本

相关内容