Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

Wednesday, 24 August 2011

LaTeX: Included graphics resolution

While most graphic files on the internet have a resolution of 72pixel/inch, you need to keep in mind that this resolution is often not suitable for printing. To illustrate that, let's take two images that have the same number of pixels (348 x 350):
One is set at 72pixels/inch:


And the other one is set at 144pixels/inch:


As you can see here, there's no way to tell the difference between them on the screen because your browser displays these images according to their sizes in pixels, regardless of their resolution.

Now if you write a LaTeX document that includes them both:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{lowres.png}
\includegraphics{highres.png}
\end{document}

Here's what you get as the resulting pdf:


As you can see, the original 72px/in image will appear 'too big', pixelized and blurry on your piece of paper, whereas the 144px/in one will be twice as small and keep its sharpness.

So don't hesitate to experiment with resolution when making LaTeX based documents.

That's all for today!

Friday, 5 November 2010

XeTeX: Breaking long lines of Japanese (and Chinese) text.

While LaTeX/XeTeX is very good at hyphenating Latin words, I recently came across the problem of overflowing boxes when attempting to typeset a long paragraph consisting exclusively of Japanese characters:

母親が育児を放棄した末、大阪市西区のマンションで幼い姉弟が亡くなった事件。多くの住民が異変に気づきながら、児童相談所(児相)に通報したのは1人だけだった。複数の人が通報していれば、児相の危機感も強まったかもしれない。なぜ通報をためらった


When you render this with XeTeX, you've got a warning that your hbox is overfull, and the rendered result shows an awful truncated Japanese line:

Rendering of an non hyphen-able Japanese line
We clearly need to fix this, because most of the time your data will be in the form of a long paragraph without any linebreaks.

In XeTeX-notes.pdf, we learn that we can activate the line-breaking in XeTeX by using:

\XeTeXlinebreaklocale"en"

The locale used doesn't matter much, the important thing is that it activates line breaking for too long lines where the hyphenation mechanism cannot do its job (a long Japanese/Chinese line for instance).

By adding this to your preamble, here's what you get:

A Japanese paragraph with line breaks.
Et voilà, lines are broken so all the characters fit in the page width!

Ps: Thanks to Google news Japan for providing example data.

Monday, 13 September 2010

LaTeX: Hyphenate single long words in narrow tabular columns

Consider the following LaTeX code:

\documentclass{article}
\usepackage[english]{babel}
\begin{document}
\begin{center}
    \begin{tabular}{ | p{2cm} | l | l | p{5cm} |}
    \hline
    Incredibilidable & foo & bar & baz \\
    \hline
    \end{tabular}
\end{center}
\end{document}

When you render it, the first column overflows on the second one because 'Incredibilidable' is considered to be the first word of a paragraph, and LaTeX does not hyphenate first words of paragraphs. So here's what you get: 
And this doesn't look nice.

To fix this, we're going to tell LaTeX our word is no longer the first of the paragraph. To do that, we insert a zero length horizontal space before it:

  \hspace{0pt}Incredibilidable & foo & bar & baz \\

The rendering now turns into:

Et voila!