7

I am really new to Latex and this has been my place of reference for the last weeks, so I wanted to ask you about a really weird thing that I have no clue how to solve... Following this thread: Plotting bell shaped curve in TikZ-PGF I am trying to include Normal distributions inside a minipage and node, but strangely, while the distributions outside the minipage look correct, inside it they sort of lose resolution... I am including a working example below. I would really appreciate your help. Thanks a lot in advance!

\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}
DaniCee
  • 2,217
  • Apart from the "resolution issue", I would like that more than one tikzpictures of distributions appear side by side in each minipage (3 per minipage)... any clue? – DaniCee Jun 23 '13 at 00:41

1 Answers1

9

The problem is not the minipage; the problem is nesting tikzpictures, since this causes the settings to be inherited by the inner picture; in particular, your plot inherits the rounded corner option and this obviously distorts the image.

One way to prevent this, in this particular case, is to use the sharp corners for the inner picture, thus annhilating the outer rounded corners (thanks to Jake for this suggestion):

\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}

Another option, specially useful if there are many possible outer settings that shouldn't be inherited, is to previously save the plot in a box, and then use it:

\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}

Another (in my opinion better) solution, is to avoid nesting tikzpictures altogether. You can produce the framed box differently using, for example, the mdframed package. An example with two plots in one 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}

enter image description here

An example with two plots each one in its mdframed (side-by-side):

\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}

enter image description here

Gonzalo Medina
  • 505,128
  • Aaah I see! your solution works like a charm, many thanks Gonzalo! – DaniCee Jun 23 '13 at 00:51
  • mdframed looks like a cleaner solution, just out of curiosity: how would I place two mdframes next to each other? – DaniCee Jun 23 '13 at 01:01
  • @user32674 please see my updated answer with an example having two side-by-side mdframed environments. – Gonzalo Medina Jun 23 '13 at 01:15
  • Many thanks Gonzalo, I'm implementing the solution with mdframed and works perfectly!! just one last little question... can I make the inside of the boxes transparent instead of white? Thanks! – DaniCee Jun 23 '13 at 15:32