我有两个并排的图表,但当我添加 \caption{此处添加一些标题文本} 时,第二个图表会移到下一行。如何解决?
\documentclass{book}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{tikz}
\usepackage{float}
\begin{document}
\begin{minipage}[t]{0.5\textwidth}
\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[
xlabel=$t$,
ylabel=$x(t)$,
grid=major,
%step=1cm,
xmin=-5, xmax=5,
ymin=-2, ymax=2,
height=70mm, width=80mm,
samples=99
]
\addplot[red, thick, line width=1pt]{sin(90*x)+0.5};
\end{axis}
\end{tikzpicture}
\caption{Sinusne funcions}
\label{fig:fig1}
\end{figure}
\end{minipage}\hspace*{2pc}%Increase the space how much you like
\begin{minipage}[t]{0.5\textwidth}
\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[
xlabel=$t$,
ylabel=$x(t)$,
grid=major,
%step=1cm,
xmin=-5, xmax=5,
ymin=-2, ymax=2,
height=70mm, width=80mm,
samples=99
]
\addplot[red, thick, line width=1pt]{sin(90*x)+0.5};
\end{axis}
\end{tikzpicture}
\caption{Sinusne functions}
\label{fig:fig2}
\end{figure}
\end{minipage}
\end{document}
答案1
请尝试以下操作:
\documentclass{book}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{tikz}
\usepackage{float}
\begin{document}
\begin{minipage}[t]{0.5\textwidth}
\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[
xlabel=$t$,
ylabel=$x(t)$,
grid=major,
%step=1cm,
xmin=-5, xmax=5,
ymin=-2, ymax=2,
height=70mm, width=80mm,
samples=99
]
\addplot[red, thick, line width=1pt]{sin(90*x)+0.5};
\end{axis}
\end{tikzpicture}
\caption{Sinusne funcions}
\label{fig:fig1}
\end{figure}
\end{minipage}\hspace*{2pc}%Increase the space how much you like
\begin{minipage}[t]{0.5\textwidth}
\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[
xlabel=$t$,
ylabel=$x(t)$,
grid=major,
%step=1cm,
xmin=-5, xmax=5,
ymin=-2, ymax=2,
height=70mm, width=80mm,
samples=99
]
\addplot[red, thick, line width=1pt]{sin(90*x)+0.5};
\end{axis}
\end{tikzpicture}
\caption{Sinusne functions}
\label{fig:fig2}
\end{figure}
\end{minipage}
\end{document}
答案2
只需反转图形和小页面的顺序即可。然后您要做的就是缩小 tikzpictures,直到它们真正适合小页面。
\documentclass{book}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{tikz}
\usepackage{float}
\usepackage{showframe}% MWE only
\begin{document}
\begin{figure}[H]
\begin{minipage}[t]{0.5\textwidth}
\begin{tikzpicture}
\begin{axis}[
xlabel=$t$,
ylabel=$x(t)$,
grid=major,
%step=1cm,
xmin=-5, xmax=5,
ymin=-2, ymax=2,
height=70mm, width=80mm,
samples=99
]
\addplot[red, thick, line width=1pt]{sin(90*x)+0.5};
\end{axis}
\end{tikzpicture}
\caption{Sinusne funcions}
\label{fig:fig1}
\end{minipage}\hfil
\begin{minipage}[t]{0.5\textwidth}
\begin{tikzpicture}
\begin{axis}[
xlabel=$t$,
ylabel=$x(t)$,
grid=major,
%step=1cm,
xmin=-5, xmax=5,
ymin=-2, ymax=2,
height=70mm, width=80mm,
samples=99
]
\addplot[red, thick, line width=1pt]{sin(90*x)+0.5};
\end{axis}
\end{tikzpicture}
\caption{Sinusne functions}
\label{fig:fig2}
\end{minipage}
\end{figure}
\end{document}