4

Consider the following snippet:

\documentclass{article}
\pagestyle{empty}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.35,baseline=(current axis.south)]
    \begin{axis}[axis lines=none,samples=100,domain=-10*pi:10*pi]
    \addplot [mark=none]{sin(deg(x-pi))/(x-pi)}; 
    \addplot [mark=none]{sin(deg(x+pi))/(x+pi)}; 
    \addplot [mark=none,color=red]{sin(deg(x+pi))/(x+pi) + sin(deg(x-pi))/(x-pi)}; 
    \draw[dashed,blue] (axis cs:pi,-5) -- (axis cs:pi,20);
    \draw[dashed,blue] (axis cs:-pi,-5) -- (axis cs:-pi,20);
    \end{axis}
\end{tikzpicture}
\begin{tikzpicture}[scale=0.35,baseline=(current axis.south)]
    \begin{axis}[axis lines=none,samples=100,domain=-10*pi:10*pi]
    \addplot [mark=none]{sin(deg(0.5*(x-pi)))/(0.5*(x-pi))}; 
    \addplot [mark=none]{sin(deg(0.5*(x+pi)))/(0.5*(x+pi))}; 
    \addplot [mark=none,color=red]{sin(deg(0.5*(x+pi)))/(0.5*(x+pi)) + sin(deg(0.5*(x-pi)))/(0.5*(x-pi))}; 
    \draw[dashed,blue] (axis cs:pi,-5) -- (axis cs:pi,20);
    \draw[dashed,blue] (axis cs:-pi,-5) -- (axis cs:-pi,20);
    \end{axis}
\end{tikzpicture}
test
\end{document}

This produces the following output (cropped):

output

I would like to have these pictures aligned vertically such that the x-axes are on the same height and form the baseline of the following text ("test").

It was my understanding that baseline=(current axis.south) should do exactly that, but apparently, I'm mistaken.

1 Answer 1

6

As this:

enter image description here

\documentclass{article}
\pagestyle{empty}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}[scale=.9] % to suppress Overfull \hbox
    \begin{axis}[axis lines=none,samples=150,domain=-10*pi:10*pi,ymin=-.5, ymax=1.5]
    \addplot [mark=none]{sin(deg(x-pi))/(x-pi)}; 
    \addplot [mark=none]{sin(deg(x+pi))/(x+pi)}; 
    \addplot [mark=none,color=red]{sin(deg(x+pi))/(x+pi) + sin(deg(x-pi))/(x-pi)}; 
    \draw[dashed,blue] (axis cs:pi,-5) -- (axis cs:pi,20);
    \draw[dashed,blue] (axis cs:-pi,-5) -- (axis cs:-pi,20);
    \end{axis}
\end{tikzpicture}
\qquad
\begin{tikzpicture}[scale=.9]    
    \begin{axis}[axis lines=none,samples=150,domain=-10*pi:10*pi,ymin=-.5, ymax=1.5]
    \addplot [mark=none]{sin(deg(0.5*(x-pi)))/(0.5*(x-pi))}; 
    \addplot [mark=none]{sin(deg(0.5*(x+pi)))/(0.5*(x+pi))}; 
    \addplot [mark=none,color=red]{sin(deg(0.5*(x+pi)))/(0.5*(x+pi)) + sin(deg(0.5*(x-pi)))/(0.5*(x-pi))}; 
    \draw[dashed,blue] (axis cs:pi,-5) -- (axis cs:pi,20);
    \draw[dashed,blue] (axis cs:-pi,-5) -- (axis cs:-pi,20);
    \end{axis}
\end{tikzpicture}

\end{document}

The current axis.south can be a reference to labels or nodes within current tikzpicture environment but cannot keep reference to future tikzpictures.

Here, since your horizontal axis is actually at y = 0, the simplest way to align the axes is to set the same y range, that is ymin=-.5, ymax=1.5 for example. For the final version, consider also increasing the number of samples for smoothness (200+ is very smooth). Another notion for compatibility, set \pgfplotsset{compat=newest}.

2
  • isn't compat=newest typically discouraged? i thought setting a specific version instead was encouraged around here. Jul 20, 2015 at 13:58
  • 1
    @aeroNotAuto You're right, I added the specific version in this case. I just kinda overlooked this, thanks.
    – AboAmmar
    Jul 20, 2015 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .