Wednesday 23 May 2012

Adjusting vertical alignment of subfigures in LaTeX

When using subfigures in Latex, I have sometimes found it annoying how the figures are vertically aligned at the bottom, rather than being centered. An example: The following code

\begin{figure}
\subfigure{\includegraphics[width=67mm]{PipeScannerUnderGround}}
\subfigure{\includegraphics[width=47mm]{CylScanGeometryPipe}}
\caption{}
\end{figure}

produces the following figure:


which seems a little lopsided. I found a nice solution at stackoverflow: Use the \raisebox command to adjust the vertical position of individual subfigures, for example

\begin{figure}
\subfigure{\includegraphics[width=67mm]{PipeScannerUnderGround}}
\subfigure{\raisebox{10mm}{\includegraphics[width=47mm]{CylScanGeometryPipe}}}
\caption{}
\end{figure}

which yields the following result:



Much nicer! :)


Monday 14 May 2012

Adjusting LaTeX margins to fit a wide figure

I'm currently writing my PhD thesis, trying to shape a number of scientific articles into a coherent whole. In this process, I've come across a problem: The PhD thesis format has a text width of 120mm, which is suitable for one-column text, but I sometimes want my figures to be wider than this. How can I adjust the margins of a page on a per-figure basis? The answer: The changepage package.

Include the package by adding this line to the preamble

\usepackage[strict]{changepage}

... and use the \adjustwidth{leftmargin}{rightmargin} inside the figure environment, for example

\begin{figure}
    \begin{adjustwidth}{-10mm}{-10mm}
        \includegraphics{wide}
        \caption{Wide figure}
    \end{adjustwidth}
\end{figure}

In this example, both the left and right margins are reduced by 10 mm, making more room for the figure. The command also works with subfigures. 

Friday 4 May 2012

Batch converting PDF to EPS

Today I found myself needing to convert about 20 vector images from PDF to EPS, because a journal that I want to submit an article to, demands that all graphics are in EPS format.

Searching the net, I found several solutions, many of them involving the pdf2ps or pdftops command-line utilities. The best solution was the one I found here, which converts all the images in a folder with a single-line for loop:

for f in *.pdf; do pdftops -eps $f; done

The code is run on the command line. I've only tried this in Linux, but some version of it may work in Windows or OSX as well.