[Japanese | English] [Index]

 Latex Tips

# Tricks related to spacing

### The amount of space above and below \section's titles can be adjusted in the definition of \newcommand\section in the .cls file

For example in jreport.cls (Japanese report style file), it originally looks like:

 \newcommand{\section}{\@startsection{section}{1}{\z@}% {1.5\Cvs \@plus.5\Cvs \@minus.2\Cvs}% {.5\Cvs \@plus.3\Cvs}% {\reset@font\Large\bfseries}}

Here, {1.5\Cvs \@plus.5\Cvs \@minus.2\Cvs} adjusts the amount of space above a \section, and {.5\Cvs \@plus.3\Cvs} the amount of space below. The way to read them is

 {A \@plusB \@minusC}: leave a space of A by default, at most A+B, at least A-C

\Cvs is a space unit used for Japanese language which amounts to \baselineskip, i.e., the basic amount of vertical space between two lines. Other units can be used, for example 3ex or 0.3cm. For example, in report.cls, commonly used for western documents, the definition goes as

 \newcommand\section{\@startsection {section}{1}{\z@}% {-3.5ex \@plus -1ex \@minus -.2ex}% {2.3ex \@plus.2ex}% {\normalfont\Large\bfseries}}}}

The sign in front of the units is related to indentation of the text that comes after the \section title: when it is negative, such as in -3.5ex, the following text is NOT indented. Personally, I used {2.5ex \@plus1ex \@minus.5ex} in my thesis. For journal or conference papers, looking at the default in the style files provided and starting from there should be a good strategy.

The amount of space around \subsection, etc., can be adjusted similarly.

### Adjusting the amount of space above and below equations

This can be done by redefining, in the .cls file, the variables \abovedisplayskip and \belowdisplayskip. In general, these variables are originally defined in files like size10.clo,or size12.clo, depending on the font size (jsize12.clo, etc., for Japanese documents). For example, for 12 points fonts, you can change the original

 \setlength\abovedisplayskip{12\p@ \@plus3\p@ \@minus7\p@}

into

 \setlength\abovedisplayskip{11\p@ \@plus3\p@ \@minus7\p@}

Quite often, it looks like the space around an equation could be shrinked to make one or two more lines fit in a page, and yet Latex does not shrink that space (annoying, isn't it?). In this kind of situation, a potential solution is to change the values of the skips temporarily. It is indeed possible to adjust these values directly inside the .tex file, the only thing to be careful about is that the way units are written changes. By writing

 {\setlength\abovedisplayskip{11pt plus 3pt minus 7pt} \setlength\belowdisplayskip{11pt plus 3pt minus 7pt} ... (Equation(s)) ... }

the variables are redefined only inside the brackets {}.

### Adjusting the amount of space above and below captions

In the same way, one can tweak \abovecaptionskip. For example, in table environments the caption usually comes above the table, but as by default no space is put below captions, the table is stuck to the caption. To avoid this, one can modify the .cls file in the following way:

 \setlength\belowcaptionskip{5\p@}

### Splitting an equation which spans several lines over two pages

When using for example the align environment, equations can span several lines and become a huge block which Latex considers as unbreakable. When that block cannot fit into the current page, Latex puts on the next page, leaving massive blank spaces inbetween paragraphs in the current page (very ugly). The killer command in this kind of situations is:

 {\allowdisplaybreaks ... \begin{align} ... \end{align} }

This command can be used both globally and locally (within brackets {}). (I somewhat recommend the temporary one. This is still a hack, so it may be better to avoid it when it's unnecessary.)

### Changing the default interline space in the text while keeping single interline space in captions

The setspace package is here for you. For example, by putting

 \RequirePackage{setspace} \setstretch{1.3}

in the .sty file, the interline space in the text becomes 1.3 times \baselineskip, but captions stay in single interline space.

### When the text does not come up to the bottom of the page, leading to pages with different lengths

The \raggedbottom command must be hidden somewhere in your .sty or .cls file. When it is effective, all the extra amount of space in a page is gathered at the bottom of the page. When commenting out, the text of each page nicely comes up to the bottom of the page, but the space between paragraphs sometimes becomes very large, making some pages very ugly. The tricks given above for the adjustement of space around equations and titles of sections should then be used. When none of these work, one can try to add some extra \vspace as a last resort.

# Disable the annoying behavior of subscripts and superscripts in recent emacs versions

 (eval-after-load gtex-modeh e(fset etex-font-lock-suscript eignore))

# Embed fonts in PDF files

I have had some problems embedding the Japanese MS Mincho and MS Gothic fonts in PDF files (on Windows XP) as they were systematically replaced by Ryumin-light and GothicBBB-Medium fonts, which by default are not embedded. This can be solved either by specifying the .map file to use
 dvipdfmx -f msembed.map file.dvi
or, to systematically have them embedded, by modifying the dvipdfmx configuration file, for me c:/tex/share/texmf/dvipdfmx/config/dvipdfmx.cfg, adding this line at the end of the file:
 f msembed.map
However, these tricks somehow did not work with xdvipdfmx, which for some reason was unable to find the msmincho.ttc fonts...

On the Western fonts side, Times and Helvetica also often fail to be embedded. Following this page, the problem can be solved similarly with
 dvipdfmx -f dlbase14.map file.dvi
or by uncommenting the corresponding line in the dvipdfmx.cfg file. However, this may not be enough (maybe because of such fonts appearing in figures), in which case you should find the gs_pdfwr.ps file (in my case it was in C:/tex/gs/gs8.64/Resource/Init/ but it is often reported as being in C:/tex/gs/gs8.64/lib/), copy it to the directory in which you are converting the DVI file, and comment out the lines declaring fonts never to embed as follows:
 /.standardfonts [ % /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique % /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique % /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic % /Symbol /ZapfDingbats ] readonly def
This should do the trick!

# Make ispell work in Meadow/Emacs on Windows XP

This is only remotely related to Latex, but can be useful. When trying to spell check a buffer in Meadow/Emacs on Windows XP, it may happen that ispell cannot find the dictionary file (typically US-xlg.hash). This can be solved by adding to environment variables (My Computer->Properties->Advanced->Environment Variables):
 DICTIONARY: C:\meadow\packages\etc\ispell\US-xlg.hash ISPELL_DICTDIR: C:\meadow\packages\etc\ispell
The correct values to put in may depend on your system. Make a search for the file US-xlg.hash to find the proper values.