Two tricks on how to deal with latex graphics

It is always annoying to adjust graphics and plots in latex environment. Somehow the program is not smart enough to figure out where to place the pictures, and worse still, it always arrange pictures and texts in unexpected order, unless you use thumb-nail sized pictures.

So the first trick is to always use the following formatting for graphics inclusion:

\begin{figure}[h!tbp]
\begin{center}
\leavevmode
\includegraphics[height=0.5\textwidth, width = 0.7\textwidth]{TubaTVimg1.pdf}
\end{center}
\end{figure}

To place two pictures side by side requires some separate latex package which I won’t discuss here.

Here the tag h!tbp roughly stands for this: first try to place the picture here (at current position in the document), if that fails, try to place it to be aligned with the top of the page, then with the bottom, and then finally, p stands for put the picture on a separate page. It’s a pretty difficult mnemonic to remember, but all you need to do is copy and paste.

Next it is still important to manually insert some “\pagebreak” to ensure proper layout in relation to the texts; otherwise later texts could be put in front of the current picture, as latex likes to do.

Also notice that setting width and height in proportion to the text width is a sensible thing to do. I haven’t tried \textheight tag. Maybe that doesn’t exist.

Another trick I want to mention is for quoting code snippets. Before I always use

\begin{verbatim}.. \end{verbatim} enclosure

but then there is the problem of lines that are too long. Verbatim doesn’t auto-wrap those lines. I discovered today that one can use the following package followed by a setting of auto line break:

\usepackage{listings}
\lstset{breaklines=true}

Then to quote a block of text with auto-wrapping, simply follow the next example:

\begin{lstlisting}
% compute the L^p smoothness of the vector v, raised to pth power

function x = smoothness(v, p)
n = length(v);
x = 0;
for i = 1:(n-1)
x = x + (abs(v(i+1)-v(i)))^p;
end
\end{lstlisting}

p.s. a good reference link for graphics: http://www.reed.edu/cis/help/latex/Graphics.html#pos

Advertisements

About aquazorcarson

math PhD at Stanford, studying probability
This entry was posted in computer science and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s