[latex] Crop, resize and rotate figures in LaTeX

Tags

, , , , , , , , , , ,

First of all, make sure to include the graphicx package in the preamble of your LaTeX source file. The following command exemplifies how to crop, resize and rotate figures in LaTeX.

\begin{figure}[h]
\centering
\includegraphics[trim=1cm 2cm 3cm 4cm, clip=true, totalheight=0.5\textheight, angle=90]{figure}
\caption{The caption goes here}
\end{figure}

Needless to say, the above goes in between begin{document} and end{document} statements.

Let’s explain the various parts in the argument of \includegraphics command:

  • Cropping:trim=1cm 2cm 3cm 4cm” trims (crops) from left, bottom, right and top by 1, 2, 3 and 4cm respectively. It must be accompanied by “clip=true”.
  • Resizing: totalheight=0.5\textheight” will force the figure to occupy 50% of the page length-wise keeping the aspect ratio constant.
  • Rotating:angle=90” rotates the figure by 90 degrees.

Reference: For more options, refer to this.

[unix] Change default login shell

Tags

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

I just stumbled upon a few ways to change the default login shell to bash:

The easiest one is

$ chsh -s /bin/bash username

On some machines you may have to use ypcsh instead of chsh. The full path of the shell executable must be specified.

But if you have root access you may have the option to use either of the following two as well:

  • $ usermod -s bash username
  • Change it by editing the entry for the user in /etc/passwd file, manually.

If none of the above works, here’s a workaround!

N.B. Make sure that the desired shell is listed in /etc/shells file.

[html] Highlight or draw a box around some text

Tags

, , , , , ,

While blogging for this site, I often want to highlight or draw a box around a certain part of the text; e.g., I feel that it looks nicer if I put a box around a snippet of code, or put a darker background when I put something which needs to be typed in the command line.

 

Highlight some text

<blockquote><div style="background-color:#DCDCDC; color:#000000; font-style: normal; font-family: Georgia;">TEXT_HERE</div></blockquote>

 

Note:

1. For a list of HTML Hex color codes, refer to this wikipedia page.

2. If the text color is already black then color:#000000 is redundant. Similarly, if the text is already normal (i.e., not boldfaced or italicized), then font-style:normal is also redundant. However, I put them there, just to remind myself that they can be altered too!

3. You can remove the blockquotes tags if you don’t like the blockquotes!

 

Draw a box of solid/dotted lines around some text

<div style="border:1px dotted black;padding:2em;">TEXT_HERE</div>

Change dotted to solid to make the lines in the box solid.

[awk] Add another column from a second file

Tags

, , , , , ,

The problem: I have  two files, file-1 and file-2, each of which has two columns; and I want to add the second column of the second file as the third column in the first file.
Let’s say the following is the content of file-1:

A   1
B   2
C   3

and that of file-2:

D   4
E   5
F   6

and I want to have something like this in file-3

A   1   4
B   2   5
C   3   6

Of course, the actual data are not as simple as the above!

Solution:

$ awk '{str1=$1; str2=$2; getline < "file-2"; print str1" \t "str2" \t "$2 > "file-3"}' file-1

I inserted the tab characters (\t) just to make file-3 look nice (scientists don’t care about white spaces, do they?)!

Reference: here.

 

UPDATE: As reader ‘boul oumag’ pointed out, an alternative to this is to use the command line utility ‘paste’.    It concatenates each pair of lines — the corresponding ones from each file — and prints it out in the standard output. There is no option to choose which columns to merge. However, you can always redirect the output to a file, open it with vim and reorder/delete columns using vim’s visual block mode (use control+V).

[bash] SSH to remote servers accessible only through a central server

Tags

, , , ,

We have several Red hat servers node001 through node065 which are only accessible from outside via a central server, central.com. I can think of three different solutions to connect to a node, say node010, via ssh:
1. First SSH to central.com then to node010
2. Forward port 22 of node010 to local machine’s port 2200 via central.com
$ ssh kousik@central.com -L 2200:node010:22
Then ssh to localhost’s port 2200
$ ssh localhost -p 2200
3. $ ssh -YC -t kousik@central.com ssh -YC kousik@node$num

It’s the last one that caught my attention recently — so much so that I put a whole function in the ~/.bash_aliases on my local machine:

#
# A function to ssh to a node: put this in the ~/.bash_aliases file
# The input is the node number
# Example: to ssh to node010 type go2 followed by either 10, 0010 or 0000010 .....
# ..... which is `arithmetically' equal to 10.
#
go2() { num="$*";
  echo "you entered '"$num"' ";
  num="${num#[Nn]ode}"; # Ignore "node", if entered, and consider the rest 
  if [ "$num" -ge 1 2>& /dev/null ] && [ "$num" -le 65 2>&/dev/null ]; then
     num=`echo $num|bc` # for correct arithmetic conversion to a decimal integer
     if [ $num -lt 10 ]; then
        num="00$num";
     else
        num="0$num";
     fi;
     echo "Logging on to  node$num in 1s";
     sleep 1;
     ssh -YC -t kousik@central.com ssh -YC kousik@node$num;
  else
     echo "Please enter a valid integer (1--65)"
  fi;
}

The first conditional statement checks to see if the input is really an integer and is within the correct range: 0-65. The redirections of STDERR to /dev/null are there to suppress appearance of error messages due to non-integer inputs. The reason for using bc for correct arithmetic expansion may be clear from my comment here.

Design a site like this with WordPress.com
Get started