对齐水平子标题和 TikZ

对齐水平子标题和 TikZ

我对 2 个图的对齐有问题。问题是我希望标题水平对齐。x 轴也应该水平对齐!

有没有办法做到这一点?

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

答案1

如果您使用 PGFPlots 绘制轴,则可以添加trim axis left水平对齐轴的选项:

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

相关内容