插入的图像位于文本和代码之前

插入的图像位于文本和代码之前

我正在输入 LaTeX 代码中的一些未完成部分,在这里的帮助下我已经取得了很大进展。我最不需要帮助的是一些我无法解决的格式问题。

基本上,我试图弄清楚如何阻止我的图像出现我的 MATLAB 代码和文本,但显然它出现在.tex文件中的 MATLAB 代码/文本之后。

\documentclass{article}
\usepackage[margin=0.75in]{geometry}
\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{listings}
\PassOptionsToPackage{breakindent=0pt}{listings}
\usepackage[useliterate, autolinebreaks, framed]{mcode}
\usepackage{mcode}
\usepackage{flafter}
\makeatletter \def\lst@breakindent{0pt} \makeatother
\makeatletter \def\lst@prebreak{} \makeatother

\begin{document}



\begin{figure}[htpb]
    \centering
    \begin{subfigure}{.5\textwidth}
      \centering
      \rule{2cm}{3cm}
      \label{fig:sub1}
    \end{subfigure}%
    \begin{subfigure}{0.5\textwidth}
      \centering
      %\includegraphics[width=1.0\linewidth]{case2Black.png}
      \rule{2cm}{3cm}
      \label{fig:sub2}
    \end{subfigure}
    \caption{A figure with two subfigures}
    \label{fig:test}
\end{figure}

This text comes before the MATLAB code.

\begin{lstlisting}

% Scanned Response Function (Spatial Frequency for linear array)

%This function will compute the spatial frequency response of a spatially sampled signal across a linear array. 'snapShots' is a matrix, where each column consists of one snapshot of the spacially sampled field. Now, each column is first shaded with a window, given my params.windowUsed. Then, each column is FFT'd, and fftShifted. Finally, the spatial frequency axis is then computed, based on whether we want the phi, k, u, or theta space. 

function [sR, axisUsed, allAxes] = scannedResponse(snapShots, params)

%We perform an element by element multiply of each snapshot with the chosen window.
Xwindowed = params.windowUsed*ones(1,params.N.totalSnapShots) .* snapShots;

\end{lstlisting}


May musical arrival beloved luckily adapted him. Shyness mention married son she his started now. Rose if as past near were. To graceful he elegance oh moderate attended entrance pleasure. Vulgar saw fat sudden edward way played either. Thoughts smallest at or peculiar relation breeding produced an. At depart spirit on stairs. She the either are wisdom praise things she before. Be mother itself vanity favour do me of. Begin sex was power joy after had walls miles. 

Up branch to easily missed by do. Admiration considered acceptance too led one melancholy expression. Are will took form the nor true. Winding enjoyed minuter her letters evident use eat colonel. He attacks observe mr cottage inquiry am examine gravity. Are dear but near left was. Year kept on over so as this of. She steepest doubtful betrayed formerly him. Active one called uneasy our seeing see cousin tastes its. Ye am it formed indeed agreed relied piqued. 

May musical arrival beloved luckily adapted him. Shyness mention married son she his started now. Rose if as past near were. To graceful he elegance oh moderate attended entrance pleasure. Vulgar saw fat sudden edward way played either. Thoughts smallest at or peculiar relation breeding produced an. At depart spirit on stairs. She the either are wisdom praise things she before. Be mother itself vanity favour do me of. Begin sex was power joy after had walls miles. 

Up branch to easily missed by do. Admiration considered acceptance too led one melancholy expression. Are will took form the nor true. Winding enjoyed minuter her letters evident use eat colonel. He attacks observe mr cottage inquiry am examine gravity. Are dear but near left was. Year kept on over so as this of. She steepest doubtful betrayed formerly him. Active one called uneasy our seeing see cousin tastes its. Ye am it formed indeed agreed relied piqued. 

May musical arrival beloved luckily adapted him. Shyness mention married son she his started now. Rose if as past near were. To graceful he elegance oh moderate attended entrance pleasure. Vulgar saw fat sudden edward way played either. Thoughts smallest at or peculiar relation breeding produced an. At depart spirit on stairs. She the either are wisdom praise things she before. Be mother itself vanity favour do me of. Begin sex was power joy after had walls miles. 

Up branch to easily missed by do. Admiration considered acceptance too led one melancholy expression. Are will took form the nor true. Winding enjoyed minuter her letters evident use eat colonel. He attacks observe mr cottage inquiry am examine gravity. Are dear but near left was. Year kept on over so as this of. She steepest doubtful betrayed formerly him. Active one called uneasy our seeing see cousin tastes its. Ye am it formed indeed agreed relied piqued. 


$\theta = 0$

\begin{figure}[htpb]
    \centering
    \begin{subfigure}{.5\textwidth}
      \centering
      %\includegraphics[width=1.0\linewidth]{case2Rect.png}
      \rule{2cm}{3cm}
      \label{fig:sub1}
    \end{subfigure}%
    \begin{subfigure}{0.5\textwidth}
      \centering
        %  \includegraphics[width=1.0\linewidth]{case2Black.png}
        \rule{2cm}{3cm}
      \label{fig:sub2}
    \end{subfigure}
    \caption{A figure with two subfigures}
    \label{fig:test}
\end{figure}

\end{document}

无论如何,这里的图像文本/MATLAB,而实际上我希望它们文本/MATLAB。

如何解决这个问题?

答案1

添加hbp可防止浮子到达顶部任何即使浮动到下一页,浮动也会返回到页面。您真正想要的是防止浮动向后浮动到当前页面的顶部。该flafter包(核心 latex 版本的一部分)更改了浮动算法,因此浮动始终出现在源中的位置之后。

添加

\usepackage{flafter}

应该解决问题。

相关内容