tikz图片和文本并排

tikz图片和文本并排

我有几个 tikzpicture,旁边有一个解释或方程式。作为示例,我使用以下一个。

我想要获得这个:

在此处输入图片描述

当我使用独立文档类时,我获得了它;但是当我将其更改为我正在处理的类时,右侧部分明显向下。我尝试制作一个两列表,但没有成功。

在此处输入图片描述

没有表格的我的 MWE 如下:

\documentclass[14pt]{extarticle}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{amsmath}
\usepackage{xltabular}

\pgfkeys{/pgfplots/Axis Style/.style={
width=7.5cm, height=8cm,
axis x line=center, 
axis y line=middle, 
samples=100,
ymin=-1.5, ymax=5.5,
xmin=-7.0, xmax=7.0,
domain=-2*pi:2*pi
}}

\begin{document}

\begin{minipage}{0.5\linewidth}
\begin{tikzpicture}
\begin{axis}[
Axis Style,
xtick={
    -6.28318, -3.14159, 3.14159, 6.28318
},
xticklabels={
    $-2\pi$, $-\pi$, $\pi$, $2\pi$
}
\addplot[red,ultra thick,smooth,domain=0:pi] {4};
\addplot[red,ultra thick,smooth,domain=-3:0] {0};
\addplot[red,ultra thick,smooth,domain=pi:2*pi] {0};
\draw[black,fill=white] (axis cs:0,2) circle(1mm) (axis cs:( -3.14159,2) 
circle(1mm) (axis cs:(3.14159,2) circle(1mm) (axis cs:(6.28318,2) 
circle(1mm);
\draw[dashed]  (-6.28318,0) -- (-6.28318,5) ( -3.14159,0) -- ( -3.14159,5);
\draw[dashed] (6.28318,0) -- (6.28318,5) (3.14159,0) -- (3.14159,5);
\end{axis}
\end{tikzpicture}
\end{minipage}

\hspace{2.725in}
\begin{tabularx}{0.4\linewidth}{X}
\[x = \epsilon [-\pi,\pi] \] \\
\[2L = 2\pi \] \\
\[ L=\pi \]
\end{tabularx}

\end{document}

我怎样才能解决这个问题?

答案1

您遇到了编译错误,请不要忽略这些错误(结束])。另外,将您的方程式放入另一个minipage环境中,应该可以解决问题

\documentclass[14pt]{extarticle}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{amsmath}
\usepackage{tabularx}

\pgfkeys{/pgfplots/Axis Style/.style={
    width=7.5cm, height=8cm,
    axis x line=center, 
    axis y line=middle, 
    samples=100,
    ymin=-1.5, ymax=5.5,
    xmin=-7.0, xmax=7.0,
    domain=-2*pi:2*pi
  }}

\begin{document}

\begin{minipage}{0.5\linewidth}
  \begin{tikzpicture}
    \begin{axis}[
      Axis Style,
      xtick={
        -6.28318, -3.14159, 3.14159, 6.28318
      },
      xticklabels={
        $-2\pi$, $-\pi$, $\pi$, $2\pi$
      }
      ] % << added this
      \addplot[red,ultra thick,smooth,domain=0:pi] {4};
      \addplot[red,ultra thick,smooth,domain=-3:0] {0};
      \addplot[red,ultra thick,smooth,domain=pi:2*pi] {0};
      \draw[black,fill=white] (axis cs:0,2) circle(1mm) (axis cs:( -3.14159,2) 
      circle(1mm) (axis cs:(3.14159,2) circle(1mm) (axis cs:(6.28318,2) 
      circle(1mm);
      \draw[dashed]  (-6.28318,0) -- (-6.28318,5) ( -3.14159,0) -- ( -3.14159,5);
      \draw[dashed] (6.28318,0) -- (6.28318,5) (3.14159,0) -- (3.14159,5);
    \end{axis}
  \end{tikzpicture}
\end{minipage}
%
\begin{minipage}{0.5\linewidth}
\begin{align*}
    x \in [-\pi,\pi]  \\
    2L = 2\pi \\
    L=\pi 
  \end{align*}
  \vfill
\end{minipage}


\end{document}

在此处输入图片描述

答案2

只是为了完整性:提案没有小页面、表格等,而只是使用pgfplots内置的功能描述。

\documentclass[14pt]{extarticle}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{amsmath}

\pgfkeys{/pgfplots/Axis Style/.style={
width=7.5cm, height=8cm,
axis x line=center, 
axis y line=middle, 
samples=100,
ymin=-1.5, ymax=5.5,
xmin=-7.0, xmax=7.0,
domain=-2*pi:2*pi,
title style={at={(1,0.5)}}
}}

\begin{document}

\begin{tikzpicture}
\begin{axis}[name=plot1,
extra description/.code={
            \node[anchor=west,align=left] (description1) at (1.1,0.5) {$x \in [-\pi,\pi]$\\
            $2L = 2\pi$\\ $L=\pi$};
        },
Axis Style,
xtick={
    -6.28318, -3.14159, 3.14159, 6.28318
},
xticklabels={
    $-2\pi$, $-\pi$, $\pi$, $2\pi$
}]
\addplot[red,ultra thick,smooth,domain=0:pi] {4};
\addplot[red,ultra thick,smooth,domain=-3:0] {0};
\addplot[red,ultra thick,smooth,domain=pi:2*pi] {0};
\draw[black,fill=white] (axis cs:0,2) circle(1mm) (axis cs:( -3.14159,2) 
circle(1mm) (axis cs:(3.14159,2) circle(1mm) (axis cs:(6.28318,2) 
circle(1mm);
\draw[dashed]  (-6.28318,0) -- (-6.28318,5) ( -3.14159,0) -- ( -3.14159,5);
\draw[dashed] (6.28318,0) -- (6.28318,5) (3.14159,0) -- (3.14159,5);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

正如您所说,您需要做其中的几个,因此我想推荐组图(pgfplots 手册第 5.8 节)。

相关内容