minipage 和 node 内的高斯曲线

minipage 和 node 内的高斯曲线

我对 Latex 还很陌生,这是我过去几周的参考地点,所以我想问你一个非常奇怪的事情,我不知道如何解决...按照这个线索:在 TikZ-PGF 中绘制钟形曲线我正在尝试在迷你页面和节点内包含正态分布,但奇怪的是,迷你页面外的分布看起来正确,但在迷你页面内,它们有点失去分辨率……我在下面提供了一个工作示例。我非常感谢您的帮助。提前谢谢!

\documentclass[ignorenonframetext, xcolor={dvipsnames,table}]{beamer}
\mode<presentation> {
\usetheme{Berkeley}
\usecolortheme{dolphin}

\usepackage{tikz} %for transparency
\usetikzlibrary{positioning,shadows,calc}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
}


\begin{document}

\begin{frame}
\begin{center}
\begin{tikzpicture} %these distributions look flawless, but I don't want to picture them
    \begin{axis}[
    no markers, domain=0:10, samples=100, smooth,
    axis lines*=left,
    height=3cm, width=5cm,
    xtick=\empty, ytick=\empty,
    enlargelimits=upper, clip=false,
    grid=major]
    \addplot [cyan!50!black] {gauss(4,0.5)};
    \addplot [thick,cyan!50!black] {gauss(6,1)};
    \end{axis}
\end{tikzpicture}

\begin{minipage}{\textwidth}
    \begin{tikzpicture}
        \node[text width=.985\textwidth,
        draw=green!70!black,
        line width=3pt,
        inner sep=7.5pt,
        rounded corners,
        outer sep=0pt] at (0,0) {
            \small{\textcolor{green!70!black}{Tissue-specific expression\\}}
            \begin{tikzpicture} %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}
        };
    \end{tikzpicture}
\end{minipage}
\begin{minipage}{\textwidth}
    \begin{tikzpicture}
        \node[text width=.985\textwidth,
        draw=pink,
        line width=3pt,
        inner sep=7.5pt,
        rounded corners,
        outer sep=0pt] at (0,0) {
        \small{\textcolor{pink}{Ubiquitous expression}}


        };
    \end{tikzpicture}
\end{minipage}
\end{center}
\end{frame}


\end{document}

答案1

问题不在于minipage;问题在于嵌套tikzpicture,因为这会导致设置被内部图片继承;特别是,您的图继承了选项rounded corner,这显然会扭曲图像。

在这种特殊情况下,防止这种情况的一种方法是使用sharp corners内部图片,从而消除外部rounded corners(这要归功于杰克对于此建议):

\documentclass[ignorenonframetext, xcolor={dvipsnames,table}]{beamer}
\mode<presentation> {
\usetheme{Berkeley}
\usecolortheme{dolphin}

\usepackage{tikz} %for transparency
\usetikzlibrary{positioning,shadows,calc}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
}


\begin{document}

\begin{frame}
\begin{center}
\begin{tikzpicture} %these distributions look flawless, but I don't want to picture them
    \begin{axis}[
    no markers, domain=0:10, samples=100, smooth,
    axis lines*=left,
    height=3cm, width=5cm,
    xtick=\empty, ytick=\empty,
    enlargelimits=upper, clip=false,
    grid=major]
    \addplot [cyan!50!black] {gauss(4,0.5)};
    \addplot [thick,cyan!50!black] {gauss(6,1)};
    \end{axis}
\end{tikzpicture}

\begin{minipage}{\textwidth}
    \begin{tikzpicture}
        \node[text width=.985\textwidth,
        draw=green!70!black,
        line width=3pt,
        inner sep=7.5pt,
        rounded corners,
        outer sep=0pt] at (0,0) {
            \small{\textcolor{green!70!black}{Tissue-specific expression\\}}
            \begin{tikzpicture}[sharp corners] %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}
        };
    \end{tikzpicture}
\end{minipage}
\begin{minipage}{\textwidth}
    \begin{tikzpicture}
        \node[text width=.985\textwidth,
        draw=pink,
        line width=3pt,
        inner sep=7.5pt,
        rounded corners,
        outer sep=0pt] at (0,0) {
        \small{\textcolor{pink}{Ubiquitous expression}}


        };
    \end{tikzpicture}
\end{minipage}
\end{center}
\end{frame}


\end{document}

另一个选项特别有用,如果存在许多不应该继承的外部设置,那就是先前将图保存在一个框中,然后使用它:

\documentclass[ignorenonframetext, xcolor={dvipsnames,table}]{beamer}
\mode<presentation> {
\usetheme{Berkeley}
\usecolortheme{dolphin}

\usepackage{tikz} %for transparency
\usetikzlibrary{positioning,shadows,calc}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
}

\newsavebox\mybox
\savebox\mybox{%
            \begin{tikzpicture} %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}%
}
\begin{document}

\begin{frame}
\begin{center}
\begin{tikzpicture} %these distributions look flawless, but I don't want to picture them
    \begin{axis}[
    no markers, domain=0:10, samples=100, smooth,
    axis lines*=left,
    height=3cm, width=5cm,
    xtick=\empty, ytick=\empty,
    enlargelimits=upper, clip=false,
    grid=major]
    \addplot [cyan!50!black] {gauss(4,0.5)};
    \addplot [thick,cyan!50!black] {gauss(6,1)};
    \end{axis}
\end{tikzpicture}

    \begin{tikzpicture}
        \node[text width=.985\textwidth,
        draw=green!70!black,
        line width=3pt,
        inner sep=7.5pt,
        rounded corners,
        outer sep=0pt] at (0,0) {
            {\small\textcolor{green!70!black}{Tissue-specific expression\\}}
            \usebox\mybox
        };
    \end{tikzpicture}

\begin{minipage}{\textwidth}
    \begin{tikzpicture}
        \node[text width=.985\textwidth,
        draw=pink,
        line width=3pt,
        inner sep=7.5pt,
        rounded corners,
        outer sep=0pt] at (0,0) {
        \small{\textcolor{pink}{Ubiquitous expression}}


        };
    \end{tikzpicture}
\end{minipage}
\end{center}
\end{frame}


\end{document}

另一个(我认为更好的)解决方案是避免嵌套tikzpicture完全避免嵌套 s。例如,您可以使用以下方法以不同的方式生成框架框:框架包中有两个图的示例mdframed

\documentclass[ignorenonframetext, xcolor={dvipsnames,table}]{beamer}
\mode<presentation> {
\usetheme{Berkeley}
\usecolortheme{dolphin}
\usepackage[framemethod=tikz]{mdframed}

\usepackage{tikz} %for transparency
\usetikzlibrary{positioning,shadows,calc}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
}

\begin{document}

\begin{frame}

\begin{mdframed}[
  innerlinewidth=3pt,
  innerlinecolor=green!70!black,
  roundcorner=5pt,
  middlelinewidth=0pt]
            \begin{tikzpicture} %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}\quad%
            \begin{tikzpicture} %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}%
\end{mdframed}

\end{frame}


\end{document}

在此处输入图片描述

一个具有两个图的示例mdframed(并排):

\documentclass[ignorenonframetext, xcolor={dvipsnames,table}]{beamer}
\mode<presentation> {
\usetheme{Berkeley}
\usecolortheme{dolphin}
\usepackage[framemethod=tikz]{mdframed}

\usepackage{tikz} %for transparency
\usetikzlibrary{positioning,shadows,calc}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
    \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
}

\newenvironment{MyFrame}
  {\begin{mdframed}[
  skipabove=\topsep,
  skipbelow=\topsep,
  innerlinewidth=3pt,
  innerlinecolor=green!70!black,
  roundcorner=5pt,
  middlelinewidth=0pt]
  }
  {\end{mdframed}}


\begin{document}

\begin{frame}

\begin{minipage}{.48\textwidth}
\begin{MyFrame}
\centering
            \begin{tikzpicture} %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}\quad%
\end{MyFrame}%
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\begin{MyFrame}
\centering
            \begin{tikzpicture} %these distributions look really distorted, and are the ones I want to include, inside the minipage
                \begin{axis}[
                no markers, domain=0:10, samples=100, smooth,
                axis lines*=left,
                height=3cm, width=5cm,
                xtick=\empty, ytick=\empty,
                enlargelimits=upper, clip=false,
                grid=major]
                \addplot [cyan!50!black] {gauss(4,0.5)};
                \addplot [thick,cyan!50!black] {gauss(6,1)};
                \end{axis}
            \end{tikzpicture}%
\end{MyFrame}
\end{minipage}%
\end{frame}


\end{document}

在此处输入图片描述

相关内容