[latex] Multiple figures under the same caption using ``subfigure''

Tags

, , , , , ,

If you want to put several small figures under the same caption, then you need to include the subfigure (along with  graphicx) package. The format is something like this:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            Contents of main.tex (LaTeX Source)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%   Preamble %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\documentclass[11pt,a4paper]{article}
\usepackage{graphicx, subfigure}
%
%%%%%%%%% The Document starts here  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\begin{document}
%
Some random text at the beginning of the document ........
%%
% --------------  Include the figures as follows -------------------%
%%
\begin{figure}[ht!]
     \begin{center}
%
        \subfigure[Caption of First Figure]{%
            \label{fig:first}
            \includegraphics[width=0.4\textwidth]{FirstFigure}
        }%
        \subfigure[Caption of Second Figure]{%
           \label{fig:second}
           \includegraphics[width=0.4\textwidth]{SecondFigure}
        }\\ %  ------- End of the first row ----------------------%
        \subfigure[Caption of Third Figure]{%
            \label{fig:third}
            \includegraphics[width=0.4\textwidth]{ThirdFigure}
        }%
        \subfigure[Caption of Fourth Figure]{%
            \label{fig:fourth}
            \includegraphics[width=0.4\textwidth]{FourthFigure}
        }%
%
    \end{center}
    \caption{%
        The l-o-n-g caption for all the subfigures
        (FirstFigure through FourthFigure) goes here.
     }%
   \label{fig:subfigures}
\end{figure}
%%
% -------------- End of figure environment ----------------------%
%%

The first, second, third and the fourth subfigures in  Figure
\ref{fig:subfigures} are labeled as
\ref{fig:first}, \ref{fig:second}, \ref{fig:third} and \ref{fig:fourth},
respectively.

Some more text before the end ..........
%
\end{document}
%
%%%%%% The End %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

It will create two rows of subfigures with two subfigures on each row (needless to say, you must have all those figures, viz. FirstFigure.eps through FourthFigure.eps, in the same directory as the LaTeX source file). The optional argument within the square brackets immediately following the subfigure statement is the caption of the subfigure (besides the main caption for all the subfigures at the end).

Various other options (e.g., cropping, resizing are rotating the figures) for includegraphics were explained awhile ago.

Reference: here.

[linux] How to install compilers on Puppy Linux

Tags

, , , , ,

Recently I have started playing with the Puppy (Puppy Linux 4.3.1, that is). I liked the speed and ease of using it so much that I decided to do a full install on my hard drive. It’s very lightweight and very fast.

However, after the initial phase of likeness, I realized that it is missing a lot of things —- including the build essentials (e.g., gcc).  That means Puppy has trimmed its fat in order to become so lean (the .iso file is about 100 MB)  that it does not have some of the necessary packages — especially the ones, that someone may need to compile packages from the source code if there is a need. However, the default software suit is very nice and useful: I haven’t seen such a good collection in a such a lean size before.

But, the tools I was looking for was not in their repository either. After searching in puppy forums, I realized that I need a package called devx-431.sfs [download link].  But for a hard puppy (a full installation of puppy on the hard drive) it is a special case if you want to install a .sfs file —- which I had a hard time figuring out skimming through various posts in the forum (which are very old by the way!).

However, it is explained in the main website in a very clear fashion (I wish I looked there first!).

1. Click on the devx_xxx.sfs in a ROX-Filer window to mount it.
2. Open a terminal in the mounted directory.
3. # cp -a --remove-destination ./* /mnt/hda2/
4. # sync
5. Close the terminal.
6. Click on the devx_xxx.sfs file to unmount it

Note, the ‘–remove-destination’ option is essential. If you only use ‘-f’ to force overwrite, it will follow (dereference) a symlink, that can cause unexpected overwrites.

I had a problem performing the second step. If you save the devx_xxx.sfs file in the /root directory (which is startup directory, i.e. if you do a “cd ~” you’ll reach there), then the mounted directory will look like “+root+devx_xxx.sfs/”. Just cd to there in the console and follow the next steps above.

Credit: here.

Further reading: Lifehacker’s review.

[awk] Output formatting

Tags

, , , ,

If you use print in awk you’ll lose the formatting of the input file — most of the times that may be OK, but not always. The solution is simple — replace print by printf. Here’s an example with strings in the input fields:

$ awk '{printf "%-20s%-20s%-20s\n", $1, $2, $3}' yourfile.dat

.

  • “%…s” means a character string.
  • 20 means a length of 20 characters.
  • awk defaults to right-alignment (presumably for columns of figures) so you need -20 for left-alignment.

Credit: here.

[osx] Restart a frozen Dock from the command line

Tags

, , , ,

I am having some problem with the X11 lately on my Mac OSX (Leopard). I have not found a solution yet — when I do I’ll sure put it up here. But a stuck X11 window in the dock caused it to freeze up. Along with that all the fancy cover switch and other related stuff are also gone! Luckily the spotlight accepted the Command+spacebar combination and let me find terminal.app from there.

However, although I knew who the culprit was (using htop) but I cannot kill it (kill -9 kills it, but it revives!). But the following command did the trick:

$ killall Dock

It’ll kill the Dock application and then restart it instantly. (Although it did not kill the culprit, x11).

I’m yet to find a solution for the x11 problem!

[awk] Command line calculator using awk

Tags

, , , , , , , , , , , ,

This is an update on our bash command line calculator posted a few days ago — except for the fact that this time we’ll use awk to do the calculation instead of bc. As I mentioned in that post, you may use python or ruby (irb) to do the same thing, but these tricks may be useful if you don’t  have ruby or python installed (bc and awk, in general, come by default in any Unix or GNU/Linux distro).

First, create (or rewrite if you used our last trick) function “?”  as follows and put it in your ~/.bashrc file:

? () { awk "BEGIN{ print $* }" ;}

and make sure to reload your ~/.bashrc file (do the similar thing if you're using any other shell). [NOTE: ZSH does not like ``?'' as a function, so you might consider replacing it with something reasonable, e.g., ``compute'']

Now, if you want to calculate an expression, do it, for example, as

$ ? "2*3+4.0*(9.9+8.1)"

and don’t forget the quotes.

.

The advantage of this over bc is that you can use more arithmetic and trigonometric functions (link):

              atan2(y,x)     Arctan of y/x between -pi and pi.

	      cos(x)	     Cosine function, x in radians.

	      exp(x)	     Exponential function.

	      int(x)	     Returns x truncated towards zero.

	      log(x)	     Natural logarithm.

	      rand()	     Returns a random number between zero and one.

	      sin(x)	     Sine function, x in radians.

	      sqrt(x)	     Returns square root of x.

.
You may include variables as well in the function definition itself:

? () { awk "BEGIN{ pi = 4.0*atan2(1.0,1.0); degree = pi/180.0; print $* }" ;}

where we have defined the variable pi and degree (such that tan(pi/4.0) = 1.0 and pi radians is equivalent to 180 degrees) to be used later, e.g.

$ ? "cos(pi)"
$ ? "cos(90*degree)"

and I’m sure that you’ll get -1 and 0 (within the machine precision), respectively, as the answer!

(You may find some more interesting calculator related tricks posted in this blog scattered in different pages)

Credit: here and here (via LifeHacker).

UPDATE: I just realized that I can use the calc package (besides bc, awk, python and irb) to do the command line math wizardry more efficiently (and let’s take that as the end to this command line calculator series!). It has a larger set of built-in functions. You may grab the source code from the maintainer’s website and follow my instructions to install it on your system [although binaries are also readily available, e.g. apcalc package for Ubuntu 9.10 (Karmic Koala)].

Design a site like this with WordPress.com
Get started