I am typing up some loose ends in my LaTeX code, and I have come far with help from here. The last things I need help with are some formatting subtleties that I cannot solve.
Basically, I am trying to figure out how to stop my images from coming before my MATLAB code and text, when clearly it is coming after the MATLAB code/text in the .tex file.
\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}
Anyway, what happens is that the images here come before the texts/MATLAB, when in fact I want them to come after the texts/MATLAB.
How to remedy this?
figureis a float. So it may come at thetop of the page. You could do\begin{figure}[hbp]in this case. – Qrrbrbirlbel Oct 01 '13 at 15:31“), you need to format your code as Code (the{}or Ctrl + K) button. See also How do I mark code blocks? – Qrrbrbirlbel Oct 01 '13 at 15:32mcodebecause I don’t have that package). Also I don’t know Matlab. Thelstlistingenvironment is also a float, here you need to use the keyfloat, e.g.\begin{lstlisting}[float=b]to put the code at the bottom. Reference: How to influence the position of float environments like figure and table in LaTeX? – Qrrbrbirlbel Oct 01 '13 at 15:36matlab-prettifierpackage; see this answer. – jub0bs Apr 28 '14 at 17:11