## Friday, April 24, 2009

### Figures, Subfigures, and Table Syntax in Latex

UPDATED*  Now I use the package \usepackage{float} for figures and tables.  It allows easy manual editing of how the figures are labeled and works for both tables and figures.
The code looks like
\usepackage{float}                      % figure floats
%===============================================================================================
% GRID REFINEMENT %===============================================================================================       \begin{figure}      % Requires \usepackage{graphicx}      \centering % centers everything on the page     \subfloat[\textbf{a)} Axisymmetric perturbations ($q=0$)]     {         \includegraphics[width=3.13in, height=1.75in]{figures/Ch_LNP_of_BV/LNP_Axisymmetric_Grid_Refinement}% include figure     \label{Ch:LNP of BV Fig:Axisymmetric Grid Refinement}}     \subfloat[\textbf{b)} Asymmetric perturbations ($q=1$)]      {         \includegraphics[width=3.13in, height=1.75in]{figures/Ch_LNP_of_BV/LNP_Asymmetric_Grid_Refinement}% include figure     \label{Ch:LNP of BV Fig:Asymetric Grid Refinement}}         \caption{Grid refinement for $\alpha=3$, $z=1.5$, $Re=10,000$, and $\kappa=0.1$} % text to be   included under all figures         \label{Ch:LNP of BV Fig:Grid Refinement}     \end{figure} %===============================================================================================

OLD WAY USING SUBFIGURE
\documentclass{article}%   PREAMBLE%=================================================================================================\usepackage{amsmath}    % math format package\usepackage{booktabs}   % professional tables package\usepackage[final]{graphicx}   % figures package\usepackage{subfigure}  % package for subfigure formatting%=================================================================================================% you must include \usepackage{graphicx}.  this has 2 options - [final] for final drafts - [draft]only gives a place holder and doesn't render the image.% for pdf documents the image must be in pdf form. for dvi the image must be in eps.% to use figures in a separate subdirectory use "folder_name/file_name"% it's not perfect because it is touchy about the files it can use.  you could use a dummy epsfile so the dvi compiler will work. or you do the figures only in pdf and don't include them untildone.% \includegraphics[width=?]{} gives options to change the properties such as width, leaving itblank uses the original sizes% some of the journal styles cause problems with this for some reason%=========================% THIS IS A SINGLE FIGURE%=========================\begin{figure}% Requires \usepackage{graphicx}\centering % centers everything on the page\includegraphics{Final_Figures/S=50}\\ % include figure\caption{$\lambda=50$} % text to be included with figure\label{fig:lambda=50}\end{figure}%=================================% THIS IS A FIGURE WITH SUBFIGURES%=================================\begin{figure}% Requires \usepackage{graphicx}\centering % centers everything on the page\subfigure[] % text to be included with figure 1 goes inside '[]'{ \includegraphics[width=2.5in, height=1.75in]{Final_Figures/S=50}% include figure \label{fig:1lambda=50}}\subfigure[] % text to be included with figure 2 goes inside '[]'{ \includegraphics[width=2.25in, height=1.75in]{Final_Figures/S=100}% include figure \label{fig:1lambda=100}}\subfigure[] % text to be included with figure 3 goes inside '[]'{ \includegraphics[width=2.5in, height=1.75in]{Final_Figures/S=200}% include figure \label{fig:1lambda=200}}\subfigure[] % text to be included with figure 4 goes inside '[]'{ \includegraphics[width=2.25in, height=1.75in]{Final_Figures/S=400}% include figure \label{fig:1lambda=400}}\caption{Analytical and numerical solutions of the eigenfunction equation with$a_0 = -\cos \left(\frac{1}{2}\pi y\right)$, $\xi=5$, $n=1$, $\omega_n t=\pi/2$, $x/l=0.5$and a Strouhal number of (a) $\lambda=50$  (b) 100   (c) 200   and (d)400. The agreement between numerics and asymptotics continues to improve withsuccessive increases in the Strouhal number despite the highly oscillatory nature ofthe solution and the radical reduction in spatial wavelength.} % text to be includedunder all figures\label{fig:Solution with several Lambdas}\end{figure}% =====================% THIS IS FOR TABLES% =====================% be sure to use \usepackage{booktabs} in the preamble% tables and tabular are different things.  Tabular gives you the format of a table,but the\table command is required to actually identify it as a table in the document with automaticcross-referencing and whatnot.% the tabular command has the format \begin{tabular}{ x y z }.  {x y z} are replacedby the cell formatting 'l' for left 'c' for center 'r' for right.  it can appear as{|x|y|z|} to give vertical lines% to span multiple cells use\multicolumn{number of cells to span}{cell formatting}{What appears in the cell goes here}\\% the '\\' command moves to the next line     \begin{table} % begin the table identification command \addtolength{\tabcolsep}{-4pt}     \centering % ensure it centers on the page.  modify this if centering is not wanted     \caption{Comparison between numerical and asymptotic solutions for both Type I and Type II.Here $\lambda=10$, $\varepsilon=10^{-3}$, $n=0$, $a_0=-\cos(\frac{1}{2}\pi x)$, and $b_0=(2n+2)F'$}% this is the text appearing with the table - description     \label{table:Comparing the Types} % this is the label for cross-referencing         \begin{tabular}{c|c c c|ccc|c} % this begins the table format             \toprule % bold horizontal line command& \multicolumn{3}{c|}{Type I}& \multicolumn{3}{c|}{Type II}& Numerical\\\cmidrule(){2-8}$x$ &   $f^{(2)}$ & $f^{(3)}$ & $f^{(4)}$ &$f^{(2)}$ & $f^{(3)}$ & $f^{(4)}$ & $f^N$\\             \midrule % horizontal line command      0 &          1 &          1 &          1 &          1 &          1 &          1 &          1 \\   0.05 &  0.8676644 &  0.8674551 &   0.867459 &  0.8676685 &   0.867459 &   0.867459 &   0.867459 \\    0.1 &  0.5188763 &  0.5186301 &  0.5186429 &  0.5188833 &  0.5186428 &  0.5186429 &  0.5186429 \\    0.2 & -0.3939219 & -0.3935576 & -0.3935347 & -0.3939428 &  -0.393534 & -0.3935347 & -0.3935347 \\    0.3 & -0.7672007 & -0.7662141 &  -0.766217 & -0.7672949 & -0.7662147 &  -0.766217 & -0.7662171 \\    0.4 & -0.2589166 & -0.2585327 & -0.2585659 & -0.2589812 & -0.2585645 & -0.2585659 & -0.2585659 \\    0.5 &  0.3586916 &  0.3582113 &  0.3582018 &  0.3589124 &  0.3581976 &  0.3582018 &  0.3582018 \\    0.6 &  0.2062112 &  0.2061807 &  0.2061778 &   0.206496 &  0.2061744 &  0.2061778 &  0.2061778 \\    0.7 & -0.1574955 &  -0.158249 & -0.1582805 &  -0.158256 & -0.1582757 & -0.1582805 & -0.1582805 \\    0.8 &  0.0345428 &  0.0357267 &  0.0360158 &  0.0356684 &  0.0360156 &  0.0360158 &  0.0360158 \\    0.9 & -0.0049035 & -0.0104253 & -0.0091613 &  -0.008804 & -0.0091688 & -0.0091612 & -0.0091613 \\   0.95 & -0.0000306 &   34513650 &  0.0008021 &  0.0006995 &  0.0008034 &  0.0008017 &  0.0008015 \\   1.0  &          0 &  $\infty$  &          0 & -0.0000111 & -0.0000168 &  -0.000017 & -0.0000339 \\             \bottomrule % horizontal line command         \end{tabular} \end{table}\end{document}

Be sure to put the \label{} command below the \caption{} command for figures and tables. See this post for more on this point.

I used this link to learn about subfigures and this and this for tables. Also, i found a great editor that exports excel data to latex format here.

This is where i figured out how to put verbatim code in Blogger