LaTeX and LyX, more useful tricks


Updated: May 3, 2012

A few months back, we had a damn good article on popular tricks you can use to significantly improve the quality and beauty of your LaTeX-made documents. Whether you prefer using a semi-office-suite-like frontend like LyX or code directly in LaTeX, the end result was the same. We got prettier, more elegant, more professional documents.

We learned about multiple columns, aligning bulleted and numbered lists, fancy footnotes and captions, splitting long titles, image adjustments, watermarks, table cell padding, programing language syntax, vertical and horizontal spacers, and LaTeX source. Today, we will learn a few more things, including some rather basic tips that I took for granted in the first article. Hopefully, you won't be disappointed.

Teaser

Document Settings > LaTeX Preamble

I have mentioned this before, but the Preamble is where you set your document globals, inputting commands using LaTeX syntax. In other words, if you wish to create styles and changes that will apply to your entire piece, this is the one location.

Document preamble

Titles & fonts

If you want to change the layout of your title, including justification, font size and sub-title decorations, you have several available options. You can select any text you want and then manually apply the desired font weight and size. You also insert ragged and justified line breaks to maintain the style over multiple lines. A good example is my Crash book. If you're wondering how things look behind the scenes, then you can open the Source viewer and examine the LyX code directly.

Title fonts

Eliminate unneeded layout elements

When you are writing your document, you have various pre-formatted styles available, like chapter, section, sub-section, paragraph, standard text, and others. One of these element is the abstract, which, like one of my readers pointed out, you may not want. So how do you get rid of it?

Styles

You can configure the class of your document in the Document Settings window. Remember Preamble? Well, look up. Document Class lets you choose the default layout for your project. Think of it as the document template in a typical word processor. The class dictates a number of parameters, including the availability of various styles. Some documents will have abstracts, others won't. The same applies to parts, chapters, etc.

Document type

Dates & author names

By default, your document will feature a date, and in some cases, your name printed on the first page, which might not be what you want. No problem. You can eliminate both easily. It's time to combine the power of document classes and the Preamble.

In the Preamble, you can set NULL date by writing \date{}. This will effectively remove the date from the front page. Moreover, you can create header and footer decorations that will feature your name, the article name and additional styles. However, this also necessitates that you use the fancy headers package, which might need a separate installation. Here's my book example:

\usepackage{fancyhdr}
\lhead{\small{www.dedoimedo.com}}
\rhead{\small{all rights reserved}}

Multiple (Two) column format

We talked about this before. But what if you want to place a graphical element that spans both columns? How do you go about that? I did mention that, but perhaps a clarification is needed. Anyhow, this is your standard multiple-column layout:

\begin{multicols}{<number>}
content goes here as usual ...
\end{multicols}

If you want to place an image that spans both columns then you would do the following:

some content goes here ...
\end{multicols}
place image or figure float here
\begin{multicols}{<number>}
content continues here ...

Essentially, you would stop the multiple-column layout, add whatever you wish to span across the entire page width, then resume the document, most likely with the same multiple-column format. And we've learned how to span images across the page.

Image placement

But one thing that may require special attention is the placement of images on the page. Sometimes, you may see that LyX shuffles your images up and down as it sees fit, and this can cause paragraphs to jump below or above the image, which is not what you intended. You can work around this problem by fixing images to an absolution position, somewhat like you do in CSS with HTML elements.

When you place a float element, you can change its settings via the right-click. Then, in the Advanced Placement Options, choose the best settings. The explanations are rather self-explanatory. The most useful one is Here definitely, which tells LyX to strictly obey your styling preferences. Use scaling and width percentage to achieve the best visual result.

Figure float options

Ragged bottoms (or not)

This is not a name of a British pop band from the 70s. It's about how the end of your multi-column document looks like. Using \raggedbottom will cause LyX to try to fill the leftmost columns vertically before moving to the next column. Some people may dislike this. However, LyX default is to try to balance content between all columns evenly, even though you may end up with only the top portion of your page filled with text. Again, combined with the \vspace clause, you can manipulate the layout as you see fit.

Reset figure and table numbering

By default, your tables and images will all be continuously numbered from the start of the document. If you have multiple, supposedly independent sections of content, you might want to reset the counter once in a while. This can be done as follows:

\setcounter{object}{0} \renewcommand{\theobject}{A.\arabic{object}} 

Replace the word object with either figure or table. This will automatically change the numbering scheme in the table of contents as well. If you want to use different numerals, you can change arabic to roman. Others options are also available. See this wiki section for more details.

Track changes

LyX also lets you track document changes, just like your fancy office suite. This can be particularly useful if you share your work with others or must combine multiple documents in one piece.

Track changes

Unrelated bonus: for super-geeks only!

This is about adding Feynman diagrams into your document! Holy banana!

\usepackage{feyn}

Feynman example

Feynman example, zoomed

And it looks like this:

Feynman code, output

Conclusion

Well, that would be all. I must admit this tutorial is tame in comparison to the first piece, but it should appeal to new and intermediate LaTeX and LyX users, who struggle with their documents. In particular, the guide places most focus on the visual layout and tiny issues with classes, titles, dates, image placement, and suchlike. You can either use the graphical interface or work directly with the LaTeX code directives, whichever you prefer.

I hope you like this. Very soon, we will have another LaTeX slash LyX article, but I cannot disclose the contents as it will spoil the surprise. But I do guarantee you will like whatever it has to offer. As always, if you feel something is missing, let me know, and there might be another tutorial. Thanks to Harold for his ideas!

Cheers.

RSS Feed icon

del.icio.us del.icio.us stumbleupon stumble digg digg reddit reddit slashdot slashdot



Advertise!

Would you like to advertise your product/site on Dedoimedo?

Read more

Donate to Dedoimedo!

Do you want to
help me take early retirement? How about donating
some dinero to
Dedoimedo?

Read more

Donate