Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with the alignment of 2 plots. The Problem is I want the captions to be horizontal aligned. Also the x-axis should be horizontal aligned!

Is there a way to do that?

\begin{figure}[!h]\centering  
\subcaptionbox{Plot 1 \label{fig:ufMna}}{   
\begin{tikzpicture}[baseline,xscale=10,yscale=10]    
\draw [<->, thick] (0,0.5)node[left]{$U$} -- (0,0) -- (0.5,0) node[below]{$f$};
\draw[blue, ultra thick](0,0)--(0.25,0.25) --(0.4,0.25);
\draw[dashed]  (0,0.25)node[left]{$U_{max}$} -- (0.25,0.25);
\end{tikzpicture}
}     
\subcaptionbox{Plot 2 \label{fig:ufMnb}}{   
\begin{tikzpicture}[baseline,xscale=10,yscale=10]
\draw [<->, thick] (0,0.5)node[left]{$M$} -- (0,0) -- (0.5,0) node[below]{$n$};
\draw[blue, ultra thick, ] (0,0.25)--(0.25,0.25)--(0.4,0.05);
\end{tikzpicture}   
}    
\caption{Showing 2 Plots}
\label{fig:ufMn}   
\end{figure}
share|improve this question
2  
to display a code correctly, you need to type 4 space before each line, not use the ` character –  Lionel MANSUY Feb 18 '13 at 12:57

1 Answer 1

If you use PGFPlots for drawing your axes, you can add the option trim axis left to horizontally align the axes:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subcaption}

\pgfplotsset{ 
    dacrip plot/.style={ % Set common styles that can be applied to the axis environment
        x=2cm, y=2cm,                   % Unit vector length
        axis lines=middle,              % Axis lines go through (0,0)
        xtick=\empty, ytick=\empty,     % No tick marks
        ymin=0, ymax=1.75,              % Y axis range
        enlargelimits=upper,            % Increase upper range a bit
        clip=false,                     % Allow labels to extend beyond the axis
        disabledatascaling,             % Allow to draw TikZ objects without having to use (axis cs:<x>,<y>)
        x label style={anchor=north},   % Alignment of axis labels
        y label style={anchor=east}
    }
}

\begin{document}
\begin{figure}[!h]\centering
\subcaptionbox{Plot 1 \label{fig:ufMnb}}{
    \begin{tikzpicture}[trim axis left]
        \begin{axis}[dacrip plot, xlabel=$f$, ylabel=$U$]
            \addplot [blue, ultra thick] coordinates {(0,0) (1,1) (2,1) };
            \draw [dashed] (0,1) -- (1,1) node [pos=0, anchor=east] {$U_{max}$};
        \end{axis}
    \end{tikzpicture}
}

\subcaptionbox{Plot 2 \label{fig:ufMnb}}{
    \begin{tikzpicture}[trim axis left]
        \begin{axis}[dacrip plot, xlabel=$f$, ylabel=$U$ ]
            \addplot [blue, ultra thick] coordinates {(0,1) (1,1) (2,0.2)};
        \end{axis}
    \end{tikzpicture}
}
\caption{Showing 2 Plots} \label{fig:ufMn}
\end{figure}
\end{document}
share|improve this answer
    
Thanks for your quick answer! –  dacrip Feb 18 '13 at 17:02
    
How can I align the same plots vertically? –  dacrip Feb 18 '13 at 17:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.